mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-23 03:31:56 +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 type {
|
||||
HandlerDetails,
|
||||
@@ -31,7 +32,7 @@ function downloadFile({
|
||||
failed(state: string): void;
|
||||
}) {
|
||||
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)) {
|
||||
const showDialogOptions: SaveDialogOptions = {
|
||||
defaultPath: path.join(downloadPath, item.getFilename()),
|
||||
@@ -86,7 +87,7 @@ function downloadFile({
|
||||
};
|
||||
|
||||
item.on("updated", updatedListener);
|
||||
item.once("done", async (_event: Event, state) => {
|
||||
item.once("done", async (_event, state) => {
|
||||
if (state === "completed") {
|
||||
await completed(item.getSavePath(), path.basename(item.getSavePath()));
|
||||
} else {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import type {Event} from "electron/common";
|
||||
import {clipboard} from "electron/common";
|
||||
import type {IpcMainEvent, WebContents} from "electron/main";
|
||||
import {BrowserWindow, app, dialog, powerMonitor, session} from "electron/main";
|
||||
@@ -170,7 +171,7 @@ function createMainWindow(): BrowserWindow {
|
||||
|
||||
ipcMain.on(
|
||||
"permission-callback",
|
||||
(event: Event, permissionCallbackId: number, grant: boolean) => {
|
||||
(event, permissionCallbackId: number, grant: boolean) => {
|
||||
permissionCallbacks.get(permissionCallbackId)?.(grant);
|
||||
permissionCallbacks.delete(permissionCallbackId);
|
||||
},
|
||||
@@ -181,7 +182,7 @@ function createMainWindow(): BrowserWindow {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
app.on("web-contents-created", (_event: Event, contents: WebContents) => {
|
||||
app.on("web-contents-created", (_event, contents: WebContents) => {
|
||||
contents.setWindowOpenHandler((details) => {
|
||||
handleExternalLink(contents, details, page);
|
||||
return {action: "deny"};
|
||||
@@ -361,24 +362,21 @@ ${error}`,
|
||||
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||
});
|
||||
|
||||
ipcMain.on("toggle-menubar", (_event: IpcMainEvent, showMenubar: boolean) => {
|
||||
ipcMain.on("toggle-menubar", (_event, showMenubar: boolean) => {
|
||||
mainWindow.autoHideMenuBar = showMenubar;
|
||||
mainWindow.setMenuBarVisibility(!showMenubar);
|
||||
send(page, "toggle-autohide-menubar", showMenubar, true);
|
||||
});
|
||||
|
||||
ipcMain.on("update-badge", (_event: IpcMainEvent, messageCount: number) => {
|
||||
ipcMain.on("update-badge", (_event, messageCount: number) => {
|
||||
badgeCount = messageCount;
|
||||
BadgeSettings.updateBadge(badgeCount, mainWindow);
|
||||
send(page, "tray", messageCount);
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
"update-taskbar-icon",
|
||||
(_event: IpcMainEvent, data: string, text: string) => {
|
||||
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
|
||||
},
|
||||
);
|
||||
ipcMain.on("update-taskbar-icon", (_event, data: string, text: string) => {
|
||||
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
"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);
|
||||
if (props.activeTabIndex !== undefined) {
|
||||
const activeTab = props.tabs[props.activeTabIndex];
|
||||
@@ -399,32 +397,29 @@ ${error}`,
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
"toggleAutoLauncher",
|
||||
async (_event: IpcMainEvent, AutoLaunchValue: boolean) => {
|
||||
await setAutoLaunch(AutoLaunchValue);
|
||||
},
|
||||
);
|
||||
ipcMain.on("toggleAutoLauncher", async (_event, AutoLaunchValue: boolean) => {
|
||||
await setAutoLaunch(AutoLaunchValue);
|
||||
});
|
||||
|
||||
ipcMain.on(
|
||||
"realm-name-changed",
|
||||
(_event: IpcMainEvent, serverURL: string, realmName: string) => {
|
||||
(_event, serverURL: string, realmName: string) => {
|
||||
send(page, "update-realm-name", serverURL, realmName);
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.on(
|
||||
"realm-icon-changed",
|
||||
(_event: IpcMainEvent, serverURL: string, iconURL: string) => {
|
||||
(_event, serverURL: string, iconURL: string) => {
|
||||
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);
|
||||
});
|
||||
|
||||
ipcMain.on("focus-this-webview", (event: IpcMainEvent) => {
|
||||
ipcMain.on("focus-this-webview", (event) => {
|
||||
send(page, "focus-webview-with-id", event.sender.id);
|
||||
mainWindow.show();
|
||||
});
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import type {Event} from "electron/common";
|
||||
import {clipboard} from "electron/common";
|
||||
import type {WebContents} from "electron/main";
|
||||
import type {
|
||||
|
@@ -65,7 +65,7 @@ export default class FunctionalTab extends Tab {
|
||||
this.$closeButton?.classList.remove("active");
|
||||
});
|
||||
|
||||
this.$closeButton?.addEventListener("click", (event: Event) => {
|
||||
this.$closeButton?.addEventListener("click", (event) => {
|
||||
this.props.onDestroy?.();
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
@@ -924,7 +924,7 @@ export class ServerManagerView {
|
||||
ipcRenderer.on(
|
||||
"permission-request",
|
||||
async (
|
||||
event: Event,
|
||||
event,
|
||||
{
|
||||
webContentsId,
|
||||
origin,
|
||||
@@ -981,7 +981,7 @@ export class ServerManagerView {
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -989,7 +989,7 @@ export class ServerManagerView {
|
||||
await this.openSettings("AddServer");
|
||||
});
|
||||
|
||||
ipcRenderer.on("reload-proxy", async (event: Event, showAlert: boolean) => {
|
||||
ipcRenderer.on("reload-proxy", async (event, showAlert: boolean) => {
|
||||
await this.loadProxy();
|
||||
if (showAlert) {
|
||||
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
|
||||
this.toggleSidebar(show);
|
||||
});
|
||||
|
||||
ipcRenderer.on("toggle-silent", async (event: Event, state: boolean) =>
|
||||
ipcRenderer.on("toggle-silent", async (event, state: boolean) =>
|
||||
Promise.all(
|
||||
this.tabs.map(async (tab) => {
|
||||
if (tab instanceof ServerTab)
|
||||
@@ -1016,7 +1016,7 @@ export class ServerManagerView {
|
||||
|
||||
ipcRenderer.on(
|
||||
"toggle-autohide-menubar",
|
||||
async (event: Event, autoHideMenubar: boolean, updateMenu: boolean) => {
|
||||
async (event, autoHideMenubar: boolean, updateMenu: boolean) => {
|
||||
if (updateMenu) {
|
||||
ipcRenderer.send("update-menu", {
|
||||
tabs: this.tabsForIpc,
|
||||
@@ -1028,11 +1028,7 @@ export class ServerManagerView {
|
||||
|
||||
ipcRenderer.on(
|
||||
"toggle-dnd",
|
||||
async (
|
||||
event: Event,
|
||||
state: boolean,
|
||||
newSettings: Partial<DndSettings>,
|
||||
) => {
|
||||
async (event, state: boolean, newSettings: Partial<DndSettings>) => {
|
||||
this.toggleDndButton(state);
|
||||
ipcRenderer.send(
|
||||
"forward-message",
|
||||
@@ -1044,7 +1040,7 @@ export class ServerManagerView {
|
||||
|
||||
ipcRenderer.on(
|
||||
"update-realm-name",
|
||||
(event: Event, serverURL: string, realmName: string) => {
|
||||
(event, serverURL: string, realmName: string) => {
|
||||
for (const [index, domain] of DomainUtil.getDomains().entries()) {
|
||||
if (domain.url === serverURL) {
|
||||
const tab = this.tabs[index];
|
||||
@@ -1063,7 +1059,7 @@ export class ServerManagerView {
|
||||
|
||||
ipcRenderer.on(
|
||||
"update-realm-icon",
|
||||
async (event: Event, serverURL: string, iconURL: string) => {
|
||||
async (event, serverURL: string, iconURL: string) => {
|
||||
await Promise.all(
|
||||
DomainUtil.getDomains().map(async (domain, index) => {
|
||||
if (domain.url === serverURL) {
|
||||
@@ -1088,61 +1084,56 @@ export class ServerManagerView {
|
||||
this.$fullscreenPopup.classList.remove("show");
|
||||
});
|
||||
|
||||
ipcRenderer.on(
|
||||
"focus-webview-with-id",
|
||||
async (event: Event, webviewId: number) =>
|
||||
Promise.all(
|
||||
this.tabs.map(async (tab) => {
|
||||
if (
|
||||
tab instanceof ServerTab &&
|
||||
(await tab.webview).webContentsId === webviewId
|
||||
) {
|
||||
const concurrentTab: HTMLButtonElement = document.querySelector(
|
||||
`div[data-tab-id="${CSS.escape(`${tab.props.tabIndex}`)}"]`,
|
||||
)!;
|
||||
concurrentTab.click();
|
||||
}
|
||||
}),
|
||||
),
|
||||
ipcRenderer.on("focus-webview-with-id", async (event, webviewId: number) =>
|
||||
Promise.all(
|
||||
this.tabs.map(async (tab) => {
|
||||
if (
|
||||
tab instanceof ServerTab &&
|
||||
(await tab.webview).webContentsId === webviewId
|
||||
) {
|
||||
const concurrentTab: HTMLButtonElement = document.querySelector(
|
||||
`div[data-tab-id="${CSS.escape(`${tab.props.tabIndex}`)}"]`,
|
||||
)!;
|
||||
concurrentTab.click();
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
ipcRenderer.on(
|
||||
"render-taskbar-icon",
|
||||
(event: Event, messageCount: number) => {
|
||||
// Create a canvas from unread message counts
|
||||
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.height = 128;
|
||||
canvas.width = 128;
|
||||
canvas.style.letterSpacing = "-5px";
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
ctx.fillStyle = "#f42020";
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
|
||||
ctx.fill();
|
||||
ctx.textAlign = "center";
|
||||
ctx.fillStyle = "white";
|
||||
if (messageCount > 99) {
|
||||
ctx.font = "65px Helvetica";
|
||||
ctx.fillText("99+", 64, 85);
|
||||
} else if (messageCount < 10) {
|
||||
ctx.font = "90px Helvetica";
|
||||
ctx.fillText(String(Math.min(99, messageCount)), 64, 96);
|
||||
} else {
|
||||
ctx.font = "85px Helvetica";
|
||||
ctx.fillText(String(Math.min(99, messageCount)), 64, 90);
|
||||
}
|
||||
|
||||
return canvas;
|
||||
ipcRenderer.on("render-taskbar-icon", (event, messageCount: number) => {
|
||||
// Create a canvas from unread message counts
|
||||
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.height = 128;
|
||||
canvas.width = 128;
|
||||
canvas.style.letterSpacing = "-5px";
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
ctx.fillStyle = "#f42020";
|
||||
ctx.beginPath();
|
||||
ctx.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
|
||||
ctx.fill();
|
||||
ctx.textAlign = "center";
|
||||
ctx.fillStyle = "white";
|
||||
if (messageCount > 99) {
|
||||
ctx.font = "65px Helvetica";
|
||||
ctx.fillText("99+", 64, 85);
|
||||
} else if (messageCount < 10) {
|
||||
ctx.font = "90px Helvetica";
|
||||
ctx.fillText(String(Math.min(99, messageCount)), 64, 96);
|
||||
} else {
|
||||
ctx.font = "85px Helvetica";
|
||||
ctx.fillText(String(Math.min(99, messageCount)), 64, 90);
|
||||
}
|
||||
|
||||
ipcRenderer.send(
|
||||
"update-taskbar-icon",
|
||||
createOverlayIcon(messageCount).toDataURL(),
|
||||
String(messageCount),
|
||||
);
|
||||
},
|
||||
);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
ipcRenderer.send(
|
||||
"update-taskbar-icon",
|
||||
createOverlayIcon(messageCount).toDataURL(),
|
||||
String(messageCount),
|
||||
);
|
||||
});
|
||||
|
||||
ipcRenderer.on("copy-zulip-url", async () => {
|
||||
clipboard.writeText(await this.getCurrentActiveServer());
|
||||
|
@@ -18,7 +18,7 @@ export function newNotification(
|
||||
): NotificationData {
|
||||
const notification = new Notification(title, {...options, silent: true});
|
||||
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 (!dispatch(type, ev)) {
|
||||
ev.preventDefault();
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import type {IpcRendererEvent} from "electron/renderer";
|
||||
import process from "node:process";
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
private readonly handleToggleMenubar = (_event: Event, state: boolean) => {
|
||||
private readonly handleToggleMenubar = (
|
||||
_event: IpcRendererEvent,
|
||||
state: boolean,
|
||||
) => {
|
||||
this.handleToggle("menubar-option", state);
|
||||
};
|
||||
|
||||
private readonly handleToggleDnd = (
|
||||
_event: Event,
|
||||
_event: IpcRendererEvent,
|
||||
_state: boolean,
|
||||
newSettings: Partial<DndSettings>,
|
||||
) => {
|
||||
|
@@ -176,7 +176,7 @@ const createTray = function (): void {
|
||||
};
|
||||
|
||||
export function initializeTray(serverManagerView: ServerManagerView) {
|
||||
ipcRenderer.on("destroytray", (_event: Event) => {
|
||||
ipcRenderer.on("destroytray", () => {
|
||||
if (!tray) {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user