Skip to content

Commit d2f949d

Browse files
committed
Use Electron Event type.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent a8c283a commit d2f949d

File tree

8 files changed

+89
-94
lines changed

8 files changed

+89
-94
lines changed

app/main/handle-external-link.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {Event} from "electron/common";
12
import {shell} from "electron/common";
23
import type {
34
HandlerDetails,
@@ -31,7 +32,7 @@ function downloadFile({
3132
failed(state: string): void;
3233
}) {
3334
contents.downloadURL(url);
34-
contents.session.once("will-download", async (_event: Event, item) => {
35+
contents.session.once("will-download", async (_event, item) => {
3536
if (ConfigUtil.getConfigItem("promptDownload", false)) {
3637
const showDialogOptions: SaveDialogOptions = {
3738
defaultPath: path.join(downloadPath, item.getFilename()),
@@ -86,7 +87,7 @@ function downloadFile({
8687
};
8788

8889
item.on("updated", updatedListener);
89-
item.once("done", async (_event: Event, state) => {
90+
item.once("done", async (_event, state) => {
9091
if (state === "completed") {
9192
await completed(item.getSavePath(), path.basename(item.getSavePath()));
9293
} else {

app/main/index.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {Event} from "electron/common";
12
import {clipboard} from "electron/common";
23
import type {IpcMainEvent, WebContents} from "electron/main";
34
import {BrowserWindow, app, dialog, powerMonitor, session} from "electron/main";
@@ -170,7 +171,7 @@ function createMainWindow(): BrowserWindow {
170171

171172
ipcMain.on(
172173
"permission-callback",
173-
(event: Event, permissionCallbackId: number, grant: boolean) => {
174+
(event, permissionCallbackId: number, grant: boolean) => {
174175
permissionCallbacks.get(permissionCallbackId)?.(grant);
175176
permissionCallbacks.delete(permissionCallbackId);
176177
},
@@ -181,7 +182,7 @@ function createMainWindow(): BrowserWindow {
181182
mainWindow.show();
182183
});
183184

184-
app.on("web-contents-created", (_event: Event, contents: WebContents) => {
185+
app.on("web-contents-created", (_event, contents: WebContents) => {
185186
contents.setWindowOpenHandler((details) => {
186187
handleExternalLink(contents, details, page);
187188
return {action: "deny"};
@@ -361,24 +362,21 @@ ${error}`,
361362
BadgeSettings.updateBadge(badgeCount, mainWindow);
362363
});
363364

364-
ipcMain.on("toggle-menubar", (_event: IpcMainEvent, showMenubar: boolean) => {
365+
ipcMain.on("toggle-menubar", (_event, showMenubar: boolean) => {
365366
mainWindow.autoHideMenuBar = showMenubar;
366367
mainWindow.setMenuBarVisibility(!showMenubar);
367368
send(page, "toggle-autohide-menubar", showMenubar, true);
368369
});
369370

370-
ipcMain.on("update-badge", (_event: IpcMainEvent, messageCount: number) => {
371+
ipcMain.on("update-badge", (_event, messageCount: number) => {
371372
badgeCount = messageCount;
372373
BadgeSettings.updateBadge(badgeCount, mainWindow);
373374
send(page, "tray", messageCount);
374375
});
375376

376-
ipcMain.on(
377-
"update-taskbar-icon",
378-
(_event: IpcMainEvent, data: string, text: string) => {
379-
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
380-
},
381-
);
377+
ipcMain.on("update-taskbar-icon", (_event, data: string, text: string) => {
378+
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
379+
});
382380

383381
ipcMain.on(
384382
"forward-message",
@@ -391,40 +389,37 @@ ${error}`,
391389
},
392390
);
393391

394-
ipcMain.on("update-menu", (_event: IpcMainEvent, props: MenuProps) => {
392+
ipcMain.on("update-menu", (_event, props: MenuProps) => {
395393
AppMenu.setMenu(props);
396394
if (props.activeTabIndex !== undefined) {
397395
const activeTab = props.tabs[props.activeTabIndex];
398396
mainWindow.setTitle(`Zulip - ${activeTab.name}`);
399397
}
400398
});
401399

402-
ipcMain.on(
403-
"toggleAutoLauncher",
404-
async (_event: IpcMainEvent, AutoLaunchValue: boolean) => {
405-
await setAutoLaunch(AutoLaunchValue);
406-
},
407-
);
400+
ipcMain.on("toggleAutoLauncher", async (_event, AutoLaunchValue: boolean) => {
401+
await setAutoLaunch(AutoLaunchValue);
402+
});
408403

409404
ipcMain.on(
410405
"realm-name-changed",
411-
(_event: IpcMainEvent, serverURL: string, realmName: string) => {
406+
(_event, serverURL: string, realmName: string) => {
412407
send(page, "update-realm-name", serverURL, realmName);
413408
},
414409
);
415410

416411
ipcMain.on(
417412
"realm-icon-changed",
418-
(_event: IpcMainEvent, serverURL: string, iconURL: string) => {
413+
(_event, serverURL: string, iconURL: string) => {
419414
send(page, "update-realm-icon", serverURL, iconURL);
420415
},
421416
);
422417

423-
ipcMain.on("save-last-tab", (_event: IpcMainEvent, index: number) => {
418+
ipcMain.on("save-last-tab", (_event, index: number) => {
424419
ConfigUtil.setConfigItem("lastActiveTab", index);
425420
});
426421

427-
ipcMain.on("focus-this-webview", (event: IpcMainEvent) => {
422+
ipcMain.on("focus-this-webview", (event) => {
428423
send(page, "focus-webview-with-id", event.sender.id);
429424
mainWindow.show();
430425
});

app/renderer/js/components/context-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {Event} from "electron/common";
12
import {clipboard} from "electron/common";
23
import type {WebContents} from "electron/main";
34
import type {

app/renderer/js/components/functional-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class FunctionalTab extends Tab {
6565
this.$closeButton?.classList.remove("active");
6666
});
6767

68-
this.$closeButton?.addEventListener("click", (event: Event) => {
68+
this.$closeButton?.addEventListener("click", (event) => {
6969
this.props.onDestroy?.();
7070
event.stopPropagation();
7171
});

app/renderer/js/main.ts

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ export class ServerManagerView {
924924
ipcRenderer.on(
925925
"permission-request",
926926
async (
927-
event: Event,
927+
event,
928928
{
929929
webContentsId,
930930
origin,
@@ -981,15 +981,15 @@ export class ServerManagerView {
981981
ipcRenderer.send("reload-full-app");
982982
});
983983

984-
ipcRenderer.on("switch-server-tab", async (event: Event, index: number) => {
984+
ipcRenderer.on("switch-server-tab", async (event, index: number) => {
985985
await this.activateLastTab(index);
986986
});
987987

988988
ipcRenderer.on("open-org-tab", async () => {
989989
await this.openSettings("AddServer");
990990
});
991991

992-
ipcRenderer.on("reload-proxy", async (event: Event, showAlert: boolean) => {
992+
ipcRenderer.on("reload-proxy", async (event, showAlert: boolean) => {
993993
await this.loadProxy();
994994
if (showAlert) {
995995
await dialog.showMessageBox({
@@ -1000,12 +1000,12 @@ export class ServerManagerView {
10001000
}
10011001
});
10021002

1003-
ipcRenderer.on("toggle-sidebar", async (event: Event, show: boolean) => {
1003+
ipcRenderer.on("toggle-sidebar", async (event, show: boolean) => {
10041004
// Toggle the left sidebar
10051005
this.toggleSidebar(show);
10061006
});
10071007

1008-
ipcRenderer.on("toggle-silent", async (event: Event, state: boolean) =>
1008+
ipcRenderer.on("toggle-silent", async (event, state: boolean) =>
10091009
Promise.all(
10101010
this.tabs.map(async (tab) => {
10111011
if (tab instanceof ServerTab)
@@ -1016,7 +1016,7 @@ export class ServerManagerView {
10161016

10171017
ipcRenderer.on(
10181018
"toggle-autohide-menubar",
1019-
async (event: Event, autoHideMenubar: boolean, updateMenu: boolean) => {
1019+
async (event, autoHideMenubar: boolean, updateMenu: boolean) => {
10201020
if (updateMenu) {
10211021
ipcRenderer.send("update-menu", {
10221022
tabs: this.tabsForIpc,
@@ -1028,11 +1028,7 @@ export class ServerManagerView {
10281028

10291029
ipcRenderer.on(
10301030
"toggle-dnd",
1031-
async (
1032-
event: Event,
1033-
state: boolean,
1034-
newSettings: Partial<DndSettings>,
1035-
) => {
1031+
async (event, state: boolean, newSettings: Partial<DndSettings>) => {
10361032
this.toggleDndButton(state);
10371033
ipcRenderer.send(
10381034
"forward-message",
@@ -1044,7 +1040,7 @@ export class ServerManagerView {
10441040

10451041
ipcRenderer.on(
10461042
"update-realm-name",
1047-
(event: Event, serverURL: string, realmName: string) => {
1043+
(event, serverURL: string, realmName: string) => {
10481044
for (const [index, domain] of DomainUtil.getDomains().entries()) {
10491045
if (domain.url === serverURL) {
10501046
const tab = this.tabs[index];
@@ -1063,7 +1059,7 @@ export class ServerManagerView {
10631059

10641060
ipcRenderer.on(
10651061
"update-realm-icon",
1066-
async (event: Event, serverURL: string, iconURL: string) => {
1062+
async (event, serverURL: string, iconURL: string) => {
10671063
await Promise.all(
10681064
DomainUtil.getDomains().map(async (domain, index) => {
10691065
if (domain.url === serverURL) {
@@ -1088,61 +1084,56 @@ export class ServerManagerView {
10881084
this.$fullscreenPopup.classList.remove("show");
10891085
});
10901086

1091-
ipcRenderer.on(
1092-
"focus-webview-with-id",
1093-
async (event: Event, webviewId: number) =>
1094-
Promise.all(
1095-
this.tabs.map(async (tab) => {
1096-
if (
1097-
tab instanceof ServerTab &&
1098-
(await tab.webview).webContentsId === webviewId
1099-
) {
1100-
const concurrentTab: HTMLButtonElement = document.querySelector(
1101-
`div[data-tab-id="${CSS.escape(`${tab.props.tabIndex}`)}"]`,
1102-
)!;
1103-
concurrentTab.click();
1104-
}
1105-
}),
1106-
),
1107-
);
1108-
1109-
ipcRenderer.on(
1110-
"render-taskbar-icon",
1111-
(event: Event, messageCount: number) => {
1112-
// Create a canvas from unread message counts
1113-
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
1114-
const canvas = document.createElement("canvas");
1115-
canvas.height = 128;
1116-
canvas.width = 128;
1117-
canvas.style.letterSpacing = "-5px";
1118-
const ctx = canvas.getContext("2d")!;
1119-
ctx.fillStyle = "#f42020";
1120-
ctx.beginPath();
1121-
ctx.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
1122-
ctx.fill();
1123-
ctx.textAlign = "center";
1124-
ctx.fillStyle = "white";
1125-
if (messageCount > 99) {
1126-
ctx.font = "65px Helvetica";
1127-
ctx.fillText("99+", 64, 85);
1128-
} else if (messageCount < 10) {
1129-
ctx.font = "90px Helvetica";
1130-
ctx.fillText(String(Math.min(99, messageCount)), 64, 96);
1131-
} else {
1132-
ctx.font = "85px Helvetica";
1133-
ctx.fillText(String(Math.min(99, messageCount)), 64, 90);
1087+
ipcRenderer.on("focus-webview-with-id", async (event, webviewId: number) =>
1088+
Promise.all(
1089+
this.tabs.map(async (tab) => {
1090+
if (
1091+
tab instanceof ServerTab &&
1092+
(await tab.webview).webContentsId === webviewId
1093+
) {
1094+
const concurrentTab: HTMLButtonElement = document.querySelector(
1095+
`div[data-tab-id="${CSS.escape(`${tab.props.tabIndex}`)}"]`,
1096+
)!;
1097+
concurrentTab.click();
11341098
}
1099+
}),
1100+
),
1101+
);
11351102

1136-
return canvas;
1103+
ipcRenderer.on("render-taskbar-icon", (event, messageCount: number) => {
1104+
// Create a canvas from unread message counts
1105+
function createOverlayIcon(messageCount: number): HTMLCanvasElement {
1106+
const canvas = document.createElement("canvas");
1107+
canvas.height = 128;
1108+
canvas.width = 128;
1109+
canvas.style.letterSpacing = "-5px";
1110+
const ctx = canvas.getContext("2d")!;
1111+
ctx.fillStyle = "#f42020";
1112+
ctx.beginPath();
1113+
ctx.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
1114+
ctx.fill();
1115+
ctx.textAlign = "center";
1116+
ctx.fillStyle = "white";
1117+
if (messageCount > 99) {
1118+
ctx.font = "65px Helvetica";
1119+
ctx.fillText("99+", 64, 85);
1120+
} else if (messageCount < 10) {
1121+
ctx.font = "90px Helvetica";
1122+
ctx.fillText(String(Math.min(99, messageCount)), 64, 96);
1123+
} else {
1124+
ctx.font = "85px Helvetica";
1125+
ctx.fillText(String(Math.min(99, messageCount)), 64, 90);
11371126
}
11381127

1139-
ipcRenderer.send(
1140-
"update-taskbar-icon",
1141-
createOverlayIcon(messageCount).toDataURL(),
1142-
String(messageCount),
1143-
);
1144-
},
1145-
);
1128+
return canvas;
1129+
}
1130+
1131+
ipcRenderer.send(
1132+
"update-taskbar-icon",
1133+
createOverlayIcon(messageCount).toDataURL(),
1134+
String(messageCount),
1135+
);
1136+
});
11461137

11471138
ipcRenderer.on("copy-zulip-url", async () => {
11481139
clipboard.writeText(await this.getCurrentActiveServer());

app/renderer/js/notification/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function newNotification(
1818
): NotificationData {
1919
const notification = new Notification(title, {...options, silent: true});
2020
for (const type of ["click", "close", "error", "show"]) {
21-
notification.addEventListener(type, (ev: Event) => {
21+
notification.addEventListener(type, (ev) => {
2222
if (type === "click") ipcRenderer.send("focus-this-webview");
2323
if (!dispatch(type, ev)) {
2424
ev.preventDefault();

app/renderer/js/pages/preference/preference.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {IpcRendererEvent} from "electron/renderer";
12
import process from "node:process";
23

34
import type {DndSettings} from "../../../../common/dnd-util.js";
@@ -115,16 +116,22 @@ export class PreferenceView {
115116
}
116117
}
117118

118-
private readonly handleToggleSidebar = (_event: Event, state: boolean) => {
119+
private readonly handleToggleSidebar = (
120+
_event: IpcRendererEvent,
121+
state: boolean,
122+
) => {
119123
this.handleToggle("sidebar-option", state);
120124
};
121125

122-
private readonly handleToggleMenubar = (_event: Event, state: boolean) => {
126+
private readonly handleToggleMenubar = (
127+
_event: IpcRendererEvent,
128+
state: boolean,
129+
) => {
123130
this.handleToggle("menubar-option", state);
124131
};
125132

126133
private readonly handleToggleDnd = (
127-
_event: Event,
134+
_event: IpcRendererEvent,
128135
_state: boolean,
129136
newSettings: Partial<DndSettings>,
130137
) => {

app/renderer/js/tray.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const createTray = function (): void {
176176
};
177177

178178
export function initializeTray(serverManagerView: ServerManagerView) {
179-
ipcRenderer.on("destroytray", (_event: Event) => {
179+
ipcRenderer.on("destroytray", () => {
180180
if (!tray) {
181181
return;
182182
}
@@ -189,7 +189,7 @@ export function initializeTray(serverManagerView: ServerManagerView) {
189189
}
190190
});
191191

192-
ipcRenderer.on("tray", (_event: Event, arg: number): void => {
192+
ipcRenderer.on("tray", (_event, arg: number): void => {
193193
if (!tray) {
194194
return;
195195
}

0 commit comments

Comments
 (0)