From 115e29640e34d8ac67c283a2e3f8788616c79b27 Mon Sep 17 00:00:00 2001 From: Tero Date: Sat, 10 Oct 2026 22:57:54 +0300 Subject: [PATCH] Fix Windows taskbar shortcut icon Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ARCHITECTURE.md | 2 +- README.md | 2 + desktop/main.cjs | 43 ++++++++- package-lock.json | 4 +- package.json | 2 +- www/pgp-ui.js | 226 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 274 insertions(+), 5 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 50f0c36..b3b179e 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -8,7 +8,7 @@ This project has a layered architecture: a desktop Electron shell, a browser-ren - `desktop/main.cjs` is the privileged process. - It owns account storage, mail sync, IMAP/SMTP connectivity, DAV sync, and OpenPGP key handling. -- It can show native dialogs, notifications, and system prompts. On Windows, its notification-area tray icon uses the packaged multi-resolution application icon and provides Open and Quit actions. +- It can show native dialogs, notifications, and system prompts. On Windows, its notification-area tray icon uses the packaged multi-resolution application icon and provides Open and Quit actions. Packaged startup repairs an existing per-user Start Menu shortcut to target the launched app and use its icon, keeping taskbar pins associated with the matching AppUserModelID. - `desktop/preload.cjs` exposes a minimal API to the renderer through `window.daybreakMail` and `window.pgpPrepareSend`. ### Renderer UI diff --git a/README.md b/README.md index c039049..e6cbb76 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ The Electron app runs in its own window. On Windows, ep-mail also shows its icon The `.github/workflows/desktop-build.yml` workflow builds both Windows and Linux artifacts on their native GitHub-hosted runners when manually started from the Actions tab. Snoozed messages return to their original mailbox with a reminder; desktop reminders are checked while the app is running, and Android uses its periodic background worker. +On packaged Windows builds, startup repairs an existing per-user Start Menu shortcut to point to the launched installed or portable executable and use its icon and AppUserModelID. Windows may keep a cached icon for an existing taskbar pin; if so, unpin and pin ep-mail again after launching the updated build. + See the project architecture overview in [ARCHITECTURE.md](./ARCHITECTURE.md). ## Android app diff --git a/desktop/main.cjs b/desktop/main.cjs index ea53a55..2d13ee5 100644 --- a/desktop/main.cjs +++ b/desktop/main.cjs @@ -1,4 +1,5 @@ const { app, BrowserWindow, shell, ipcMain, safeStorage, dialog, Notification, powerMonitor, Menu, Tray, nativeImage } = require('electron'); +const fsSync = require('node:fs'); const path = require('node:path'); const fs = require('node:fs/promises'); const { ImapFlow } = require('imapflow'); @@ -18,6 +19,7 @@ const backgroundRetryIntervalMs = 2 * 60 * 1000; const backgroundSyncConcurrency = 2; const backgroundIdleConcurrency = 2; const snoozeCheckIntervalMs = 30 * 1000; +const windowsAppUserModelId = 'studio.daybreak.mail'; let accountStoreQueue = Promise.resolve(); let backgroundSyncInProgress = false; let backgroundSyncRequested = false; @@ -1939,11 +1941,50 @@ function createWindowsTray() { tray.on('double-click', showMainWindow); } +function repairWindowsStartMenuShortcut() { + if (!app.isPackaged) return; + + const shortcutPath = path.join( + app.getPath('appData'), + 'Microsoft', + 'Windows', + 'Start Menu', + 'Programs', + 'ep-mail.lnk' + ); + if (!fsSync.existsSync(shortcutPath)) return; + + try { + const shortcut = shell.readShortcutLink(shortcutPath); + const isEpMailShortcut = path.basename(shortcut.target).toLowerCase() === 'ep-mail.exe' + || shortcut.appUserModelId === windowsAppUserModelId; + if (!isEpMailShortcut) return; + if (shortcut.appUserModelId && shortcut.appUserModelId !== windowsAppUserModelId) return; + + const portableExecutable = process.env.PORTABLE_EXECUTABLE_FILE; + const executable = portableExecutable && fsSync.existsSync(portableExecutable) + ? portableExecutable + : process.execPath; + const updated = shell.writeShortcutLink(shortcutPath, 'update', { + ...shortcut, + target: executable, + cwd: path.dirname(executable), + icon: executable, + iconIndex: 0, + appUserModelId: windowsAppUserModelId + }); + if (!updated) throw new Error('Windows did not update the shortcut.'); + } catch (error) { + console.error('Could not repair the ep-mail Start Menu shortcut:', error); + } +} + app.whenReady().then(() => { - app.setAppUserModelId('studio.daybreak.mail'); + app.setAppUserModelId(windowsAppUserModelId); if (process.platform === 'win32') { windowsAppIcon = nativeImage.createFromPath(path.join(__dirname, '..', 'icon.ico')); if (windowsAppIcon.isEmpty()) throw new Error('Could not load the Windows application icon.'); + repairWindowsStartMenuShortcut(); createWindowsTray(); } createWindow(); diff --git a/package-lock.json b/package-lock.json index 1c77acd..6a62a97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ep-mail", - "version": "0.3.6", + "version": "0.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ep-mail", - "version": "0.3.6", + "version": "0.4.3", "dependencies": { "@capacitor/android": "^8.5.2", "@capacitor/core": "^8.5.2", diff --git a/package.json b/package.json index de002b1..d4854fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ep-mail", - "version": "0.3.6", + "version": "0.4.3", "private": true, "description": "Eternity Project mail client", "author": "Eternity Project", diff --git a/www/pgp-ui.js b/www/pgp-ui.js index 80aa35d..443d464 100644 --- a/www/pgp-ui.js +++ b/www/pgp-ui.js @@ -7,9 +7,27 @@ function openEncryptionKeys() { root.innerHTML = `