tray: Move initialization to a function.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-10-14 20:46:00 -07:00
parent 12c773bc71
commit b263997bed
2 changed files with 58 additions and 57 deletions

View File

@@ -14,14 +14,12 @@ import type {NavItem, ServerConf, TabData} from "../../common/types";
import FunctionalTab from "./components/functional-tab";
import ServerTab from "./components/server-tab";
import WebView from "./components/webview";
import {initializeTray} from "./tray";
import {ipcRenderer} from "./typed-ipc-renderer";
import * as DomainUtil from "./utils/domain-util";
import * as LinkUtil from "./utils/link-util";
import ReconnectUtil from "./utils/reconnect-util";
// eslint-disable-next-line import/no-unassigned-import
import "./tray";
const {session, app, Menu, dialog} = remote;
type WebviewListener =
@@ -113,6 +111,7 @@ class ServerManagerView {
}
async init(): Promise<void> {
initializeTray();
await this.loadProxy();
this.initDefaultSettings();
this.initSidebar();

View File

@@ -168,7 +168,8 @@ const createTray = function (): void {
}
};
ipcRenderer.on("destroytray", (_event: Event) => {
export function initializeTray() {
ipcRenderer.on("destroytray", (_event: Event) => {
if (!tray) {
return;
}
@@ -179,9 +180,9 @@ ipcRenderer.on("destroytray", (_event: Event) => {
} else {
throw new Error("Tray icon not properly destroyed.");
}
});
});
ipcRenderer.on("tray", (_event: Event, arg: number): void => {
ipcRenderer.on("tray", (_event: Event, arg: number): void => {
if (!tray) {
return;
}
@@ -199,9 +200,9 @@ ipcRenderer.on("tray", (_event: Event, arg: number): void => {
tray.setToolTip(`${arg} unread messages`);
}
}
});
});
function toggleTray(): void {
function toggleTray(): void {
let state;
if (tray) {
state = false;
@@ -229,12 +230,13 @@ function toggleTray(): void {
if (webview !== null) {
ipcRenderer.sendTo(webview.getWebContentsId(), "toggle-tray", state);
}
}
}
ipcRenderer.on("toggletray", toggleTray);
ipcRenderer.on("toggletray", toggleTray);
if (ConfigUtil.getConfigItem("trayIcon", true)) {
if (ConfigUtil.getConfigItem("trayIcon", true)) {
createTray();
}
}
export {};