diff --git a/emain/emain-viewmgr.ts b/emain/emain-viewmgr.ts index 0afe7a0f1..8f56f13cf 100644 --- a/emain/emain-viewmgr.ts +++ b/emain/emain-viewmgr.ts @@ -556,3 +556,9 @@ async function setTabViewIntoWindow(bwin: WaveBrowserWindow, tabView: WaveTabVie } }, 30); } + +electron.powerMonitor.on("resume", () => { + for (const tabView of wcvCache.values()) { + tabView.webContents.send("resume"); + } +}); diff --git a/emain/preload.ts b/emain/preload.ts index 6b3e2317d..7325b0bf6 100644 --- a/emain/preload.ts +++ b/emain/preload.ts @@ -13,6 +13,7 @@ contextBridge.exposeInMainWorld("api", { getAboutModalDetails: () => ipcRenderer.sendSync("get-about-modal-details"), getDocsiteUrl: () => ipcRenderer.sendSync("get-docsite-url"), getWebviewPreload: () => ipcRenderer.sendSync("get-webview-preload"), + onResume: (callback) => ipcRenderer.on("resume", callback), openNewWindow: () => ipcRenderer.send("open-new-window"), showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position), onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", (_event, id) => callback(id)), diff --git a/frontend/app/store/ws.ts b/frontend/app/store/ws.ts index e2da02707..457ec4cfd 100644 --- a/frontend/app/store/ws.ts +++ b/frontend/app/store/ws.ts @@ -68,7 +68,7 @@ class WSControl { } connectNow(desc: string) { - if (this.open || this.noReconnect) { + if (this.open || this.noReconnect || this.opening) { return; } this.lastReconnectTime = Date.now(); @@ -134,7 +134,7 @@ class WSControl { if (event.wasClean) { dlog("connection closed"); } else { - dlog("connection error/disconnected"); + dlog("connection error/disconnected", event.code, event.reason); } if (this.open || this.opening) { this.open = false; @@ -157,6 +157,16 @@ class WSControl { this.runMsgQueue(); } + onResume() { + dlog("onResume"); + this.reconnectTimes = 0; + if (!this.open) { + this.reconnect(); + } else { + this.sendPing(); + } + } + runMsgQueue() { if (!this.open) { return; diff --git a/frontend/app/store/wshrpcutil.ts b/frontend/app/store/wshrpcutil.ts index b0d40bf2e..8ba63da49 100644 --- a/frontend/app/store/wshrpcutil.ts +++ b/frontend/app/store/wshrpcutil.ts @@ -1,6 +1,7 @@ // Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { getApi } from "@/app/store/global"; import { wpsReconnectHandler } from "@/app/store/wps"; import { WshClient } from "@/app/store/wshclient"; import { makeTabRouteId, WshRouter } from "@/app/store/wshrouter"; @@ -139,6 +140,9 @@ function initWshrpc(tabId: string): WSControl { DefaultRouter.reannounceRoutes(); }); addWSReconnectHandler(wpsReconnectHandler); + getApi().onResume(() => { + globalWS?.onResume(); + }); return globalWS; } diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index 6cd1c8e55..20f356f5d 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -65,6 +65,7 @@ declare global { getUserName: () => string; getHostName: () => string; getWebviewPreload: () => string; + onResume: (callback: () => void) => void; getAboutModalDetails: () => AboutModalDetails; getDocsiteUrl: () => string; showContextMenu: (menu?: ElectronContextMenuItem[]) => void;