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);
}
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"),
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)),

View File

@ -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;

View File

@ -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;
}

View File

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