Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(launcher): show real macOS application icons

vastsa157092d87d0a
diff --git a/apps/desktop/electron/main/local-app-icon.ts b/apps/desktop/electron/main/local-app-icon.ts
new file mode 100644
index 000000000..a112438fe
--- /dev/null
+++ b/apps/desktop/electron/main/local-app-icon.ts
@@ -0,0 +1,66 @@
+/**
+ * Platform icon lookup for discovered applications.
+ *
+ * macOS: `app.getFileIcon(bundle, { size: "small" })` returns the generic
+ * bundle placeholder for every `.app`, so each application rendered the same
+ * blank square. The Quick Look thumbnail of a bundle is its real icon, so it
+ * is tried first and the native file icon is only the fallback. The `large`
+ * file-icon size is still never requested: it triggered a native startup
+ * SIGTRAP on macOS.
+ *
+ * Every native capability is injected so the selection stays unit-testable.
+ */
+
+/** Minimal image handle; `NativeImage` from Electron satisfies it. */
+export interface PlatformIconImage {
+ isEmpty(): boolean;
+ toDataURL(): string;
+}
+
+export interface PlatformIconProviders {
+ /** `nativeImage.createThumbnailFromPath` (macOS / Windows only). */
+ thumbnail(target: string, size: number): Promise<PlatformIconImage>;
+ /** `app.getFileIcon(target, { size: "small" })`. */
+ fileIcon(target: string): Promise<PlatformIconImage>;
+}
+
+/**
+ * Thumbnail edge in device pixels. The tile draws the icon at 48 CSS px, so
+ * 96 stays sharp on a 2x display; the encoded PNG stays well under the 32 KiB
+ * per-icon budget (measured: p90 ~15 KiB across the stock /Applications set).
+ */
+export const MAC_APP_ICON_THUMBNAIL_SIZE = 96;
+
+function usable(image: PlatformIconImage | null | undefined): PlatformIconImage | null {
+ if (!image) return null;
+ try {
+ return image.isEmpty() ? null : image;
+ } catch {
+ return null;
+ }
+}
+
+async function attempt(
+ load: () => Promise<PlatformIconImage>,
+): Promise<PlatformIconImage | null> {
+ try {
+ return usable(await load());
+ } catch {
+ return null;
+ }
+}
+
+/** Resolve the best available icon, or `null` when the platform has none. */
+export async function loadPlatformIcon(
+ platform: string,
+ target: string,
+ providers: PlatformIconProviders,
+): Promise<PlatformIconImage | null> {
+ if (platform === "darwin" && target.trim().toLowerCase().endsWith(".app")) {
+ const thumbnail = await attempt(() =>
+ providers.thumbnail(target, MAC_APP_ICON_THUMBNAIL_SIZE),
+ );
+ if (thumbnail) return thumbnail;
+ }
+ return attempt(() => providers.fileIcon(target));
+}
diff --git a/apps/desktop/electron/main/local-apps.ts b/apps/desktop/electron/main/local-apps.ts
index 40d95ff32..24891fdef 100644
--- a/apps/desktop/electron/main/local-apps.ts
+++ b/apps/desktop/electron/main/local-apps.ts
@@ -18,6 +18,7 @@ import {
discoverMacApps,
discoverWindowsApps,
} from "./local-apps-platform.ts";
+import { loadPlatformIcon } from "./local-app-icon.ts";
import { joinPath } from "./local-app-parse.ts";
export {
@@ -428,7 +429,7 @@ export async function createDefaultLocalAppDeps(): Promise<LocalAppDeps> {
import("node:fs"),
import("electron"),
]);
- const { app, shell } = electron;
+ const { app, nativeImage, shell } = electron;
const homeDir = app.getPath("home");
const platform = process.platform;
@@ -502,12 +503,11 @@ export async function createDefaultLocalAppDeps(): Promise<LocalAppDeps> {
}
},
async getFileIcon(target) {
- try {
- const icon = await app.getFileIcon(target, { size: "small" });
- return icon ?? null;
- } catch {
- return null;
- }
+ return loadPlatformIcon(platform, target, {
+ thumbnail: (path, size) =>
+ nativeImage.createThumbnailFromPath(path, { width: size, height: size }),
+ fileIcon: (path) => app.getFileIcon(path, { size: "small" }),
+ });
},
async openPath(target) {
return shell.openPath(target);
diff --git a/apps/desktop/src/components/launcher/LauncherTileButton.tsx b/apps/desktop/src/components/launcher/LauncherTileButton.tsx
index f7f33d0cf..63a81d399 100644
--- a/apps/desktop/src/components/launcher/LauncherTileButton.tsx
+++ b/apps/desktop/src/components/launcher/LauncherTileButton.tsx
@@ -71,7 +71,12 @@ export function LauncherTileButton({
title={title}
onClick={onOpen}
>
- <span className="plugin-launcher-icon" aria-hidden>
+ <span
+ className={`plugin-launcher-icon${
+ showIcon && tile.kind === "app" ? " plugin-launcher-icon-native" : ""
+ }`}
+ aria-hidden
+ >
{showIcon ? (
<img
src={tile.iconDataUrl}
diff --git a/apps/desktop/src/styles/plugin-launcher.css b/apps/desktop/src/styles/plugin-launcher.css
index d994b8d00..4c1156ae8 100644
--- a/apps/desktop/src/styles/plugin-launcher.css
+++ b/apps/desktop/src/styles/plugin-launcher.css
@@ -176,9 +176,10 @@ html[data-surface="plugin-launcher"] #root {
color: var(--ds-text-primary);
}
+/* Selection is a filled cell, not an outline: the grid stays calm while the
+ arrow keys move through it. Keyboard focus keeps its own accent ring. */
.plugin-launcher-tile.active .plugin-launcher-tile-open {
- border-color: var(--ds-border-strong);
- background: var(--ds-bg-hover);
+ background: var(--ds-bg-active);
color: var(--ds-text-primary);
}
@@ -213,6 +214,22 @@ html[data-surface="plugin-launcher"] #root {
pointer-events: none;
}
+/*
+ * An installed application's own icon already carries its shape (the macOS
+ * squircle, a Windows tile), so it fills the cell instead of sitting inside a
+ * second rounded square.
+ */
+.plugin-launcher-icon.plugin-launcher-icon-native {
+ overflow: visible;
+ border-radius: 0;
+ background: transparent;
+}
+
+.plugin-launcher-icon.plugin-launcher-icon-native img {
+ width: 48px;
+ height: 48px;
+}
+
.plugin-launcher-monogram {
font-size: var(--text-xl);
font-weight: var(--font-weight-semibold);
diff --git a/apps/desktop/test/local-apps.test.mjs b/apps/desktop/test/local-apps.test.mjs
index 3f0080fbd..9b5cc8183 100644
--- a/apps/desktop/test/local-apps.test.mjs
+++ b/apps/desktop/test/local-apps.test.mjs
@@ -10,6 +10,10 @@ import {
parseDesktopEntry,
windowsStartMenuDirs,
} from "../electron/main/local-apps.ts";
+import {
+ MAC_APP_ICON_THUMBNAIL_SIZE,
+ loadPlatformIcon,
+} from "../electron/main/local-app-icon.ts";
import { readMainModuleSync } from "./helpers/source-contracts.mjs";
import {
desktopExecutable,
@@ -386,11 +390,78 @@ test("icon failures and oversized icons never fail the scan", async () => {
test("the icon budget is 32 KiB and startup uses the stable small native icon", () => {
assert.equal(LOCAL_APP_MAX_ICON_BYTES, 32_768);
+ const source = readMainModuleSync("local-apps.ts");
// The large lookup triggered a native startup SIGTRAP on macOS.
- assert.match(
- readMainModuleSync("local-apps.ts"),
- /app\.getFileIcon\(target, \{ size: "small" \}\)/,
- );
+ assert.match(source, /app\.getFileIcon\(path, \{ size: "small" \}\)/);
+ assert.doesNotMatch(source, /size: "large"/);
+ assert.match(source, /loadPlatformIcon\(platform, target,/);
+ assert.match(source, /nativeImage\.createThumbnailFromPath\(path,/);
+});
+
+function fakeImage(dataUrl) {
+ return { isEmpty: () => dataUrl === "", toDataURL: () => dataUrl };
+}
+
+function fakeIconProviders({ thumbnail, fileIcon }) {
+ const calls = [];
+ return {
+ calls,
+ providers: {
+ async thumbnail(target, size) {
+ calls.push(["thumbnail", target, size]);
+ if (thumbnail instanceof Error) throw thumbnail;
+ return fakeImage(thumbnail);
+ },
+ async fileIcon(target) {
+ calls.push(["fileIcon", target]);
+ if (fileIcon instanceof Error) throw fileIcon;
+ return fakeImage(fileIcon);
+ },
+ },
+ };
+}
+
+test("macOS bundles use the Quick Look thumbnail instead of the generic file icon", async () => {
+ const { providers, calls } = fakeIconProviders({
+ thumbnail: "data:image/png;base64,REAL",
+ fileIcon: "data:image/png;base64,GENERIC",
+ });
+
+ const icon = await loadPlatformIcon("darwin", "/Applications/Chrome.app", providers);
+
+ assert.equal(icon.toDataURL(), "data:image/png;base64,REAL");
+ assert.deepEqual(calls, [
+ ["thumbnail", "/Applications/Chrome.app", MAC_APP_ICON_THUMBNAIL_SIZE],
+ ]);
+});
+
+test("macOS falls back to the native file icon when the thumbnail is empty or fails", async () => {
+ for (const thumbnail of ["", new Error("quick look unavailable")]) {
+ const { providers } = fakeIconProviders({
+ thumbnail,
+ fileIcon: "data:image/png;base64,GENERIC",
+ });
+ const icon = await loadPlatformIcon("darwin", "/Applications/Tool.app", providers);
+ assert.equal(icon.toDataURL(), "data:image/png;base64,GENERIC");
+ }
+
+ const { providers } = fakeIconProviders({ thumbnail: "", fileIcon: "" });
+ assert.equal(await loadPlatformIcon("darwin", "/Applications/Tool.app", providers), null);
+});
+
+test("other platforms keep the native file icon and never request a thumbnail", async () => {
+ for (const [platform, target] of [
+ ["win32", "C:\\Program Files\\Chrome\\chrome.exe"],
+ ["linux", "/usr/share/icons/chrome.png"],
+ ]) {
+ const { providers, calls } = fakeIconProviders({
+ thumbnail: "data:image/png;base64,REAL",
+ fileIcon: "data:image/png;base64,NATIVE",
+ });
+ const icon = await loadPlatformIcon(platform, target, providers);
+ assert.equal(icon.toDataURL(), "data:image/png;base64,NATIVE");
+ assert.deepEqual(calls, [["fileIcon", target]]);
+ }
});
test("a rescan reuses the icon it already fetched", async () => {