implement resume event for tabs/websocket

This commit is contained in:
sawka 2024-10-18 10:05:07 -07:00
parent 0590ba2509
commit 984533e21d
5 changed files with 24 additions and 2 deletions

View File

@ -556,3 +556,9 @@ async function setTabViewIntoWindow(bwin: WaveBrowserWindow, tabView: WaveTabVie
} }
}, 30); }, 30);
} }
electron.powerMonitor.on("resume", () => {
for (const tabView of wcvCache.values()) {
tabView.webContents.send("resume");
}
});

View File

@ -13,6 +13,7 @@ contextBridge.exposeInMainWorld("api", {
getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"), getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"),
getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"), getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"),
getWebviewPreload: () => ipcRenderer.sendSync("get-webview-preload"), getWebviewPreload: () => ipcRenderer.sendSync("get-webview-preload"),
onResume: (callback) => ipcRenderer.on("resume", callback),
openNewWindow: () => ipcRenderer.send("open-new-window"), openNewWindow: () => ipcRenderer.send("open-new-window"),
showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position), showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position),
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)), onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)),

View File

@ -68,7 +68,7 @@ class WSControl {
} }
connectNow(desc: string) { connectNow(desc: string) {
if (this.open || this.noReconnect) { if (this.open || this.noReconnect || this.opening) {
return; return;
} }
this.lastReconnectTime = Date.now(); this.lastReconnectTime = Date.now();
@ -134,7 +134,7 @@ class WSControl {
if (event.wasClean) { if (event.wasClean) {
dlog("connection closed"); dlog("connection closed");
} else { } else {
dlog("connection error/disconnected"); dlog("connection error/disconnected", event.code, event.reason);
} }
if (this.open || this.opening) { if (this.open || this.opening) {
this.open = false; this.open = false;
@ -157,6 +157,16 @@ class WSControl {
this.runMsgQueue(); this.runMsgQueue();
} }
onResume() {
dlog("onResume");
this.reconnectTimes = 0;
if (!this.open) {
this.reconnect();
} else {
this.sendPing();
}
}
runMsgQueue() { runMsgQueue() {
if (!this.open) { if (!this.open) {
return; return;

View File

@ -1,6 +1,7 @@
// Copyright 2024, Command Line Inc. // Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { getApi } from "@/app/store/global";
import { wpsReconnectHandler } from "@/app/store/wps"; import { wpsReconnectHandler } from "@/app/store/wps";
import { WshClient } from "@/app/store/wshclient"; import { WshClient } from "@/app/store/wshclient";
import { makeTabRouteId, WshRouter } from "@/app/store/wshrouter"; import { makeTabRouteId, WshRouter } from "@/app/store/wshrouter";
@ -139,6 +140,9 @@ function initWshrpc(tabId: string): WSControl {
DefaultRouter.reannounceRoutes(); DefaultRouter.reannounceRoutes();
}); });
addWSReconnectHandler(wpsReconnectHandler); addWSReconnectHandler(wpsReconnectHandler);
getApi().onResume(() => {
globalWS?.onResume();
});
return globalWS; return globalWS;
} }

View File

@ -65,6 +65,7 @@ declare global {
getUserName: () => string; getUserName: () => string;
getHostName: () => string; getHostName: () => string;
getWebviewPreload: () => string; getWebviewPreload: () => string;
onResume: (callback: () => void) => void;
getAboutModalDetails: () => AboutModalDetails; getAboutModalDetails: () => AboutModalDetails;
getDocsiteUrl: () => string; getDocsiteUrl: () => string;
showContextMenu: (menu?: ElectronContextMenuItem[]) => void; showContextMenu: (menu?: ElectronContextMenuItem[]) => void;