mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
implement resume event for tabs/websocket
This commit is contained in:
parent
0590ba2509
commit
984533e21d
@ -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");
|
||||
}
|
||||
});
|
||||
|
@ -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)),
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
1
frontend/types/custom.d.ts
vendored
1
frontend/types/custom.d.ts
vendored
@ -65,6 +65,7 @@ declare global {
|
||||
getUserName: () => string;
|
||||
getHostName: () => string;
|
||||
getWebviewPreload: () => string;
|
||||
onResume: (callback: () => void) => void;
|
||||
getAboutModalDetails: () => AboutModalDetails;
|
||||
getDocsiteUrl: () => string;
|
||||
showContextMenu: (menu?: ElectronContextMenuItem[]) => void;
|
||||
|
Loading…
Reference in New Issue
Block a user