improve linux tray icon support (#5425)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
+30
-18
@@ -764,30 +764,43 @@ const destroyTray = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const disableTray = () => {
|
||||||
|
const settings = loadSettings();
|
||||||
|
settings.showMenuBarIcon = false;
|
||||||
|
saveSettings(settings);
|
||||||
|
};
|
||||||
|
|
||||||
const createTray = () => {
|
const createTray = () => {
|
||||||
// If tray already exists, destroy it first
|
|
||||||
destroyTray();
|
destroyTray();
|
||||||
|
|
||||||
const isDev = !app.isPackaged;
|
const possiblePaths = [
|
||||||
let iconPath: string;
|
path.join(process.resourcesPath, 'images', 'iconTemplate.png'),
|
||||||
|
path.join(process.cwd(), 'src', 'images', 'iconTemplate.png'),
|
||||||
|
path.join(__dirname, '..', 'images', 'iconTemplate.png'),
|
||||||
|
path.join(__dirname, 'images', 'iconTemplate.png'),
|
||||||
|
path.join(process.cwd(), 'images', 'iconTemplate.png'),
|
||||||
|
];
|
||||||
|
|
||||||
if (isDev) {
|
const iconPath = possiblePaths.find((p) => fsSync.existsSync(p));
|
||||||
iconPath = path.join(process.cwd(), 'src', 'images', 'iconTemplate.png');
|
|
||||||
} else {
|
if (!iconPath) {
|
||||||
iconPath = path.join(process.resourcesPath, 'images', 'iconTemplate.png');
|
console.warn('[Main] Tray icon not found. App will continue without system tray.');
|
||||||
|
disableTray();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tray = new Tray(iconPath);
|
try {
|
||||||
|
tray = new Tray(iconPath);
|
||||||
|
setTrayRef(tray);
|
||||||
|
updateTrayMenu(getUpdateAvailable());
|
||||||
|
|
||||||
// Set tray reference for auto-updater
|
if (process.platform === 'win32') {
|
||||||
setTrayRef(tray);
|
tray.on('click', showWindow);
|
||||||
|
}
|
||||||
// Initially build menu based on update status
|
} catch (error) {
|
||||||
updateTrayMenu(getUpdateAvailable());
|
console.error('[Main] Tray creation failed. App will continue without system tray.', error);
|
||||||
|
disableTray();
|
||||||
// On Windows, clicking the tray icon should show the window
|
tray = null;
|
||||||
if (process.platform === 'win32') {
|
|
||||||
tray.on('click', showWindow);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -802,7 +815,6 @@ const showWindow = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the initial offset values
|
|
||||||
const initialOffsetX = 30;
|
const initialOffsetX = 30;
|
||||||
const initialOffsetY = 30;
|
const initialOffsetY = 30;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user