From a05860bc6af28ca3f1448bedced34e117362872d Mon Sep 17 00:00:00 2001 From: lanxiuyun Date: Wed, 3 Dec 2025 13:39:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=94=AF=E6=8C=81=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20onShow=20onHide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 6 ++++++ src/main/browsers/main.ts | 2 ++ src/main/common/api.ts | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/public/preload.js b/public/preload.js index 0cf7acc..05f7c80 100644 --- a/public/preload.js +++ b/public/preload.js @@ -39,6 +39,12 @@ window.rubick = { openPlugin(plugin) { ipcSendSync('loadPlugin', plugin); }, + onShow(cb) { + typeof cb === 'function' && (window.rubick.hooks.onShow = cb); + }, + onHide(cb) { + typeof cb === 'function' && (window.rubick.hooks.onHide = cb); + }, // 窗口交互 hideMainWindow() { ipcSendSync('hideMainWindow'); diff --git a/src/main/browsers/main.ts b/src/main/browsers/main.ts index 35b94db..3fd4031 100644 --- a/src/main/browsers/main.ts +++ b/src/main/browsers/main.ts @@ -59,6 +59,7 @@ export default () => { }); win.on('show', () => { + // 触发主窗口的 onShow hook win.webContents.executeJavaScript( `window.rubick && window.rubick.hooks && typeof window.rubick.hooks.onShow === "function" && window.rubick.hooks.onShow()` ); @@ -67,6 +68,7 @@ export default () => { }); win.on('hide', () => { + // 触发主窗口的 onHide hook win.webContents.executeJavaScript( `window.rubick && window.rubick.hooks && typeof window.rubick.hooks.onHide === "function" && window.rubick.hooks.onHide()` ); diff --git a/src/main/common/api.ts b/src/main/common/api.ts index 34453e8..d455d48 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -68,6 +68,20 @@ class API extends DBInstance { mainWindow.webContents.on('before-input-event', (event, input) => this.__EscapeKeyDown(event, input, mainWindow) ); + // 设置主窗口的 show/hide 事件监听 + this.setupMainWindowHooks(mainWindow); + } + + private setupMainWindowHooks(mainWindow: BrowserWindow) { + mainWindow.on('show', () => { + // 触发插件的 onShow hook + runnerInstance.executeHooks('Show', null); + }); + + mainWindow.on('hide', () => { + // 触发插件的 onHide hook + runnerInstance.executeHooks('Hide', null); + }); } public getCurrentWindow = (window, e) => {