diff --git a/desktop/README.md b/desktop/README.md index cf96f6c78..656ce9757 100644 --- a/desktop/README.md +++ b/desktop/README.md @@ -94,6 +94,11 @@ Changing the services themselves also means running their own tests — see ## Build +`npm run generate:icons` stages the application icons from `resources/app-icon/`. +The macOS menu bar uses `pair-tray-template.png`, a transparent monochrome version +of PAIR's symbol, rendered at standard and Retina resolutions. Keep its background +transparent so macOS can adapt the template to light and dark menu bars. + ```bash npm run build # renderer, main, preload, and CLI bundles ``` diff --git a/desktop/electron.vite.config.ts b/desktop/electron.vite.config.ts index b3905cf48..22ab5e62b 100644 --- a/desktop/electron.vite.config.ts +++ b/desktop/electron.vite.config.ts @@ -30,7 +30,7 @@ function copyIconsPlugin() { resolve(__dirname, 'out/resources/icons'), resolve(__dirname, 'resources/icons') ] - // Only the flat logo.* files are needed at runtime (tray.ts / window.ts). + // Only the flat icon files are needed at runtime (tray.ts / window.ts). // Skip subdirectories such as linux/, which is consumed by electron-builder // at package time, not by the running app — copyFileSync on a dir throws. const files = readdirSync(src, { withFileTypes: true }) diff --git a/desktop/resources/app-icon/pair-tray-template.png b/desktop/resources/app-icon/pair-tray-template.png new file mode 100644 index 000000000..6bc20be2c Binary files /dev/null and b/desktop/resources/app-icon/pair-tray-template.png differ diff --git a/desktop/scripts/build/generate-app-icons.ts b/desktop/scripts/build/generate-app-icons.ts index 4fe5bef79..3cb628053 100644 --- a/desktop/scripts/build/generate-app-icons.ts +++ b/desktop/scripts/build/generate-app-icons.ts @@ -13,6 +13,7 @@ * resources/icons/logo.png <- pair-1024.png (tray/window downscale) * resources/icons/logo.ico <- pair.ico (Windows builder) * resources/icons/logo.icns <- assembled from the sized PNGs (macOS builder) + * resources/icons/pairTrayTemplate.png <- transparent macOS menu bar symbol * resources/icons/linux/x.png <- freedesktop hicolor set (Linux builder) * src/ui/public/favicon.png <- pair-256.png (renderer favicon) * @@ -86,6 +87,9 @@ function assertSources(): void { } } if (!existsSync(resolve(srcDir, 'pair.ico'))) problems.push('pair.ico is missing') + if (!existsSync(resolve(srcDir, 'pair-tray-template.png'))) { + problems.push('pair-tray-template.png is missing') + } if (problems.length > 0) { throw new Error( 'Invalid source icons in resources/app-icon/:\n - ' + @@ -121,6 +125,10 @@ function copyStaticIcons(): void { copyFileSync(master, resolve(iconsDir, 'logo.png')) copyFileSync(ico, resolve(iconsDir, 'logo.ico')) + copyFileSync( + resolve(srcDir, 'pair-tray-template.png'), + resolve(iconsDir, 'pairTrayTemplate.png') + ) copyFileSync(srcPngPath(256), resolve(faviconDir, 'favicon.png')) } @@ -148,6 +156,7 @@ function main(): void { console.log( 'Generated app icons:\n' + ' resources/icons/logo.{png,ico,icns}\n' + + ' resources/icons/pairTrayTemplate.png\n' + ` resources/icons/linux/x.png (${linuxIconSizes.join(', ')})\n` + ' src/ui/public/favicon.png' ) diff --git a/desktop/src/electron/tray.ts b/desktop/src/electron/tray.ts index cb13275f6..341b6a9e9 100644 --- a/desktop/src/electron/tray.ts +++ b/desktop/src/electron/tray.ts @@ -37,13 +37,15 @@ class TrayManager { const iconsDir = join(__dirname, '../../resources/icons') if (currentPlatform() === 'darwin') { - let image = nativeImage.createFromPath(join(iconsDir, 'logo.png')) - image = image.resize({ width: 16, height: 16, quality: 'best' }) - try { - image.setTemplateImage(true) - } catch { - /* not supported in test env */ - } + const source = nativeImage.createFromPath( + join(__dirname, '../resources/icons/pairTrayTemplate.png') + ) + const image = source.resize({ width: 18, height: 18, quality: 'best' }) + image.addRepresentation({ + scaleFactor: 2, + buffer: source.resize({ width: 36, height: 36, quality: 'best' }).toPNG() + }) + image.setTemplateImage(true) return image }