forked from Blendman974/faceclaw
Even store integration
This commit is contained in:
1 parent
5cd61da362
commit
add8763028
16 files changed
+737
-56
No files matched your search
@@ -1,6 +1,11 @@
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { type AppDefinition } from "../app-definition";
|
||||
import { createLauncherWindow, LAUNCHER_SURFACE_ID, LAUNCHER_WINDOW_ID } from "./launcher-app";
|
||||
import {
|
||||
getInstalledEvenHubApps,
|
||||
installedEvenHubAppId,
|
||||
renderInstalledEvenHubIcon,
|
||||
} from "../evenhub/installed-apps";
|
||||
|
||||
const launcherApp: AppDefinition = {
|
||||
appId: "launcher",
|
||||
@@ -17,10 +22,21 @@ const launcherApp: AppDefinition = {
|
||||
...ctx.actions,
|
||||
requestRender: () => shell.foregroundWindow()?.requestRender(),
|
||||
},
|
||||
apps: ctx.apps
|
||||
.filter((app) => app.showInLauncher !== false)
|
||||
.map((app) => ({ appId: app.appId, label: app.title, icon: app.icon })),
|
||||
apps: () => [
|
||||
...ctx.apps
|
||||
.filter((app) => app.showInLauncher !== false)
|
||||
.map((app) => ({ appId: app.appId, label: app.title, icon: app.icon })),
|
||||
...getInstalledEvenHubApps().map((app) => ({
|
||||
appId: installedEvenHubAppId(app.packageId),
|
||||
label: app.name,
|
||||
icon: "package" as const,
|
||||
renderIcon: (size: number) => renderInstalledEvenHubIcon(app.packageId, size, app),
|
||||
iconKey: `${app.installedAt}:${app.iconFile ?? ""}`,
|
||||
uninstallable: true,
|
||||
})),
|
||||
],
|
||||
launchApp: (appId) => ctx.launchApp(appId),
|
||||
uninstallApp: (appId) => ctx.uninstallApp(appId),
|
||||
submitFrame: (image, paintMs, frameId) => ctx.submitWindowFrame(LAUNCHER_SURFACE_ID, image, paintMs, frameId),
|
||||
setSurfaceVisible: (visible) => ctx.setWindowSurfaceVisible(LAUNCHER_SURFACE_ID, visible),
|
||||
}),
|
||||
|
||||
@@ -26,12 +26,17 @@ export type LauncherAppEntry = {
|
||||
appId: string;
|
||||
label: string;
|
||||
icon: IconName;
|
||||
uninstallable?: boolean;
|
||||
/** Dynamic artwork for installed apps; icon remains the fallback. */
|
||||
renderIcon?: (size: number) => GrayImage | null;
|
||||
iconKey?: string;
|
||||
};
|
||||
|
||||
export type LauncherOptions = {
|
||||
actions: LayerActions;
|
||||
apps: LauncherAppEntry[];
|
||||
apps: () => LauncherAppEntry[];
|
||||
launchApp: (appId: string) => Promise<void> | void;
|
||||
uninstallApp: (appId: string) => Promise<void> | void;
|
||||
/** Submit a painted viewport-sized frame to this window's surface. */
|
||||
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
|
||||
/** Flip the launcher's compositor surface visibility on foreground changes. */
|
||||
@@ -58,7 +63,7 @@ type LauncherMode = "row" | "item";
|
||||
|
||||
/** One cell of the grid: an app, or a folder holding some of the apps. */
|
||||
type LauncherGridEntry =
|
||||
| { kind: "app"; label: string; icon: IconName; appId: string }
|
||||
| { kind: "app"; label: string; icon: IconName; appId: string; renderIcon?: (size: number) => GrayImage | null }
|
||||
| { kind: "folder"; label: string; name: string };
|
||||
|
||||
/**
|
||||
@@ -90,14 +95,21 @@ class LauncherGridLayer implements Layer {
|
||||
* disbanded it), the view falls back to the top grid.
|
||||
*/
|
||||
private entries(): LauncherGridEntry[] {
|
||||
const byAppId = new Map(this.options.apps.map((app) => [app.appId, app]));
|
||||
const apps = this.options.apps();
|
||||
const byAppId = new Map(apps.map((app) => [app.appId, app]));
|
||||
if (this.currentFolder !== null) {
|
||||
const members = (getFolders().get(this.currentFolder) ?? [])
|
||||
.map((appId) => byAppId.get(appId))
|
||||
.filter(Boolean) as LauncherAppEntry[];
|
||||
if (members.length > 0) {
|
||||
return members
|
||||
.map((app): LauncherGridEntry => ({ kind: "app", label: app.label, icon: app.icon, appId: app.appId }))
|
||||
.map((app): LauncherGridEntry => ({
|
||||
kind: "app",
|
||||
label: app.label,
|
||||
icon: app.icon,
|
||||
appId: app.appId,
|
||||
renderIcon: app.renderIcon,
|
||||
}))
|
||||
.sort((a, b) => a.label.localeCompare(b.label));
|
||||
}
|
||||
this.currentFolder = null;
|
||||
@@ -111,9 +123,15 @@ class LauncherGridLayer implements Layer {
|
||||
entries.push({ kind: "folder", label: name, name });
|
||||
}
|
||||
}
|
||||
for (const app of this.options.apps) {
|
||||
for (const app of apps) {
|
||||
if (!assignments[app.appId]) {
|
||||
entries.push({ kind: "app", label: app.label, icon: app.icon, appId: app.appId });
|
||||
entries.push({
|
||||
kind: "app",
|
||||
label: app.label,
|
||||
icon: app.icon,
|
||||
appId: app.appId,
|
||||
renderIcon: app.renderIcon,
|
||||
});
|
||||
}
|
||||
}
|
||||
return entries.sort((a, b) => a.label.localeCompare(b.label));
|
||||
@@ -155,6 +173,32 @@ class LauncherGridLayer implements Layer {
|
||||
);
|
||||
},
|
||||
},
|
||||
...(this.options.apps().find((app) => app.appId === entry.appId)?.uninstallable
|
||||
? [{
|
||||
label: "Uninstall",
|
||||
onSelect: (ctx: LayerContext) => {
|
||||
ctx.stack.pop();
|
||||
ctx.stack.push(
|
||||
new MenuLayer(
|
||||
"Uninstall app?",
|
||||
[
|
||||
{
|
||||
label: "Confirm uninstall",
|
||||
onSelect: async (confirmCtx) => {
|
||||
confirmCtx.stack.pop();
|
||||
setAppFolder(entry.appId, null);
|
||||
await this.options.uninstallApp(entry.appId);
|
||||
this.mode = "row";
|
||||
},
|
||||
},
|
||||
{ label: "Cancel", onSelect: (confirmCtx) => confirmCtx.stack.pop() },
|
||||
],
|
||||
WINDOW_MENU_LAYOUT,
|
||||
),
|
||||
);
|
||||
},
|
||||
} satisfies MenuItem]
|
||||
: []),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -237,7 +281,9 @@ class LauncherGridLayer implements Layer {
|
||||
const blockTop = rowY(row) + Math.max(2, (rowH - ICON_SIZE - font.lineHeight - LABEL_GAP) / 2);
|
||||
if (blockTop >= gridBottom) break; // fully below the grid
|
||||
const centerX = (index % COLS) * colW + colW / 2;
|
||||
const icon = renderIcon(entry.kind === "app" ? entry.icon : "folder-filled", ICON_SIZE);
|
||||
const icon = entry.kind === "app"
|
||||
? entry.renderIcon?.(ICON_SIZE) ?? renderIcon(entry.icon, ICON_SIZE)
|
||||
: renderIcon("folder-filled", ICON_SIZE);
|
||||
if (icon) {
|
||||
// Clip the icon at the grid bottom so a peeking row shows only its top.
|
||||
const clipHeight = Math.min(icon.height, Math.floor(gridBottom - blockTop));
|
||||
@@ -357,12 +403,18 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
|
||||
// keeps every unrelated setting change from repainting the launcher. The
|
||||
// launcher is pinned for the app's lifetime, so the subscription never needs
|
||||
// tearing down.
|
||||
let lastFolderState = getFolderStateFingerprint();
|
||||
let lastState = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
onAnySettingChanged(() => {
|
||||
const state = getFolderStateFingerprint();
|
||||
if (state === lastFolderState) return;
|
||||
lastFolderState = state;
|
||||
const state = `${getFolderStateFingerprint()}\n${launcherAppsFingerprint(options.apps())}`;
|
||||
if (state === lastState) return;
|
||||
lastState = state;
|
||||
created.requestRender();
|
||||
});
|
||||
return created.window;
|
||||
}
|
||||
|
||||
function launcherAppsFingerprint(apps: LauncherAppEntry[]): string {
|
||||
return apps
|
||||
.map((app) => `${app.appId}:${app.label}:${app.icon}:${app.iconKey ?? ""}:${app.uninstallable ? 1 : 0}`)
|
||||
.join("|");
|
||||
}
|
||||
Reference in new issue
Block a user