Add Windows notification area icon
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+33
-2
@@ -1,4 +1,4 @@
|
||||
const { app, BrowserWindow, shell, ipcMain, safeStorage, dialog, Notification, powerMonitor } = require('electron');
|
||||
const { app, BrowserWindow, shell, ipcMain, safeStorage, dialog, Notification, powerMonitor, Menu, Tray, nativeImage } = require('electron');
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs/promises');
|
||||
const { ImapFlow } = require('imapflow');
|
||||
@@ -27,6 +27,8 @@ const backgroundSyncFailures = new Map();
|
||||
const flagSnapshots = new Map();
|
||||
const idleWatchers = new Map();
|
||||
const lastBackgroundSyncAt = new Map();
|
||||
let windowsAppIcon = null;
|
||||
let tray = null;
|
||||
|
||||
function updateAccountStore(update) {
|
||||
const operation = accountStoreQueue.then(async () => {
|
||||
@@ -1893,7 +1895,7 @@ function createWindow() {
|
||||
backgroundColor: '#f4f5f1',
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
icon: path.join(__dirname, '..', process.platform === 'win32' ? 'icon.ico' : 'icon.svg'),
|
||||
icon: windowsAppIcon || path.join(__dirname, '..', 'icon.svg'),
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
contextIsolation: true,
|
||||
@@ -1911,10 +1913,39 @@ function createWindow() {
|
||||
window.webContents.on('will-navigate', (event, url) => {
|
||||
if (!url.startsWith('file:')) event.preventDefault();
|
||||
});
|
||||
return window;
|
||||
}
|
||||
|
||||
function showMainWindow() {
|
||||
let window = BrowserWindow.getAllWindows().find(item => !item.isDestroyed());
|
||||
if (!window) {
|
||||
window = createWindow();
|
||||
} else {
|
||||
if (window.isMinimized()) window.restore();
|
||||
window.show();
|
||||
window.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function createWindowsTray() {
|
||||
tray = new Tray(windowsAppIcon.resize({ width: 16, height: 16 }));
|
||||
tray.setToolTip('ep-mail');
|
||||
tray.setContextMenu(Menu.buildFromTemplate([
|
||||
{ label: 'Open ep-mail', click: showMainWindow },
|
||||
{ type: 'separator' },
|
||||
{ label: 'Quit ep-mail', click: () => app.quit() }
|
||||
]));
|
||||
tray.on('click', showMainWindow);
|
||||
tray.on('double-click', showMainWindow);
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
app.setAppUserModelId('studio.daybreak.mail');
|
||||
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.');
|
||||
createWindowsTray();
|
||||
}
|
||||
createWindow();
|
||||
const syncTimer = setInterval(() => {
|
||||
void runBackgroundSync(true).catch(error => console.error('Periodic mail sync failed:', error));
|
||||
|
||||
Reference in New Issue
Block a user