Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to hide tray icon on non-Mac (which has no tray icon) #11258

Merged
merged 4 commits into from
Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions electron_app/src/electron-main.js
Original file line number Diff line number Diff line change
@@ -86,8 +86,14 @@ const store = new Store({ name: "electron-config" });

let mainWindow = null;
global.appQuitting = false;
global.minimizeToTray = 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);
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
const trayConfig = {
icon_path: iconPath,
brand: vectorConfig.brand || 'Riot',
};

// handle uncaught errors otherwise it displays
// stack traces in popup dialogs, which is terrible (which
@@ -167,10 +173,16 @@ ipcMain.on('ipcCall', async function(ev, payload) {
}
break;
case 'getMinimizeToTrayEnabled':
ret = global.minimizeToTray;
ret = tray.hasTray();
break;
case 'setMinimizeToTrayEnabled':
store.set('minimizeToTray', global.minimizeToTray = args[0]);
if (args[0]) {
// Create trayIcon icon
tray.create(trayConfig);
} else {
tray.destroy();
}
store.set('minimizeToTray', args[0]);
break;
case 'getAutoHideMenuBarEnabled':
ret = global.mainWindow.isMenuBarAutoHide();
@@ -329,11 +341,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,
@@ -366,15 +373,8 @@ app.on('ready', () => {
mainWindow.loadURL('vector://vector/webapp/');
Menu.setApplicationMenu(vectorMenu);

// explicitly hide because setApplicationMenu on Linux otherwise shows...
// https://github.com/electron/electron/issues/9621
mainWindow.hide();

// Create trayIcon icon
tray.create({
icon_path: iconPath,
brand: vectorConfig.brand || 'Riot',
});
if (store.get('minimizeToTray', true)) tray.create(trayConfig);

mainWindow.once('ready-to-show', () => {
mainWindowState.manage(mainWindow);
@@ -391,7 +391,8 @@ app.on('ready', () => {
mainWindow = global.mainWindow = null;
});
mainWindow.on('close', (e) => {
if (global.minimizeToTray && !global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
// If we are not quitting and have a tray icon then minimize to tray
if (!global.appQuitting && tray.hasTray()) {
// On Mac, closing the window just hides it
// (this is generally how single-window Mac apps
// behave, eg. Mail.app)
7 changes: 7 additions & 0 deletions electron_app/src/tray.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion src/vector/platform/ElectronPlatform.js
Original file line number Diff line number Diff line change
@@ -212,7 +212,8 @@ export default class ElectronPlatform extends VectorBasePlatform {
}

supportsMinimizeToTray(): boolean {
return true;
// Things other than Mac support tray icons
return !navigator.platform.toUpperCase().includes('MAC');
}

async getMinimizeToTrayEnabled(): boolean {