forked from matrix/element-web
Add ability to hide tray icon on non-Mac (which has no tray icon)
This commit is contained in:
parent
6ada5e4397
commit
1498872214
|
@ -86,8 +86,16 @@ const store = new Store({ name: "electron-config" });
|
|||
|
||||
let mainWindow = null;
|
||||
global.appQuitting = false;
|
||||
global.minimizeToTray = store.get('minimizeToTray', true);
|
||||
global.showTrayIcon = store.get("showTrayIcon", true);
|
||||
global.minimizeToTray = global.showTrayIcon && store.get('minimizeToTray', true);
|
||||
|
||||
// It's important to call `path.join` so we don't end up with the packaged asar in the final path.
|
||||
const iconFile = `riot.${process.platform === 'win32' ? 'ico' : 'png'}`;
|
||||
const iconPath = path.join(__dirname, "..", "img", iconFile);
|
||||
const trayConfig = {
|
||||
icon_path: iconPath,
|
||||
brand: vectorConfig.brand || 'Riot',
|
||||
};
|
||||
|
||||
// handle uncaught errors otherwise it displays
|
||||
// stack traces in popup dialogs, which is terrible (which
|
||||
|
@ -166,6 +174,20 @@ ipcMain.on('ipcCall', async function(ev, payload) {
|
|||
launcher.disable();
|
||||
}
|
||||
break;
|
||||
case 'getTrayIconEnabled':
|
||||
ret = global.showTrayIcon;
|
||||
break;
|
||||
case 'setTrayIconEnabled':
|
||||
if (args[0]) {
|
||||
// Create trayIcon icon
|
||||
tray.create(trayConfig);
|
||||
} else {
|
||||
tray.destroy();
|
||||
}
|
||||
store.set('minimizeToTray', global.showTrayIcon = args[0]);
|
||||
// re-evaluate whether we should be minimizing to tray
|
||||
global.minimizeToTray = global.showTrayIcon && store.get('minimizeToTray', true);
|
||||
break;
|
||||
case 'getMinimizeToTrayEnabled':
|
||||
ret = global.minimizeToTray;
|
||||
break;
|
||||
|
@ -329,11 +351,6 @@ app.on('ready', () => {
|
|||
console.log('No update_base_url is defined: auto update is disabled');
|
||||
}
|
||||
|
||||
// It's important to call `path.join` so we don't end up with the packaged
|
||||
// asar in the final path.
|
||||
const iconFile = `riot.${process.platform === 'win32' ? 'ico' : 'png'}`;
|
||||
const iconPath = path.join(__dirname, "..", "..", "img", iconFile);
|
||||
|
||||
// Load the previous window state with fallback to defaults
|
||||
const mainWindowState = windowStateKeeper({
|
||||
defaultWidth: 1024,
|
||||
|
@ -371,10 +388,7 @@ app.on('ready', () => {
|
|||
mainWindow.hide();
|
||||
|
||||
// Create trayIcon icon
|
||||
tray.create({
|
||||
icon_path: iconPath,
|
||||
brand: vectorConfig.brand || 'Riot',
|
||||
});
|
||||
if (global.showTrayIcon) tray.create(trayConfig);
|
||||
|
||||
mainWindow.once('ready-to-show', () => {
|
||||
mainWindowState.manage(mainWindow);
|
||||
|
|
|
@ -26,6 +26,13 @@ exports.hasTray = function hasTray() {
|
|||
return (trayIcon !== null);
|
||||
};
|
||||
|
||||
exports.destroy = function() {
|
||||
if (trayIcon) {
|
||||
trayIcon.destroy();
|
||||
trayIcon = null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.create = function(config) {
|
||||
// no trays on darwin
|
||||
if (process.platform === 'darwin' || trayIcon) return;
|
||||
|
|
|
@ -211,6 +211,19 @@ export default class ElectronPlatform extends VectorBasePlatform {
|
|||
return this._ipcCall('setAutoHideMenuBarEnabled', enabled);
|
||||
}
|
||||
|
||||
supportsTrayIcon(): boolean {
|
||||
// Things other than Mac support tray icons
|
||||
return !navigator.platform.toUpperCase().includes('MAC');
|
||||
}
|
||||
|
||||
async getTrayIconEnabled(): boolean {
|
||||
return this._ipcCall('getTrayIconEnabled');
|
||||
}
|
||||
|
||||
async setTrayIconEnabled(enabled: boolean): void {
|
||||
return this._ipcCall('setTrayIconEnabled', enabled);
|
||||
}
|
||||
|
||||
supportsMinimizeToTray(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue