mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-31 20:13:43 +00:00
Use Electron Event type.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import type {Event} from "electron/common";
|
||||||
import {shell} from "electron/common";
|
import {shell} from "electron/common";
|
||||||
import type {
|
import type {
|
||||||
HandlerDetails,
|
HandlerDetails,
|
||||||
@@ -31,7 +32,7 @@ function downloadFile({
|
|||||||
failed(state: string): void;
|
failed(state: string): void;
|
||||||
}) {
|
}) {
|
||||||
contents.downloadURL(url);
|
contents.downloadURL(url);
|
||||||
contents.session.once("will-download", async (_event: Event, item) => {
|
contents.session.once("will-download", async (_event, item) => {
|
||||||
if (ConfigUtil.getConfigItem("promptDownload", false)) {
|
if (ConfigUtil.getConfigItem("promptDownload", false)) {
|
||||||
const showDialogOptions: SaveDialogOptions = {
|
const showDialogOptions: SaveDialogOptions = {
|
||||||
defaultPath: path.join(downloadPath, item.getFilename()),
|
defaultPath: path.join(downloadPath, item.getFilename()),
|
||||||
@@ -86,7 +87,7 @@ function downloadFile({
|
|||||||
};
|
};
|
||||||
|
|
||||||
item.on("updated", updatedListener);
|
item.on("updated", updatedListener);
|
||||||
item.once("done", async (_event: Event, state) => {
|
item.once("done", async (_event, state) => {
|
||||||
if (state === "completed") {
|
if (state === "completed") {
|
||||||
await completed(item.getSavePath(), path.basename(item.getSavePath()));
|
await completed(item.getSavePath(), path.basename(item.getSavePath()));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type {Event} from "electron/common";
|
||||||
import {clipboard} from "electron/common";
|
import {clipboard} from "electron/common";
|
||||||
import type {IpcMainEvent, WebContents} from "electron/main";
|
import type {IpcMainEvent, WebContents} from "electron/main";
|
||||||
import {BrowserWindow, app, dialog, powerMonitor, session} from "electron/main";
|
import {BrowserWindow, app, dialog, powerMonitor, session} from "electron/main";
|
||||||
@@ -170,7 +171,7 @@ function createMainWindow(): BrowserWindow {
|
|||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on(
|
||||||
"permission-callback",
|
"permission-callback",
|
||||||
(event: Event, permissionCallbackId: number, grant: boolean) => {
|
(event, permissionCallbackId: number, grant: boolean) => {
|
||||||
permissionCallbacks.get(permissionCallbackId)?.(grant);
|
permissionCallbacks.get(permissionCallbackId)?.(grant);
|
||||||
permissionCallbacks.delete(permissionCallbackId);
|
permissionCallbacks.delete(permissionCallbackId);
|
||||||
},
|
},
|
||||||
@@ -181,7 +182,7 @@ function createMainWindow(): BrowserWindow {
|
|||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("web-contents-created", (_event: Event, contents: WebContents) => {
|
app.on("web-contents-created", (_event, contents: WebContents) => {
|
||||||
contents.setWindowOpenHandler((details) => {
|
contents.setWindowOpenHandler((details) => {
|
||||||
handleExternalLink(contents, details, page);
|
handleExternalLink(contents, details, page);
|
||||||
return {action: "deny"};
|
return {action: "deny"};
|
||||||
@@ -361,24 +362,21 @@ ${error}`,
|
|||||||
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("toggle-menubar", (_event: IpcMainEvent, showMenubar: boolean) => {
|
ipcMain.on("toggle-menubar", (_event, showMenubar: boolean) => {
|
||||||
mainWindow.autoHideMenuBar = showMenubar;
|
mainWindow.autoHideMenuBar = showMenubar;
|
||||||
mainWindow.setMenuBarVisibility(!showMenubar);
|
mainWindow.setMenuBarVisibility(!showMenubar);
|
||||||
send(page, "toggle-autohide-menubar", showMenubar, true);
|
send(page, "toggle-autohide-menubar", showMenubar, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("update-badge", (_event: IpcMainEvent, messageCount: number) => {
|
ipcMain.on("update-badge", (_event, messageCount: number) => {
|
||||||
badgeCount = messageCount;
|
badgeCount = messageCount;
|
||||||
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||||
send(page, "tray", messageCount);
|
send(page, "tray", messageCount);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on("update-taskbar-icon", (_event, data: string, text: string) => {
|
||||||
"update-taskbar-icon",
|
|
||||||
(_event: IpcMainEvent, data: string, text: string) => {
|
|
||||||
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
|
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on(
|
||||||
"forward-message",
|
"forward-message",
|
||||||
@@ -391,7 +389,7 @@ ${error}`,
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.on("update-menu", (_event: IpcMainEvent, props: MenuProps) => {
|
ipcMain.on("update-menu", (_event, props: MenuProps) => {
|
||||||
AppMenu.setMenu(props);
|
AppMenu.setMenu(props);
|
||||||
if (props.activeTabIndex !== undefined) {
|
if (props.activeTabIndex !== undefined) {
|
||||||
const activeTab = props.tabs[props.activeTabIndex];
|
const activeTab = props.tabs[props.activeTabIndex];
|
||||||
@@ -399,32 +397,29 @@ ${error}`,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on("toggleAutoLauncher", async (_event, AutoLaunchValue: boolean) => {
|
||||||
"toggleAutoLauncher",
|
|
||||||
async (_event: IpcMainEvent, AutoLaunchValue: boolean) => {
|
|
||||||
await setAutoLaunch(AutoLaunchValue);
|
await setAutoLaunch(AutoLaunchValue);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on(
|
||||||
"realm-name-changed",
|
"realm-name-changed",
|
||||||
(_event: IpcMainEvent, serverURL: string, realmName: string) => {
|
(_event, serverURL: string, realmName: string) => {
|
||||||
send(page, "update-realm-name", serverURL, realmName);
|
send(page, "update-realm-name", serverURL, realmName);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.on(
|
ipcMain.on(
|
||||||
"realm-icon-changed",
|
"realm-icon-changed",
|
||||||
(_event: IpcMainEvent, serverURL: string, iconURL: string) => {
|
(_event, serverURL: string, iconURL: string) => {
|
||||||
send(page, "update-realm-icon", serverURL, iconURL);
|
send(page, "update-realm-icon", serverURL, iconURL);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.on("save-last-tab", (_event: IpcMainEvent, index: number) => {
|
ipcMain.on("save-last-tab", (_event, index: number) => {
|
||||||
ConfigUtil.setConfigItem("lastActiveTab", index);
|
ConfigUtil.setConfigItem("lastActiveTab", index);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("focus-this-webview", (event: IpcMainEvent) => {
|
ipcMain.on("focus-this-webview", (event) => {
|
||||||
send(page, "focus-webview-with-id", event.sender.id);
|
send(page, "focus-webview-with-id", event.sender.id);
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type {Event} from "electron/common";
|
||||||
import {clipboard} from "electron/common";
|
import {clipboard} from "electron/common";
|
||||||
import type {WebContents} from "electron/main";
|
import type {WebContents} from "electron/main";
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default class FunctionalTab extends Tab {
|
|||||||
this.$closeButton?.classList.remove("active");
|
this.$closeButton?.classList.remove("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$closeButton?.addEventListener("click", (event: Event) => {
|
this.$closeButton?.addEventListener("click", (event) => {
|
||||||
this.props.onDestroy?.();
|
this.props.onDestroy?.();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -924,7 +924,7 @@ export class ServerManagerView {
|
|||||||
ipcRenderer.on(
|
ipcRenderer.on(
|
||||||
"permission-request",
|
"permission-request",
|
||||||
async (
|
async (
|
||||||
event: Event,
|
event,
|
||||||
{
|
{
|
||||||
webContentsId,
|
webContentsId,
|
||||||
origin,
|
origin,
|
||||||
@@ -981,7 +981,7 @@ export class ServerManagerView {
|
|||||||
ipcRenderer.send("reload-full-app");
|
ipcRenderer.send("reload-full-app");
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("switch-server-tab", async (event: Event, index: number) => {
|
ipcRenderer.on("switch-server-tab", async (event, index: number) => {
|
||||||
await this.activateLastTab(index);
|
await this.activateLastTab(index);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -989,7 +989,7 @@ export class ServerManagerView {
|
|||||||
await this.openSettings("AddServer");
|
await this.openSettings("AddServer");
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("reload-proxy", async (event: Event, showAlert: boolean) => {
|
ipcRenderer.on("reload-proxy", async (event, showAlert: boolean) => {
|
||||||
await this.loadProxy();
|
await this.loadProxy();
|
||||||
if (showAlert) {
|
if (showAlert) {
|
||||||
await dialog.showMessageBox({
|
await dialog.showMessageBox({
|
||||||
@@ -1000,12 +1000,12 @@ export class ServerManagerView {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("toggle-sidebar", async (event: Event, show: boolean) => {
|
ipcRenderer.on("toggle-sidebar", async (event, show: boolean) => {
|
||||||
// Toggle the left sidebar
|
// Toggle the left sidebar
|
||||||
this.toggleSidebar(show);
|
this.toggleSidebar(show);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("toggle-silent", async (event: Event, state: boolean) =>
|
ipcRenderer.on("toggle-silent", async (event, state: boolean) =>
|
||||||
Promise.all(
|
Promise.all(
|
||||||
this.tabs.map(async (tab) => {
|
this.tabs.map(async (tab) => {
|
||||||
if (tab instanceof ServerTab)
|
if (tab instanceof ServerTab)
|
||||||
@@ -1016,7 +1016,7 @@ export class ServerManagerView {
|
|||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on(
|
||||||
"toggle-autohide-menubar",
|
"toggle-autohide-menubar",
|
||||||
async (event: Event, autoHideMenubar: boolean, updateMenu: boolean) => {
|
async (event, autoHideMenubar: boolean, updateMenu: boolean) => {
|
||||||
if (updateMenu) {
|
if (updateMenu) {
|
||||||
ipcRenderer.send("update-menu", {
|
ipcRenderer.send("update-menu", {
|
||||||
tabs: this.tabsForIpc,
|
tabs: this.tabsForIpc,
|
||||||
@@ -1028,11 +1028,7 @@ export class ServerManagerView {
|
|||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on(
|
||||||
"toggle-dnd",
|
"toggle-dnd",
|
||||||
async (
|
async (event, state: boolean, newSettings: Partial<DndSettings>) => {
|
||||||
event: Event,
|
|
||||||
state: boolean,
|
|
||||||
newSettings: Partial<DndSettings>,
|
|
||||||
) => {
|
|
||||||
this.toggleDndButton(state);
|
this.toggleDndButton(state);
|
||||||
ipcRenderer.send(
|
ipcRenderer.send(
|
||||||
"forward-message",
|
"forward-message",
|
||||||
@@ -1044,7 +1040,7 @@ export class ServerManagerView {
|
|||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on(
|
||||||
"update-realm-name",
|
"update-realm-name",
|
||||||
(event: Event, serverURL: string, realmName: string) => {
|
(event, serverURL: string, realmName: string) => {
|
||||||
for (const [index, domain] of DomainUtil.getDomains().entries()) {
|
for (const [index, domain] of DomainUtil.getDomains().entries()) {
|
||||||
if (domain.url === serverURL) {
|
if (domain.url === serverURL) {
|
||||||
const tab = this.tabs[index];
|
const tab = this.tabs[index];
|
||||||
@@ -1063,7 +1059,7 @@ export class ServerManagerView {
|
|||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on(
|
||||||
"update-realm-icon",
|
"update-realm-icon",
|
||||||
async (event: Event, serverURL: string, iconURL: string) => {
|
async (event, serverURL: string, iconURL: string) => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
DomainUtil.getDomains().map(async (domain, index) => {
|
DomainUtil.getDomains().map(async (domain, index) => {
|
||||||
if (domain.url === serverURL) {
|
if (domain.url === serverURL) {
|
||||||
@@ -1088,9 +1084,7 @@ export class ServerManagerView {
|
|||||||
this.$fullscreenPopup.classList.remove("show");
|
this.$fullscreenPopup.classList.remove("show");
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on("focus-webview-with-id", async (event, webviewId: number) =>
|
||||||
"focus-webview-with-id",
|
|
||||||
async (event: Event, webviewId: number) =>
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
this.tabs.map(async (tab) => {
|
this.tabs.map(async (tab) => {
|
||||||
if (
|
if (
|
||||||
@@ -1106,9 +1100,7 @@ export class ServerManagerView {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcRenderer.on(
|
ipcRenderer.on("render-taskbar-icon", (event, messageCount: number) => {
|
||||||
"render-taskbar-icon",
|
|
||||||
(event: Event, messageCount: number) => {
|
|
||||||
// Create a canvas from unread message counts
|
// Create a canvas from unread message counts
|
||||||
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
|
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
@@ -1141,8 +1133,7 @@ export class ServerManagerView {
|
|||||||
createOverlayIcon(messageCount).toDataURL(),
|
createOverlayIcon(messageCount).toDataURL(),
|
||||||
String(messageCount),
|
String(messageCount),
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
ipcRenderer.on("copy-zulip-url", async () => {
|
ipcRenderer.on("copy-zulip-url", async () => {
|
||||||
clipboard.writeText(await this.getCurrentActiveServer());
|
clipboard.writeText(await this.getCurrentActiveServer());
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function newNotification(
|
|||||||
): NotificationData {
|
): NotificationData {
|
||||||
const notification = new Notification(title, {...options, silent: true});
|
const notification = new Notification(title, {...options, silent: true});
|
||||||
for (const type of ["click", "close", "error", "show"]) {
|
for (const type of ["click", "close", "error", "show"]) {
|
||||||
notification.addEventListener(type, (ev: Event) => {
|
notification.addEventListener(type, (ev) => {
|
||||||
if (type === "click") ipcRenderer.send("focus-this-webview");
|
if (type === "click") ipcRenderer.send("focus-this-webview");
|
||||||
if (!dispatch(type, ev)) {
|
if (!dispatch(type, ev)) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type {IpcRendererEvent} from "electron/renderer";
|
||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
|
|
||||||
import type {DndSettings} from "../../../../common/dnd-util.js";
|
import type {DndSettings} from "../../../../common/dnd-util.js";
|
||||||
@@ -115,16 +116,22 @@ export class PreferenceView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly handleToggleSidebar = (_event: Event, state: boolean) => {
|
private readonly handleToggleSidebar = (
|
||||||
|
_event: IpcRendererEvent,
|
||||||
|
state: boolean,
|
||||||
|
) => {
|
||||||
this.handleToggle("sidebar-option", state);
|
this.handleToggle("sidebar-option", state);
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly handleToggleMenubar = (_event: Event, state: boolean) => {
|
private readonly handleToggleMenubar = (
|
||||||
|
_event: IpcRendererEvent,
|
||||||
|
state: boolean,
|
||||||
|
) => {
|
||||||
this.handleToggle("menubar-option", state);
|
this.handleToggle("menubar-option", state);
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly handleToggleDnd = (
|
private readonly handleToggleDnd = (
|
||||||
_event: Event,
|
_event: IpcRendererEvent,
|
||||||
_state: boolean,
|
_state: boolean,
|
||||||
newSettings: Partial<DndSettings>,
|
newSettings: Partial<DndSettings>,
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ const createTray = function (): void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function initializeTray(serverManagerView: ServerManagerView) {
|
export function initializeTray(serverManagerView: ServerManagerView) {
|
||||||
ipcRenderer.on("destroytray", (_event: Event) => {
|
ipcRenderer.on("destroytray", () => {
|
||||||
if (!tray) {
|
if (!tray) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ export function initializeTray(serverManagerView: ServerManagerView) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("tray", (_event: Event, arg: number): void => {
|
ipcRenderer.on("tray", (_event, arg: number): void => {
|
||||||
if (!tray) {
|
if (!tray) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user