mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-15 06:44:53 +08:00
插件支持调用 onShow onHide
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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()`
|
||||
);
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user