Merge pull request #481 from lanxiuyun/hooks-onShow-onHide

插件支持调用 onShow onHide
This commit is contained in:
muwoo
2025-12-03 13:54:07 +08:00
committed by GitHub
3 changed files with 22 additions and 0 deletions

View File

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

View File

@@ -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()`
);

View File

@@ -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) => {