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> {
 | 
					  async send(channel: string, ...parameters: unknown[]): Promise<void> {
 | 
				
			||||||
    await this.domReady;
 | 
					    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 {
 | 
					  updateGeneralSettings(setting: string, value: unknown): void {
 | 
				
			||||||
    if (this.getActiveWebview()) {
 | 
					    if (this.getActiveWebview()) {
 | 
				
			||||||
      const webContents = remote.webContents.fromId(
 | 
					      const webContentsId = this.getActiveWebview().getWebContentsId();
 | 
				
			||||||
        this.getActiveWebview().getWebContentsId(),
 | 
					      ipcRenderer.sendTo(webContentsId, setting, value);
 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      webContents.send(setting, value);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1065,10 +1063,8 @@ class ServerManagerView {
 | 
				
			|||||||
          "toggle-silent",
 | 
					          "toggle-silent",
 | 
				
			||||||
          newSettings.silent,
 | 
					          newSettings.silent,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        const webContents = remote.webContents.fromId(
 | 
					        const webContentsId = this.getActiveWebview().getWebContentsId();
 | 
				
			||||||
          this.getActiveWebview().getWebContentsId(),
 | 
					        ipcRenderer.sendTo(webContentsId, "toggle-dnd", state, newSettings);
 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        webContents.send("toggle-dnd", state, newSettings);
 | 
					 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1197,22 +1193,22 @@ class ServerManagerView {
 | 
				
			|||||||
      await this.openSettings("AddServer");
 | 
					      await this.openSettings("AddServer");
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ipcRenderer.on("set-active", async () => {
 | 
					    ipcRenderer.on("set-active", () => {
 | 
				
			||||||
      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
					      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
				
			||||||
        "webview",
 | 
					        "webview",
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      await Promise.all(
 | 
					      for (const webview of webviews) {
 | 
				
			||||||
        [...webviews].map(async (webview) => webview.send("set-active")),
 | 
					        ipcRenderer.sendTo(webview.getWebContentsId(), "set-active");
 | 
				
			||||||
      );
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ipcRenderer.on("set-idle", async () => {
 | 
					    ipcRenderer.on("set-idle", () => {
 | 
				
			||||||
      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
					      const webviews: NodeListOf<Electron.WebviewTag> = document.querySelectorAll(
 | 
				
			||||||
        "webview",
 | 
					        "webview",
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      await Promise.all(
 | 
					      for (const webview of webviews) {
 | 
				
			||||||
        [...webviews].map(async (webview) => webview.send("set-idle")),
 | 
					        ipcRenderer.sendTo(webview.getWebContentsId(), "set-idle");
 | 
				
			||||||
      );
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ipcRenderer.on("open-network-settings", async () => {
 | 
					    ipcRenderer.on("open-network-settings", async () => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
import {remote} from "electron";
 | 
					import {ipcRenderer, remote} from "electron";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Do not change this
 | 
					// Do not change this
 | 
				
			||||||
export const appId = "org.zulip.zulip-electron";
 | 
					export const appId = "org.zulip.zulip-electron";
 | 
				
			||||||
@@ -10,5 +10,9 @@ const webContentsId = webContents.id;
 | 
				
			|||||||
// This function will focus the server that sent
 | 
					// This function will focus the server that sent
 | 
				
			||||||
// the notification. Main function implemented in main.js
 | 
					// the notification. Main function implemented in main.js
 | 
				
			||||||
export function focusCurrentServer(): void {
 | 
					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);
 | 
					        const newValue = !ConfigUtil.getConfigItem("silent", true);
 | 
				
			||||||
        ConfigUtil.setConfigItem("silent", newValue);
 | 
					        ConfigUtil.setConfigItem("silent", newValue);
 | 
				
			||||||
        updateSilentOption();
 | 
					        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.restore();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  win.webContents.send(action);
 | 
					  ipcRenderer.sendTo(win.webContents.id, action);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const createTray = function (): void {
 | 
					const createTray = function (): void {
 | 
				
			||||||
@@ -219,8 +219,7 @@ function toggleTray(): void {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const selector = "webview:not([class*=disabled])";
 | 
					  const selector = "webview:not([class*=disabled])";
 | 
				
			||||||
  const webview: WebviewTag = document.querySelector(selector)!;
 | 
					  const webview: WebviewTag = document.querySelector(selector)!;
 | 
				
			||||||
  const webContents = remote.webContents.fromId(webview.getWebContentsId());
 | 
					  ipcRenderer.sendTo(webview.getWebContentsId(), "toggletray", state);
 | 
				
			||||||
  webContents.send("toggletray", state);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ipcRenderer.on("toggletray", toggleTray);
 | 
					ipcRenderer.on("toggletray", toggleTray);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user