mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-03 21:43:18 +00:00 
			
		
		
		
	renderer: Use ipcRenderer.sendTo to communicate with other WebContents.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		@@ -335,6 +335,6 @@ export default class WebView {
 | 
			
		||||
 | 
			
		||||
  async send(channel: string, ...parameters: unknown[]): Promise<void> {
 | 
			
		||||
    await this.domReady;
 | 
			
		||||
    await this.$el!.send(channel, ...parameters);
 | 
			
		||||
    ipcRenderer.sendTo(this.$el!.getWebContentsId(), channel, ...parameters);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -783,10 +783,8 @@ class ServerManagerView {
 | 
			
		||||
 | 
			
		||||
  updateGeneralSettings(setting: string, value: unknown): void {
 | 
			
		||||
    if (this.getActiveWebview()) {
 | 
			
		||||
      const webContents = remote.webContents.fromId(
 | 
			
		||||
        this.getActiveWebview().getWebContentsId(),
 | 
			
		||||
      );
 | 
			
		||||
      webContents.send(setting, value);
 | 
			
		||||
      const webContentsId = this.getActiveWebview().getWebContentsId();
 | 
			
		||||
      ipcRenderer.sendTo(webContentsId, setting, value);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -1065,10 +1063,8 @@ class ServerManagerView {
 | 
			
		||||
          "toggle-silent",
 | 
			
		||||
          newSettings.silent,
 | 
			
		||||
        );
 | 
			
		||||
        const webContents = remote.webContents.fromId(
 | 
			
		||||
          this.getActiveWebview().getWebContentsId(),
 | 
			
		||||
        );
 | 
			
		||||
        webContents.send("toggle-dnd", state, newSettings);
 | 
			
		||||
        const webContentsId = this.getActiveWebview().getWebContentsId();
 | 
			
		||||
        ipcRenderer.sendTo(webContentsId, "toggle-dnd", state, newSettings);
 | 
			
		||||
      },
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
@@ -1197,22 +1193,22 @@ class ServerManagerView {
 | 
			
		||||
      await this.openSettings("AddServer");
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ipcRenderer.on("set-active", async () => {
 | 
			
		||||
    ipcRenderer.on("set-active", () => {
 | 
			
		||||
      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
			
		||||
        "webview",
 | 
			
		||||
      );
 | 
			
		||||
      await Promise.all(
 | 
			
		||||
        [...webviews].map(async (webview) => webview.send("set-active")),
 | 
			
		||||
      );
 | 
			
		||||
      for (const webview of webviews) {
 | 
			
		||||
        ipcRenderer.sendTo(webview.getWebContentsId(), "set-active");
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ipcRenderer.on("set-idle", async () => {
 | 
			
		||||
    ipcRenderer.on("set-idle", () => {
 | 
			
		||||
      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
			
		||||
        "webview",
 | 
			
		||||
      );
 | 
			
		||||
      await Promise.all(
 | 
			
		||||
        [...webviews].map(async (webview) => webview.send("set-idle")),
 | 
			
		||||
      );
 | 
			
		||||
      for (const webview of webviews) {
 | 
			
		||||
        ipcRenderer.sendTo(webview.getWebContentsId(), "set-idle");
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ipcRenderer.on("open-network-settings", async () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
import {remote} from "electron";
 | 
			
		||||
import {ipcRenderer, remote} from "electron";
 | 
			
		||||
 | 
			
		||||
// Do not change this
 | 
			
		||||
export const appId = "org.zulip.zulip-electron";
 | 
			
		||||
@@ -10,5 +10,9 @@ const webContentsId = webContents.id;
 | 
			
		||||
// This function will focus the server that sent
 | 
			
		||||
// the notification. Main function implemented in main.js
 | 
			
		||||
export function focusCurrentServer(): void {
 | 
			
		||||
  currentWindow.webContents.send("focus-webview-with-id", webContentsId);
 | 
			
		||||
  ipcRenderer.sendTo(
 | 
			
		||||
    currentWindow.webContents.id,
 | 
			
		||||
    "focus-webview-with-id",
 | 
			
		||||
    webContentsId,
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -352,7 +352,11 @@ export function initGeneralSection(props: GeneralSectionProps): void {
 | 
			
		||||
        const newValue = !ConfigUtil.getConfigItem("silent", true);
 | 
			
		||||
        ConfigUtil.setConfigItem("silent", newValue);
 | 
			
		||||
        updateSilentOption();
 | 
			
		||||
        currentBrowserWindow.webContents.send("toggle-silent", newValue);
 | 
			
		||||
        ipcRenderer.sendTo(
 | 
			
		||||
          currentBrowserWindow.webContents.id,
 | 
			
		||||
          "toggle-silent",
 | 
			
		||||
          newValue,
 | 
			
		||||
        );
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -125,7 +125,7 @@ function sendAction(action: string): void {
 | 
			
		||||
    win.restore();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  win.webContents.send(action);
 | 
			
		||||
  ipcRenderer.sendTo(win.webContents.id, action);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const createTray = function (): void {
 | 
			
		||||
@@ -219,8 +219,7 @@ function toggleTray(): void {
 | 
			
		||||
 | 
			
		||||
  const selector = "webview:not([class*=disabled])";
 | 
			
		||||
  const webview: WebviewTag = document.querySelector(selector)!;
 | 
			
		||||
  const webContents = remote.webContents.fromId(webview.getWebContentsId());
 | 
			
		||||
  webContents.send("toggletray", state);
 | 
			
		||||
  ipcRenderer.sendTo(webview.getWebContentsId(), "toggletray", state);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ipcRenderer.on("toggletray", toggleTray);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user