WebView: Use send method.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-10-19 15:52:50 -07:00
parent 76a879e4fd
commit 0eb910b2e8
2 changed files with 36 additions and 33 deletions

View File

@@ -993,7 +993,7 @@ export class ServerManagerView {
} }
}); });
ipcRenderer.on("toggle-sidebar", (event: Event, show: boolean) => { ipcRenderer.on("toggle-sidebar", async (event: Event, show: boolean) => {
// Toggle the left sidebar // Toggle the left sidebar
this.toggleSidebar(show); this.toggleSidebar(show);
}); });
@@ -1009,7 +1009,7 @@ export class ServerManagerView {
ipcRenderer.on( ipcRenderer.on(
"toggle-autohide-menubar", "toggle-autohide-menubar",
(event: Event, autoHideMenubar: boolean, updateMenu: boolean) => { async (event: Event, autoHideMenubar: boolean, updateMenu: boolean) => {
if (updateMenu) { if (updateMenu) {
ipcRenderer.send("update-menu", { ipcRenderer.send("update-menu", {
tabs: this.tabsForIpc, tabs: this.tabsForIpc,
@@ -1021,7 +1021,11 @@ export class ServerManagerView {
ipcRenderer.on( ipcRenderer.on(
"toggle-dnd", "toggle-dnd",
(event: Event, state: boolean, newSettings: Partial<DNDSettings>) => { async (
event: Event,
state: boolean,
newSettings: Partial<DNDSettings>,
) => {
this.toggleDNDButton(state); this.toggleDNDButton(state);
ipcRenderer.send( ipcRenderer.send(
"forward-message", "forward-message",
@@ -1087,20 +1091,20 @@ export class ServerManagerView {
ipcRenderer.on( ipcRenderer.on(
"focus-webview-with-id", "focus-webview-with-id",
(event: Event, webviewId: number) => { async (event: Event, webviewId: number) =>
const webviews: NodeListOf<Electron.WebviewTag> = Promise.all(
document.querySelectorAll("webview"); this.tabs.map(async (tab) => {
for (const webview of webviews) { if (
const currentId = webview.getWebContentsId(); tab instanceof ServerTab &&
const tabId = webview.getAttribute("data-tab-id")!; (await tab.webview).webContentsId === webviewId
const concurrentTab: HTMLButtonElement = document.querySelector( ) {
`div[data-tab-id="${CSS.escape(tabId)}"]`, const concurrentTab: HTMLButtonElement = document.querySelector(
)!; `div[data-tab-id="${CSS.escape(`${tab.props.tabIndex}`)}"]`,
if (currentId === webviewId) { )!;
concurrentTab.click(); concurrentTab.click();
} }
} }),
}, ),
); );
ipcRenderer.on( ipcRenderer.on(
@@ -1149,21 +1153,21 @@ export class ServerManagerView {
await this.openSettings("AddServer"); await this.openSettings("AddServer");
}); });
ipcRenderer.on("set-active", () => { ipcRenderer.on("set-active", async () =>
const webviews: NodeListOf<Electron.WebviewTag> = Promise.all(
document.querySelectorAll("webview"); this.tabs.map(async (tab) => {
for (const webview of webviews) { if (tab instanceof ServerTab) (await tab.webview).send("set-active");
ipcRenderer.sendTo(webview.getWebContentsId(), "set-active"); }),
} ),
}); );
ipcRenderer.on("set-idle", () => { ipcRenderer.on("set-idle", async () =>
const webviews: NodeListOf<Electron.WebviewTag> = Promise.all(
document.querySelectorAll("webview"); this.tabs.map(async (tab) => {
for (const webview of webviews) { if (tab instanceof ServerTab) (await tab.webview).send("set-idle");
ipcRenderer.sendTo(webview.getWebContentsId(), "set-idle"); }),
} ),
}); );
ipcRenderer.on("open-network-settings", async () => { ipcRenderer.on("open-network-settings", async () => {
await this.openSettings("Network"); await this.openSettings("Network");
@@ -1175,5 +1179,3 @@ window.addEventListener("load", async () => {
const serverManagerView = new ServerManagerView(); const serverManagerView = new ServerManagerView();
await serverManagerView.init(); await serverManagerView.init();
}); });
export {};

View File

@@ -288,6 +288,7 @@
"disallowTypeAnnotations": false "disallowTypeAnnotations": false
} }
], ],
"@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-redeclare": "error", "@typescript-eslint/no-redeclare": "error",
"@typescript-eslint/no-unused-vars": [ "@typescript-eslint/no-unused-vars": [
"error", "error",