[MM-52625] Rework tray icon code into a class, make the behaviour of the tray icon consistent with the OS it's running on (#2708)

* Rework tray into a class, make click behaviour consistent

* Fix issue where app wouldn't switch to workspace where the app was visible

* Fixed an issue where the app would show the window with hideOnStart enabled

* Add comment about StatusIconLinuxDbus

* Fix tests
This commit is contained in:
Devin Binnie
2023-05-04 09:21:50 -04:00
committed by GitHub
parent 78dc529d32
commit c20088f6fa
11 changed files with 172 additions and 166 deletions

View File

@@ -25,6 +25,7 @@ import {
MAXIMIZE_CHANGE,
MAIN_WINDOW_CREATED,
MAIN_WINDOW_RESIZED,
MAIN_WINDOW_FOCUSED,
VIEW_FINISHED_RESIZING,
} from 'common/communication';
import Config from 'common/config';
@@ -99,11 +100,6 @@ export class MainWindow extends EventEmitter {
this.win.setAutoHideMenuBar(true);
this.win.setMenuBarVisibility(false);
const localURL = getLocalURLString('index.html');
this.win.loadURL(localURL).catch(
(reason) => {
log.error('failed to load', reason);
});
this.win.once('ready-to-show', () => {
if (!this.win) {
return;
@@ -123,7 +119,6 @@ export class MainWindow extends EventEmitter {
this.win.once('restore', () => {
this.win?.restore();
});
this.win.on('close', this.onClose);
this.win.on('closed', this.onClosed);
this.win.on('focus', this.onFocus);
@@ -143,7 +138,6 @@ export class MainWindow extends EventEmitter {
if (process.platform === 'linux') {
this.win.on('resize', this.onResize);
}
this.win.webContents.on('before-input-event', this.onBeforeInputEvent);
// Should not allow the main window to generate a window of its own
@@ -155,6 +149,12 @@ export class MainWindow extends EventEmitter {
const contextMenu = new ContextMenu({}, this.win);
contextMenu.reload();
const localURL = getLocalURLString('index.html');
this.win.loadURL(localURL).catch(
(reason) => {
log.error('failed to load', reason);
});
this.emit(MAIN_WINDOW_CREATED);
}
@@ -167,15 +167,11 @@ export class MainWindow extends EventEmitter {
}
show = () => {
if (this.win) {
if (this.win.isVisible()) {
this.win.focus();
} else {
this.win.show();
}
if (this.win && this.isReady) {
this.win.show();
this.win.focus();
} else {
this.init();
this.show();
}
}
@@ -202,8 +198,6 @@ export class MainWindow extends EventEmitter {
}
}
onBrowserWindow = this.win?.on;
sendToRenderer = (channel: string, ...args: unknown[]) => {
this.sendToRendererWithRetry(3, channel, ...args);
}
@@ -295,6 +289,7 @@ export class MainWindow extends EventEmitter {
}
this.emit(MAIN_WINDOW_RESIZED, this.getBounds());
this.emit(MAIN_WINDOW_FOCUSED);
}
private onBlur = () => {