mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-02 13:03:22 +00:00
tray: Move initialization to a function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
Reference in New Issue
Block a user