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
@@ -50,6 +50,8 @@ export type AppContext = {
|
||||
actions: Omit<LayerActions, "requestRender">;
|
||||
/** Launch (or focus) any app by id through the shell. */
|
||||
launchApp: (appId: string, params?: AppLaunchParams) => Promise<void>;
|
||||
/** Uninstall a dynamically registered app, if the app id supports it. */
|
||||
uninstallApp: (appId: string) => Promise<void>;
|
||||
/** Launch-or-focus a main-thread singleton window keyed by windowId. */
|
||||
launchInProcessApp: (
|
||||
windowId: string,
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
declare const android: any;
|
||||
|
||||
const API_HOST = "https://api.evenrealities.com";
|
||||
const PUBLIC_CDN_HOST = "https://cdn-pub.evenhub.evenrealities.com";
|
||||
const SIGN_KEY = "a7964f42c39200cfa25c258b7a311b106e20232173667e543c34ced91d63b404";
|
||||
const REQUEST_TIMEOUT_MS = 30_000;
|
||||
|
||||
@@ -28,6 +29,11 @@ export type EvenHubStoreApp = {
|
||||
installCount: number;
|
||||
likeCount: number;
|
||||
firstPublishedAt: string;
|
||||
/** Public-CDN-relative SVG/raster artwork path. */
|
||||
iconPath: string;
|
||||
version: string;
|
||||
changelog: string;
|
||||
fileSize: number;
|
||||
};
|
||||
|
||||
export type EvenHubStorePage = {
|
||||
@@ -82,6 +88,10 @@ export class EvenHubApiClient {
|
||||
return asRecord(data);
|
||||
}
|
||||
|
||||
async getStoreAppDetail(packageId: string): Promise<EvenHubStoreApp | null> {
|
||||
return parseStoreApp(await this.getAppDetail(packageId));
|
||||
}
|
||||
|
||||
/** Resolve the signed download URL, then fetch and sanity-check its EHPK. */
|
||||
async downloadApp(packageId: string): Promise<Uint8Array> {
|
||||
const data = await this.authenticatedRequest("POST", "/v2/evenhub/app/download", {
|
||||
@@ -104,6 +114,22 @@ export class EvenHubApiClient {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/** Download one public storefront asset, constrained to Even's CDN path. */
|
||||
async downloadPublicAsset(path: string): Promise<{ bytes: Uint8Array; extension: string }> {
|
||||
const cleanPath = path.replace(/^\/+/, "");
|
||||
if (!/^prod\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]+\.(?:svg|png|webp|jpe?g)$/i.test(cleanPath) || cleanPath.includes("..")) {
|
||||
throw new Error("EvenHub returned an invalid public asset path.");
|
||||
}
|
||||
const response = await fetchWithTimeout(`${PUBLIC_CDN_HOST}/${cleanPath}`, {}, 30_000);
|
||||
if (!response.ok) throw new Error(`EvenHub icon download failed (HTTP ${response.status}).`);
|
||||
const contentLength = Number(response.headers.get("Content-Length") ?? 0);
|
||||
if (contentLength > 1_000_000) throw new Error("EvenHub icon is unexpectedly large.");
|
||||
const bytes = new Uint8Array(await response.arrayBuffer());
|
||||
if (bytes.length === 0 || bytes.length > 1_000_000) throw new Error("EvenHub icon is empty or too large.");
|
||||
const extension = cleanPath.toLowerCase().match(/\.([a-z0-9]+)$/)?.[1] ?? "";
|
||||
return { bytes, extension: extension === "jpeg" ? "jpg" : extension };
|
||||
}
|
||||
|
||||
clearSession(): void {
|
||||
this.token = "";
|
||||
this.loginPromise = null;
|
||||
@@ -297,6 +323,7 @@ function unwrap(envelope: ApiEnvelope, httpStatus: number, path: string): unknow
|
||||
|
||||
function parseStoreApp(value: unknown): EvenHubStoreApp | null {
|
||||
const item = asRecord(value);
|
||||
const version = asRecord(item.version);
|
||||
const packageId = stringValue(item.package_id);
|
||||
if (!packageId) return null;
|
||||
return {
|
||||
@@ -309,7 +336,11 @@ function parseStoreApp(value: unknown): EvenHubStoreApp | null {
|
||||
categories: Array.isArray(item.category) ? item.category.map(stringValue).filter(Boolean) : [],
|
||||
installCount: finiteNumber(item.install_count),
|
||||
likeCount: finiteNumber(item.like_count),
|
||||
firstPublishedAt: stringValue(item.first_published_at),
|
||||
firstPublishedAt: stringValue(item.first_published_at || item.created_at),
|
||||
iconPath: stringValue(item.icon),
|
||||
version: stringValue(version.version || item.latest_version),
|
||||
changelog: stringValue(version.changelog),
|
||||
fileSize: finiteNumber(version.file_size),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ import {
|
||||
type InProcessWindow,
|
||||
} from "../../ui/shell/in-process-window";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer";
|
||||
import { EvenHubSession } from "./session";
|
||||
import { renderInstalledEvenHubIcon } from "./installed-apps";
|
||||
|
||||
class EvenHubAppLayer implements Layer {
|
||||
constructor(private readonly session: EvenHubSession) {}
|
||||
@@ -31,16 +33,22 @@ class EvenHubAppLayer implements Layer {
|
||||
|
||||
export function createEvenHubWindow(
|
||||
windowId: string,
|
||||
appId: string,
|
||||
session: EvenHubSession,
|
||||
options: InProcessAppOptions,
|
||||
onShowPhone: () => void,
|
||||
): InProcessWindow {
|
||||
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
||||
const created = createInProcessWindow({
|
||||
appId: "evenhub",
|
||||
appId,
|
||||
windowId,
|
||||
title: session.manifest.name,
|
||||
iconLetter: session.manifest.name.charAt(0).toUpperCase() || "E",
|
||||
closeable: true,
|
||||
drawIcon: makeImageWindowIcon(
|
||||
(size) => renderInstalledEvenHubIcon(session.manifest.packageId, size),
|
||||
fallbackIcon,
|
||||
),
|
||||
heightMode: "medium",
|
||||
// Glasses-first: the app runs without the phone showing it; this reveals
|
||||
// its phone UI (config pages, etc.) over the dashboard on demand.
|
||||
|
||||
@@ -37,7 +37,7 @@ const evenhubApp: AppDefinition = {
|
||||
}
|
||||
let created: InProcessWindow | null = null;
|
||||
const store = new EvenHubStoreLayer({
|
||||
openPackage: (path) => openEvenHubPackage(ctx, path),
|
||||
launchApp: (appId) => ctx.launchApp(appId),
|
||||
openSettings: () => ctx.launchApp("settings", { section: "EvenHub" }),
|
||||
appendLog: ctx.appendLog,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
/**
|
||||
* Persistent registry and package storage for user-installed EvenHub apps.
|
||||
*
|
||||
* The EHPK itself is the source of truth for the runnable app. A small JSON
|
||||
* index in Faceclaw's settings store makes installed packages discoverable by
|
||||
* the launcher without expanding the static built-in AppDefinition registry.
|
||||
*/
|
||||
import {
|
||||
appFilesDirPath,
|
||||
deletePathRecursively,
|
||||
readBinaryFile,
|
||||
readTextFile,
|
||||
writeBinaryFile,
|
||||
} from "../../native/file-access";
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
import { loadImageFileAsGray } from "../../native/image-files";
|
||||
import { renderSvgIcon } from "../../graphics/icons";
|
||||
import { type GrayImage } from "../../graphics/image";
|
||||
import { parseEhpk, parseManifest, utf8Decode, type EhpkArchive, type EvenHubManifest } from "./ehpk";
|
||||
|
||||
const STORAGE_KEY = "evenhub.installedApps.v1";
|
||||
const APP_ID_PREFIX = "evenhub-installed:";
|
||||
|
||||
export type InstalledEvenHubApp = {
|
||||
packageId: string;
|
||||
name: string;
|
||||
version: string;
|
||||
installedAt: string;
|
||||
/** Filename beneath the installed package directory, when artwork is available. */
|
||||
iconFile?: string;
|
||||
};
|
||||
|
||||
export type EvenHubInstallIcon = {
|
||||
bytes: Uint8Array;
|
||||
extension: string;
|
||||
};
|
||||
|
||||
const renderedIconCache = new Map<string, GrayImage | null>();
|
||||
|
||||
export function installedEvenHubAppId(packageId: string): string {
|
||||
return `${APP_ID_PREFIX}${encodeURIComponent(packageId)}`;
|
||||
}
|
||||
|
||||
export function installedEvenHubPackageId(appId: string): string | null {
|
||||
if (!appId.startsWith(APP_ID_PREFIX)) return null;
|
||||
try {
|
||||
const packageId = decodeURIComponent(appId.slice(APP_ID_PREFIX.length));
|
||||
return packageId || null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getInstalledEvenHubApps(): InstalledEvenHubApp[] {
|
||||
const raw = getStringSetting(STORAGE_KEY, "");
|
||||
if (!raw) return [];
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
const apps: InstalledEvenHubApp[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const value of parsed) {
|
||||
if (!value || typeof value !== "object") continue;
|
||||
const item = value as Record<string, unknown>;
|
||||
const packageId = stringValue(item.packageId).trim();
|
||||
if (!packageId || seen.has(packageId)) continue;
|
||||
seen.add(packageId);
|
||||
apps.push({
|
||||
packageId,
|
||||
name: stringValue(item.name).trim() || packageId,
|
||||
version: stringValue(item.version).trim() || "0",
|
||||
installedAt: stringValue(item.installedAt),
|
||||
iconFile: safeIconFilename(stringValue(item.iconFile)),
|
||||
});
|
||||
}
|
||||
return apps.sort((a, b) => a.name.localeCompare(b.name));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function getInstalledEvenHubApp(packageId: string): InstalledEvenHubApp | null {
|
||||
return getInstalledEvenHubApps().find((app) => app.packageId === packageId) ?? null;
|
||||
}
|
||||
|
||||
export function getInstalledEvenHubAppById(appId: string): InstalledEvenHubApp | null {
|
||||
const packageId = installedEvenHubPackageId(appId);
|
||||
return packageId ? getInstalledEvenHubApp(packageId) : null;
|
||||
}
|
||||
|
||||
export function installedEvenHubPackagePath(packageId: string): string {
|
||||
return `${installedRoot(packageId)}/package.ehpk`;
|
||||
}
|
||||
|
||||
/** Validate and copy an EHPK into Faceclaw's app-private installed store. */
|
||||
export function installEvenHubPackageBytes(
|
||||
bytes: Uint8Array,
|
||||
options: { expectedPackageId?: string; icon?: EvenHubInstallIcon } = {},
|
||||
): InstalledEvenHubApp {
|
||||
const { archive, manifest } = inspectEhpk(bytes);
|
||||
if (!manifest.packageId || manifest.packageId === "unknown.package") {
|
||||
throw new Error("The EHPK manifest has no package ID.");
|
||||
}
|
||||
if (options.expectedPackageId && manifest.packageId !== options.expectedPackageId) {
|
||||
throw new Error(`Downloaded package ID ${manifest.packageId} does not match ${options.expectedPackageId}.`);
|
||||
}
|
||||
const root = installedRoot(manifest.packageId);
|
||||
const path = installedEvenHubPackagePath(manifest.packageId);
|
||||
if (!writeBinaryFile(path, bytes)) {
|
||||
throw new Error(`Could not store ${manifest.name}.`);
|
||||
}
|
||||
const previous = getInstalledEvenHubApp(manifest.packageId);
|
||||
const icon = normalizeInstallIcon(options.icon) ?? findEmbeddedIcon(archive, manifest);
|
||||
let iconFile = previous?.iconFile;
|
||||
if (icon) {
|
||||
const candidate = `icon.${icon.extension}`;
|
||||
if (writeBinaryFile(`${root}/${candidate}`, icon.bytes)) {
|
||||
iconFile = candidate;
|
||||
clearStoredIcons(root, candidate);
|
||||
} else {
|
||||
console.warn(`evenhub: could not store icon for ${manifest.packageId}`);
|
||||
}
|
||||
}
|
||||
clearRenderedIconCache(manifest.packageId);
|
||||
const installed: InstalledEvenHubApp = {
|
||||
packageId: manifest.packageId,
|
||||
name: manifest.name,
|
||||
version: manifest.version,
|
||||
installedAt: new Date().toISOString(),
|
||||
iconFile: iconFile && readBinaryFile(`${root}/${iconFile}`) ? iconFile : undefined,
|
||||
};
|
||||
const apps = getInstalledEvenHubApps().filter((app) => app.packageId !== installed.packageId);
|
||||
apps.push(installed);
|
||||
saveInstalledApps(apps);
|
||||
return installed;
|
||||
}
|
||||
|
||||
/** Validate and install an EHPK selected in Files. */
|
||||
export function installEvenHubPackageFile(path: string): InstalledEvenHubApp {
|
||||
const bytes = readBinaryFile(path);
|
||||
if (!bytes) throw new Error("Could not read the EHPK file.");
|
||||
return installEvenHubPackageBytes(bytes);
|
||||
}
|
||||
|
||||
/** Remove the stored EHPK, unpacked runtime files, and registry entry. */
|
||||
export function uninstallEvenHubPackage(packageId: string): boolean {
|
||||
const apps = getInstalledEvenHubApps();
|
||||
if (!apps.some((app) => app.packageId === packageId)) return false;
|
||||
saveInstalledApps(apps.filter((app) => app.packageId !== packageId));
|
||||
deletePathRecursively(installedRoot(packageId));
|
||||
deletePathRecursively(`${appFilesDirPath()}/evenhub-apps/${safePackageId(packageId)}`);
|
||||
clearRenderedIconCache(packageId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Add or replace artwork for an existing install (used to backfill old installs). */
|
||||
export function setInstalledEvenHubIcon(packageId: string, icon: EvenHubInstallIcon): boolean {
|
||||
const normalized = normalizeInstallIcon(icon);
|
||||
const apps = getInstalledEvenHubApps();
|
||||
const index = apps.findIndex((app) => app.packageId === packageId);
|
||||
if (!normalized || index < 0) return false;
|
||||
const root = installedRoot(packageId);
|
||||
const iconFile = `icon.${normalized.extension}`;
|
||||
if (!writeBinaryFile(`${root}/${iconFile}`, normalized.bytes)) return false;
|
||||
clearStoredIcons(root, iconFile);
|
||||
apps[index] = { ...apps[index]!, iconFile };
|
||||
clearRenderedIconCache(packageId);
|
||||
saveInstalledApps(apps);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Render an installed app's SVG/raster artwork at launcher/sidebar size. */
|
||||
export function renderInstalledEvenHubIcon(
|
||||
packageId: string,
|
||||
size: number,
|
||||
installedApp?: InstalledEvenHubApp,
|
||||
): GrayImage | null {
|
||||
const app = installedApp ?? getInstalledEvenHubApp(packageId);
|
||||
if (!app?.iconFile) return null;
|
||||
const cacheKey = `${packageId}:${app.installedAt}:${app.iconFile}:${Math.round(size)}`;
|
||||
if (renderedIconCache.has(cacheKey)) return renderedIconCache.get(cacheKey) ?? null;
|
||||
const path = `${installedRoot(packageId)}/${app.iconFile}`;
|
||||
let image: GrayImage | null = null;
|
||||
if (app.iconFile.endsWith(".svg")) {
|
||||
const svg = readTextFile(path);
|
||||
if (svg) image = renderSvgIcon(cacheKey, svg, size);
|
||||
} else {
|
||||
image = loadImageFileAsGray(path, size, size);
|
||||
}
|
||||
renderedIconCache.set(cacheKey, image);
|
||||
return image;
|
||||
}
|
||||
|
||||
/** Raw registry value, suitable for cheap launcher change detection. */
|
||||
export function getInstalledEvenHubFingerprint(): string {
|
||||
return getStringSetting(STORAGE_KEY, "");
|
||||
}
|
||||
|
||||
function inspectEhpk(bytes: Uint8Array): { archive: EhpkArchive; manifest: EvenHubManifest } {
|
||||
const archive = parseEhpk(bytes);
|
||||
const appJson = archive.files.get("app.json");
|
||||
if (!appJson) throw new Error("The EHPK package has no app.json manifest.");
|
||||
return { archive, manifest: parseManifest(utf8Decode(appJson)) };
|
||||
}
|
||||
|
||||
function installedRoot(packageId: string): string {
|
||||
return `${appFilesDirPath()}/evenhub-installed/${safePackageId(packageId)}`;
|
||||
}
|
||||
|
||||
function safePackageId(packageId: string): string {
|
||||
return packageId.replace(/[^A-Za-z0-9._-]/g, "_");
|
||||
}
|
||||
|
||||
function saveInstalledApps(apps: InstalledEvenHubApp[]): void {
|
||||
setStringSetting(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify(apps.slice().sort((a, b) => a.name.localeCompare(b.name))),
|
||||
);
|
||||
}
|
||||
|
||||
function findEmbeddedIcon(archive: EhpkArchive, manifest: EvenHubManifest): EvenHubInstallIcon | null {
|
||||
const candidates: string[] = [];
|
||||
for (const key of ["icon", "icon_path", "iconPath", "app_icon", "appIcon"]) {
|
||||
const value = manifest.raw[key];
|
||||
if (typeof value === "string") candidates.push(value);
|
||||
}
|
||||
const entrypoint = archive.files.get(`dist/${manifest.entrypoint}`);
|
||||
if (entrypoint) {
|
||||
const html = utf8Decode(entrypoint);
|
||||
for (const tag of html.match(/<link\b[^>]*>/gi) ?? []) {
|
||||
if (!/\brel\s*=\s*["'][^"']*icon/i.test(tag)) continue;
|
||||
const href = tag.match(/\bhref\s*=\s*["']([^"']+)/i)?.[1];
|
||||
if (href) candidates.push(href);
|
||||
}
|
||||
}
|
||||
candidates.push(
|
||||
"icon.svg", "icon.png", "favicon.svg", "favicon.png",
|
||||
"dist/icon.svg", "dist/icon.png", "dist/favicon.svg", "dist/favicon.png",
|
||||
);
|
||||
for (const candidate of candidates) {
|
||||
const normalized = normalizeArchivePath(candidate);
|
||||
if (!normalized) continue;
|
||||
for (const path of [normalized, `dist/${normalized}`]) {
|
||||
const content = archive.files.get(path);
|
||||
const extension = iconExtension(path);
|
||||
if (content && extension) return { bytes: content, extension };
|
||||
}
|
||||
}
|
||||
const fallback = Array.from(archive.files.entries()).find(([path]) =>
|
||||
/(?:^|\/)(?:app-?)?(?:icon|favicon)\.(?:svg|png|webp|jpe?g)$/i.test(path),
|
||||
);
|
||||
const extension = fallback ? iconExtension(fallback[0]) : null;
|
||||
return fallback && extension ? { bytes: fallback[1], extension } : null;
|
||||
}
|
||||
|
||||
function normalizeInstallIcon(icon: EvenHubInstallIcon | undefined): EvenHubInstallIcon | null {
|
||||
if (!icon || icon.bytes.length === 0 || icon.bytes.length > 1_000_000) return null;
|
||||
const extension = iconExtension(`icon.${icon.extension}`);
|
||||
return extension ? { bytes: icon.bytes, extension } : null;
|
||||
}
|
||||
|
||||
function normalizeArchivePath(path: string): string {
|
||||
const clean = path.split(/[?#]/, 1)[0]!.replace(/^\.\//, "").replace(/^\//, "");
|
||||
return !clean || clean.includes("..") || /^[a-z]+:/i.test(clean) ? "" : clean;
|
||||
}
|
||||
|
||||
function iconExtension(path: string): string | null {
|
||||
const match = path.toLowerCase().match(/\.(svg|png|webp|jpe?g)$/);
|
||||
return match ? (match[1] === "jpeg" ? "jpg" : match[1]!) : null;
|
||||
}
|
||||
|
||||
function safeIconFilename(value: string): string | undefined {
|
||||
return /^icon\.(?:svg|png|webp|jpg)$/i.test(value) ? value.toLowerCase() : undefined;
|
||||
}
|
||||
|
||||
function clearStoredIcons(root: string, keep = ""): void {
|
||||
for (const extension of ["svg", "png", "webp", "jpg"]) {
|
||||
const filename = `icon.${extension}`;
|
||||
if (filename !== keep) deletePathRecursively(`${root}/${filename}`);
|
||||
}
|
||||
}
|
||||
|
||||
function clearRenderedIconCache(packageId: string): void {
|
||||
for (const key of Array.from(renderedIconCache.keys())) {
|
||||
if (key.startsWith(`${packageId}:`)) renderedIconCache.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
function stringValue(value: unknown): string {
|
||||
return typeof value === "string" ? value : value == null ? "" : String(value);
|
||||
}
|
||||
@@ -22,9 +22,17 @@ import { parseEhpk, parseManifest, utf8Decode } from "./ehpk";
|
||||
import { EvenHubSession } from "./session";
|
||||
import { createEvenHubWindow } from "./evenhub-window";
|
||||
import { createEvenHubWebView, type EvenHubWebView } from "./webview";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import {
|
||||
installedEvenHubAppId,
|
||||
installedEvenHubPackagePath,
|
||||
type InstalledEvenHubApp,
|
||||
} from "./installed-apps";
|
||||
|
||||
type RunningApp = {
|
||||
windowId: string;
|
||||
appId: string;
|
||||
packageId: string;
|
||||
session: EvenHubSession;
|
||||
webView: EvenHubWebView;
|
||||
};
|
||||
@@ -50,7 +58,11 @@ function ensureBackHandler(): void {
|
||||
* Unpack an .ehpk and launch it as a new concurrent app: a glasses window plus
|
||||
* a persistent WebView. Does not disturb other running apps or the phone screen.
|
||||
*/
|
||||
export async function launchPackage(ctx: AppContext, ehpkPath: string): Promise<void> {
|
||||
export async function launchPackage(
|
||||
ctx: AppContext,
|
||||
ehpkPath: string,
|
||||
options: { appId?: string; singleton?: boolean } = {},
|
||||
): Promise<void> {
|
||||
const data = readBinaryFile(ehpkPath);
|
||||
if (!data) {
|
||||
ctx.appendLog(`evenhub: could not read ${ehpkPath}`);
|
||||
@@ -63,6 +75,15 @@ export async function launchPackage(ctx: AppContext, ehpkPath: string): Promise<
|
||||
return;
|
||||
}
|
||||
const manifest = parseManifest(utf8Decode(appJson));
|
||||
const appId = options.appId ?? "evenhub";
|
||||
if (options.singleton) {
|
||||
const existing = Array.from(running.values()).find((app) => app.appId === appId);
|
||||
if (existing) {
|
||||
shell.focusWindow(existing.windowId);
|
||||
ctx.requestShellRender();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Unpack fresh into app-private storage, keyed by package id.
|
||||
const safeId = manifest.packageId.replace(/[^A-Za-z0-9._-]/g, "_");
|
||||
@@ -89,15 +110,31 @@ export async function launchPackage(ctx: AppContext, ehpkPath: string): Promise<
|
||||
running.delete(windowId);
|
||||
},
|
||||
});
|
||||
running.set(windowId, { windowId, session, webView });
|
||||
running.set(windowId, { windowId, appId, packageId: manifest.packageId, session, webView });
|
||||
ensureBackHandler();
|
||||
ctx.appendLog(`evenhub: launching ${manifest.name} ${manifest.version} (${manifest.packageId})`);
|
||||
|
||||
await ctx.launchInProcessApp(windowId, `window:${windowId}`, (options) =>
|
||||
createEvenHubWindow(windowId, session, options, () => showOnPhone(windowId)),
|
||||
createEvenHubWindow(windowId, appId, session, options, () => showOnPhone(windowId)),
|
||||
);
|
||||
}
|
||||
|
||||
/** Launch an installed app as a launcher-addressable singleton. */
|
||||
export function launchInstalledPackage(ctx: AppContext, app: InstalledEvenHubApp): Promise<void> {
|
||||
return launchPackage(ctx, installedEvenHubPackagePath(app.packageId), {
|
||||
appId: installedEvenHubAppId(app.packageId),
|
||||
singleton: true,
|
||||
});
|
||||
}
|
||||
|
||||
/** Close every running instance before an installed package is removed. */
|
||||
export function closeRunningPackage(packageId: string): void {
|
||||
const windowIds = Array.from(running.values())
|
||||
.filter((app) => app.packageId === packageId)
|
||||
.map((app) => app.windowId);
|
||||
for (const windowId of windowIds) shell.closeWindow(windowId);
|
||||
}
|
||||
|
||||
/** Overlay one app's phone UI over the dashboard (from its window menu). */
|
||||
export function showOnPhone(windowId: string): void {
|
||||
const app = running.get(windowId);
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
|
||||
import { type DashboardInputEvent, type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { evenHubApi, type EvenHubStoreApp } from "./even-api";
|
||||
import {
|
||||
getInstalledEvenHubApp,
|
||||
installEvenHubPackageBytes,
|
||||
installedEvenHubAppId,
|
||||
setInstalledEvenHubIcon,
|
||||
} from "./installed-apps";
|
||||
|
||||
const X = 18;
|
||||
const BUTTON_HEIGHT = 24;
|
||||
|
||||
export type EvenHubStoreDetailOptions = {
|
||||
launchApp: (appId: string) => Promise<void> | void;
|
||||
appendLog: (message: string) => void;
|
||||
};
|
||||
|
||||
/** Storefront metadata and the Install/Launch action for one public app. */
|
||||
export class EvenHubStoreDetailLayer implements Layer {
|
||||
private working = false;
|
||||
private detailPromise: Promise<void> | null = null;
|
||||
private status = "";
|
||||
|
||||
constructor(
|
||||
private app: EvenHubStoreApp,
|
||||
private readonly options: EvenHubStoreDetailOptions,
|
||||
) {}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
if (!this.detailPromise) void this.ensureDetail(ctx);
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const textWidth = width - X * 2;
|
||||
let y = 8;
|
||||
|
||||
image.drawText(font, X, y, truncateText(font, this.app.name, textWidth), 235);
|
||||
y += 16;
|
||||
const creator = this.app.creatorName ? `by ${this.app.creatorName}` : this.app.packageId;
|
||||
image.drawText(font, X, y, truncateText(font, creator, textWidth), 130);
|
||||
y += 20;
|
||||
|
||||
const summary = this.app.tagline || this.app.description || "No description supplied.";
|
||||
for (const line of wrapText(font, summary, textWidth).slice(0, 3)) {
|
||||
image.drawText(font, X, y, line, 205);
|
||||
y += 14;
|
||||
}
|
||||
y += 4;
|
||||
|
||||
const metadata = [
|
||||
`${formatCount(this.app.installCount)} installs · ${formatCount(this.app.likeCount)} likes`,
|
||||
this.app.version ? `Version ${this.app.version}${this.app.fileSize ? ` · ${formatBytes(this.app.fileSize)}` : ""}` : "",
|
||||
this.app.categories.length ? `Categories: ${this.app.categories.join(", ")}` : "",
|
||||
this.app.firstPublishedAt ? `Published: ${formatDate(this.app.firstPublishedAt)}` : "",
|
||||
].filter(Boolean);
|
||||
for (const line of metadata) {
|
||||
image.drawText(font, X, y, truncateText(font, line, textWidth), 125);
|
||||
y += 14;
|
||||
}
|
||||
|
||||
const installed = getInstalledEvenHubApp(this.app.packageId);
|
||||
if (installed) {
|
||||
image.drawText(font, X, y + 2, `Installed version ${installed.version}`, 155);
|
||||
}
|
||||
if (this.status) {
|
||||
image.drawText(font, X, Math.min(height - 58, y + 18), truncateText(font, this.status, textWidth), 180);
|
||||
}
|
||||
|
||||
const buttonY = height - 48;
|
||||
drawSelectionHighlight(image, X - 5, buttonY, textWidth + 10, BUTTON_HEIGHT, ctx.stack.isFocused(), 8);
|
||||
const label = this.working ? "Installing..." : installed ? "Launch" : "Install";
|
||||
image.drawText(font, X + 6, buttonY + 5, label, this.working ? 145 : 245);
|
||||
image.drawText(
|
||||
font,
|
||||
X,
|
||||
height - 16,
|
||||
`${GESTURE_CLICK} ${installed ? "launch" : "install"} ${GESTURE_DOUBLE_CLICK} back`,
|
||||
105,
|
||||
);
|
||||
return image;
|
||||
}
|
||||
|
||||
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (event.type === "double-click") {
|
||||
if (!this.working) ctx.stack.pop();
|
||||
return;
|
||||
}
|
||||
if (event.type !== "click" || this.working) return;
|
||||
|
||||
await this.ensureDetail(ctx);
|
||||
|
||||
const installed = getInstalledEvenHubApp(this.app.packageId);
|
||||
if (installed) {
|
||||
await this.options.launchApp(installedEvenHubAppId(installed.packageId));
|
||||
return;
|
||||
}
|
||||
|
||||
this.working = true;
|
||||
this.status = `Downloading ${this.app.name}...`;
|
||||
ctx.actions.requestRender();
|
||||
try {
|
||||
const [bytes, icon] = await Promise.all([
|
||||
evenHubApi.downloadApp(this.app.packageId),
|
||||
this.app.iconPath
|
||||
? evenHubApi.downloadPublicAsset(this.app.iconPath).catch((error) => {
|
||||
this.options.appendLog(`evenhub store: icon unavailable for ${this.app.packageId}: ${cleanError(error)}`);
|
||||
return undefined;
|
||||
})
|
||||
: Promise.resolve(undefined),
|
||||
]);
|
||||
this.status = "Installing...";
|
||||
ctx.actions.requestRender();
|
||||
const result = installEvenHubPackageBytes(bytes, {
|
||||
expectedPackageId: this.app.packageId,
|
||||
icon,
|
||||
});
|
||||
this.options.appendLog(
|
||||
`evenhub store: installed ${result.packageId} ${result.version} (${bytes.length} bytes)`,
|
||||
);
|
||||
this.status = "Installed";
|
||||
ctx.actions.requestRender();
|
||||
await this.options.launchApp(installedEvenHubAppId(result.packageId));
|
||||
} catch (error) {
|
||||
this.status = cleanError(error);
|
||||
this.options.appendLog(`evenhub store: ${this.status}`);
|
||||
} finally {
|
||||
this.working = false;
|
||||
ctx.actions.requestRender();
|
||||
}
|
||||
}
|
||||
|
||||
private ensureDetail(ctx: LayerContext): Promise<void> {
|
||||
if (this.detailPromise) return this.detailPromise;
|
||||
this.detailPromise = evenHubApi
|
||||
.getStoreAppDetail(this.app.packageId)
|
||||
.then((detail) => {
|
||||
if (detail) this.app = { ...this.app, ...detail };
|
||||
const installed = getInstalledEvenHubApp(this.app.packageId);
|
||||
if (installed && !installed.iconFile && this.app.iconPath) {
|
||||
return evenHubApi.downloadPublicAsset(this.app.iconPath).then((icon) => {
|
||||
setInstalledEvenHubIcon(this.app.packageId, icon);
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.options.appendLog(`evenhub store: app details unavailable: ${cleanError(error)}`);
|
||||
})
|
||||
.finally(() => ctx.actions.requestRender());
|
||||
return this.detailPromise;
|
||||
}
|
||||
}
|
||||
|
||||
function formatCount(value: number): string {
|
||||
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}m`;
|
||||
if (value >= 1000) return `${(value / 1000).toFixed(value >= 10_000 ? 0 : 1)}k`;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function formatDate(value: string): string {
|
||||
const date = new Date(value);
|
||||
return Number.isFinite(date.getTime()) ? date.toISOString().slice(0, 10) : value;
|
||||
}
|
||||
|
||||
function formatBytes(value: number): string {
|
||||
if (value < 1024) return `${value} B`;
|
||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
|
||||
return `${(value / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
function cleanError(error: unknown): string {
|
||||
return String((error as Error)?.message ?? error).replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
}
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
type MenuItem,
|
||||
} from "../../ui/menu";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { appFilesDirPath, writeBinaryFile } from "../../native/file-access";
|
||||
import { evenHubApi, isEvenHubStoreConfigured, type EvenHubStoreApp } from "./even-api";
|
||||
import { EvenHubStoreDetailLayer } from "./store-detail-layer";
|
||||
|
||||
const HEADER_HEIGHT = 34;
|
||||
const FOOTER_HEIGHT = 22;
|
||||
@@ -20,7 +20,7 @@ const ROW_HEIGHT = 30;
|
||||
const LIST_X = 18;
|
||||
|
||||
export type EvenHubStoreLayerOptions = {
|
||||
openPackage: (path: string) => Promise<void> | void;
|
||||
launchApp: (appId: string) => Promise<void> | void;
|
||||
openSettings: () => Promise<void> | void;
|
||||
appendLog: (message: string) => void;
|
||||
};
|
||||
@@ -34,7 +34,6 @@ export class EvenHubStoreLayer implements Layer {
|
||||
private nextPage = 1;
|
||||
private started = false;
|
||||
private loading = false;
|
||||
private downloadingPackageId = "";
|
||||
private status = "";
|
||||
|
||||
constructor(private readonly options: EvenHubStoreLayerOptions) {}
|
||||
@@ -75,9 +74,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, ROW_HEIGHT - 2, ctx.stack.isFocused(), 5);
|
||||
}
|
||||
const pending = app.packageId === this.downloadingPackageId;
|
||||
const title = pending ? `${app.name} (downloading...)` : app.name;
|
||||
image.drawText(font, LIST_X, y + 2, truncateText(font, title, width - LIST_X * 2), pending ? 255 : 215);
|
||||
image.drawText(font, LIST_X, y + 2, truncateText(font, app.name, width - LIST_X * 2), 215);
|
||||
const detail = app.tagline || `${app.creatorName} · ${formatCount(app.installCount)} installs`;
|
||||
image.drawText(font, LIST_X, y + 16, truncateText(font, detail, width - LIST_X * 2), 115);
|
||||
}
|
||||
@@ -88,7 +85,7 @@ export class EvenHubStoreLayer implements Layer {
|
||||
|
||||
const hint = !isEvenHubStoreConfigured()
|
||||
? `${GESTURE_CLICK} settings ${GESTURE_DOUBLE_CLICK} back`
|
||||
: `${GESTURE_SCROLL} select ${GESTURE_CLICK} download & run ${GESTURE_DOUBLE_CLICK} back`;
|
||||
: `${GESTURE_SCROLL} select ${GESTURE_CLICK} details ${GESTURE_DOUBLE_CLICK} back`;
|
||||
image.drawText(font, LIST_X, height - 16, truncateText(font, hint, width - LIST_X * 2), 105);
|
||||
return image;
|
||||
}
|
||||
@@ -109,9 +106,16 @@ export class EvenHubStoreLayer implements Layer {
|
||||
await this.options.openSettings();
|
||||
return;
|
||||
}
|
||||
if (!this.loading && !this.downloadingPackageId) {
|
||||
if (!this.loading) {
|
||||
const app = this.apps[this.selectedIndex];
|
||||
if (app) await this.downloadAndRun(app, ctx);
|
||||
if (app) {
|
||||
ctx.stack.push(
|
||||
new EvenHubStoreDetailLayer(app, {
|
||||
launchApp: this.options.launchApp,
|
||||
appendLog: this.options.appendLog,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
return;
|
||||
case "double-click":
|
||||
@@ -178,28 +182,6 @@ export class EvenHubStoreLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
private async downloadAndRun(app: EvenHubStoreApp, ctx: LayerContext): Promise<void> {
|
||||
this.downloadingPackageId = app.packageId;
|
||||
this.status = `Downloading ${app.name}...`;
|
||||
ctx.actions.requestRender();
|
||||
try {
|
||||
const bytes = await evenHubApi.downloadApp(app.packageId);
|
||||
const safeId = app.packageId.replace(/[^A-Za-z0-9._-]/g, "_");
|
||||
const path = `${appFilesDirPath()}/evenhub-downloads/${safeId}.ehpk`;
|
||||
if (!writeBinaryFile(path, bytes)) throw new Error("Could not save the downloaded EHPK package.");
|
||||
this.options.appendLog(`evenhub store: downloaded ${app.packageId} (${bytes.length} bytes)`);
|
||||
this.status = `Launching ${app.name}...`;
|
||||
ctx.actions.requestRender();
|
||||
await this.options.openPackage(path);
|
||||
this.status = "";
|
||||
} catch (error) {
|
||||
this.status = cleanError(error);
|
||||
this.options.appendLog(`evenhub store: ${this.status}`);
|
||||
} finally {
|
||||
this.downloadingPackageId = "";
|
||||
ctx.actions.requestRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanError(error: unknown): string {
|
||||
|
||||
@@ -27,6 +27,8 @@ export type FilesAppOptions = InProcessAppOptions & {
|
||||
openImageWindow: (title: string, path: string) => void;
|
||||
/** Launch an EvenHub app package (.ehpk) through the EvenHub host. */
|
||||
openEhpkApp: (path: string) => void;
|
||||
/** Copy an EHPK into the installed-app store, register it, and launch it. */
|
||||
installEhpkApp: (path: string) => Promise<void> | void;
|
||||
/** Open a font file's previewer as its own shell window. */
|
||||
openFontWindow: (title: string, path: string) => void;
|
||||
};
|
||||
@@ -170,6 +172,13 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
|
||||
options.openEhpkApp(entry.path);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Install",
|
||||
onSelect: async (ctx) => {
|
||||
ctx.stack.pop();
|
||||
await options.installEhpkApp(entry.path);
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
if (isDecodableImageFile(entry.name)) {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { type AppContext, type AppDefinition } from "../app-definition";
|
||||
import { openEvenHubPackage } from "../evenhub";
|
||||
import {
|
||||
installEvenHubPackageFile,
|
||||
installedEvenHubAppId,
|
||||
} from "../evenhub/installed-apps";
|
||||
import { closeRunningPackage } from "../evenhub/manager";
|
||||
import {
|
||||
createFilesAppWindow,
|
||||
createFontDocumentWindow,
|
||||
@@ -61,6 +66,16 @@ const filesApp: AppDefinition = {
|
||||
ctx.appendLog(`evenhub launch failed: ${error}`);
|
||||
});
|
||||
},
|
||||
installEhpkApp: async (path) => {
|
||||
try {
|
||||
const installed = installEvenHubPackageFile(path);
|
||||
ctx.appendLog(`evenhub: installed ${installed.packageId} ${installed.version}`);
|
||||
closeRunningPackage(installed.packageId);
|
||||
await ctx.launchApp(installedEvenHubAppId(installed.packageId));
|
||||
} catch (error) {
|
||||
ctx.appendLog(`evenhub install failed: ${error}`);
|
||||
}
|
||||
},
|
||||
openFontWindow: (title, path) => openFontDocumentWindow(ctx, title, path),
|
||||
}),
|
||||
),
|
||||
|
||||
@@ -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("|");
|
||||
}
|
||||
@@ -34,6 +34,12 @@ import { appViewportRect, type WindowHeightMode } from "../ui/shell/geometry";
|
||||
import { type LayerActions } from "../ui/layers";
|
||||
import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||
import {
|
||||
getInstalledEvenHubAppById,
|
||||
installedEvenHubPackageId,
|
||||
uninstallEvenHubPackage,
|
||||
} from "../apps/evenhub/installed-apps";
|
||||
import { closeRunningPackage, launchInstalledPackage } from "../apps/evenhub/manager";
|
||||
|
||||
type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting";
|
||||
|
||||
@@ -1416,6 +1422,7 @@ class DashboardController {
|
||||
apps: ALL_APPS,
|
||||
actions: this.sharedActions,
|
||||
launchApp: (appId, params) => this.launchApp(appId, params),
|
||||
uninstallApp: (appId) => this.uninstallApp(appId),
|
||||
launchInProcessApp: (windowId, surfaceId, create) => this.launchInProcessApp(windowId, surfaceId, create),
|
||||
ensureWorkerHost: (createWorker) => this.ensureWorkerHost(app.appId, createWorker),
|
||||
submitWindowFrame: (surfaceId, image, paintMs, frameId) =>
|
||||
@@ -1456,7 +1463,7 @@ class DashboardController {
|
||||
this.suppressOpenAppsPersist = true;
|
||||
try {
|
||||
for (const appId of saved.open) {
|
||||
if (!known.has(appId)) continue;
|
||||
if (!known.has(appId) && !getInstalledEvenHubAppById(appId)) continue;
|
||||
try {
|
||||
await this.launchApp(appId);
|
||||
} catch (error) {
|
||||
@@ -1482,11 +1489,29 @@ class DashboardController {
|
||||
*/
|
||||
private async launchApp(appId: string, params?: AppLaunchParams): Promise<void> {
|
||||
const app = ALL_APPS.find((entry) => entry.appId === appId);
|
||||
if (!app) {
|
||||
this.appendLog(`unknown app: ${appId}`);
|
||||
if (app) {
|
||||
await app.launch(this.buildAppContext(app), params);
|
||||
return;
|
||||
}
|
||||
await app.launch(this.buildAppContext(app), params);
|
||||
const installed = getInstalledEvenHubAppById(appId);
|
||||
if (installed) {
|
||||
const host = ALL_APPS.find((entry) => entry.appId === "evenhub")!;
|
||||
await launchInstalledPackage(this.buildAppContext({ ...host, appId }), installed);
|
||||
return;
|
||||
}
|
||||
this.appendLog(`unknown app: ${appId}`);
|
||||
}
|
||||
|
||||
private async uninstallApp(appId: string): Promise<void> {
|
||||
const packageId = installedEvenHubPackageId(appId);
|
||||
if (!packageId) {
|
||||
this.appendLog(`app is not uninstallable: ${appId}`);
|
||||
return;
|
||||
}
|
||||
closeRunningPackage(packageId);
|
||||
if (uninstallEvenHubPackage(packageId)) {
|
||||
this.appendLog(`evenhub: uninstalled ${packageId}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Create/refresh a window surface on the compositor, if connected. */
|
||||
|
||||
@@ -143,6 +143,11 @@ export function renderIcon(name: IconName, size: number): GrayImage | null {
|
||||
return renderSvgCached(name, ICON_SVGS[name], size);
|
||||
}
|
||||
|
||||
/** Render an app-provided SVG using the same small renderer and cache. */
|
||||
export function renderSvgIcon(cacheName: string, svg: string, size: number): GrayImage | null {
|
||||
return renderSvgCached(`custom:${cacheName}`, svg, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an icon with a glyph character substituted in — currently only the
|
||||
* terminal icon, whose "_" becomes the glyph (">3" instead of ">_"). Falls
|
||||
|
||||
@@ -125,6 +125,34 @@ export function windowIcon(icon: IconName | undefined, letter: string, glyph?: s
|
||||
return icon ? makeSvgWindowIcon(icon, glyph) : makeLetterWindowIcon(letter);
|
||||
}
|
||||
|
||||
/** Window icon backed by an arbitrary cached grayscale image renderer. */
|
||||
export function makeImageWindowIcon(
|
||||
render: (size: number) => GrayImage | null,
|
||||
fallback: ShellChromeWindow["drawIcon"],
|
||||
): ShellChromeWindow["drawIcon"] {
|
||||
return (image, x, y, size, inverted) => {
|
||||
const icon = render(size);
|
||||
if (!icon) {
|
||||
fallback(image, x, y, size, inverted);
|
||||
return;
|
||||
}
|
||||
const dx = x + Math.max(0, ((size - icon.width) / 2) | 0);
|
||||
const dy = y + Math.max(0, ((size - icon.height) / 2) | 0);
|
||||
if (!inverted) {
|
||||
image.bitBlt(icon, dx, dy, { transparentZero: true });
|
||||
return;
|
||||
}
|
||||
for (let row = 0; row < icon.height; row++) {
|
||||
for (let col = 0; col < icon.width; col++) {
|
||||
const coverage = icon.pixels[row * icon.width + col] ?? 0;
|
||||
if (coverage > 0) {
|
||||
image.setPixel(dx + col, dy + row, Math.max(SHELL_OPAQUE_BLACK, 255 - coverage));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Base layer of the shell surface: the window sidebar on the left and the
|
||||
* status top bar. Everything not explicitly painted stays 0 (transparent on
|
||||
|
||||
@@ -23,6 +23,8 @@ export type InProcessWindowOptions = {
|
||||
iconLetter: string;
|
||||
/** Lucide icon name for the sidebar indicator; falls back to iconLetter. */
|
||||
icon?: IconName;
|
||||
/** App-supplied sidebar icon renderer; takes precedence over icon/iconLetter. */
|
||||
drawIcon?: ShellWindow["drawIcon"];
|
||||
closeable: boolean;
|
||||
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
|
||||
heightMode?: WindowHeightMode;
|
||||
@@ -148,7 +150,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
options.onClosed?.();
|
||||
options.removeSurface?.();
|
||||
},
|
||||
drawIcon: windowIcon(options.icon, options.iconLetter),
|
||||
drawIcon: options.drawIcon ?? windowIcon(options.icon, options.iconLetter),
|
||||
handleInput: async (event, frameId) => {
|
||||
// The default long-press response: the window menu. Handled here (not
|
||||
// per-layer) so it works over submenus and app content alike.
|
||||
|
||||
Reference in new issue
Block a user