Fix Windows taskbar shortcut icon
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+42
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user