From 6b9d5182bf90e9c7d3a8b8b47feb2f72e1a43966 Mon Sep 17 00:00:00 2001 From: layyback <505187749@qq.com> Date: Thu, 18 Jul 2024 16:46:33 +0800 Subject: [PATCH 1/2] :bug: fix hooks triggering issue --- src/main/browsers/runner.ts | 28 ++++++++++++++-------------- src/main/common/api.ts | 6 ++++-- src/renderer/App.vue | 13 +++++++------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/browsers/runner.ts b/src/main/browsers/runner.ts index d63b7881..3c58e469 100644 --- a/src/main/browsers/runner.ts +++ b/src/main/browsers/runner.ts @@ -72,6 +72,8 @@ export default () => { view.setAutoResize({ width: true, height: true }); executeHooks('PluginEnter', ext); executeHooks('PluginReady', ext); + console.log('enterrrr'); + const config = await localConfig.getConfig(); const darkMode = config.perf.common.darkMode; darkMode && @@ -175,31 +177,29 @@ export default () => { const removeView = (window: BrowserWindow) => { if (!view) return; - window.removeBrowserView(view); - if (!view.inDetach) { - window.setBrowserView(null); - view.webContents?.destroy(); - } - - // window.setSize(800, 60); executeHooks('PluginOut', null); - window.webContents?.executeJavaScript(`window.initRubick()`); - view = undefined; + setTimeout(() => { + window.removeBrowserView(view); + if (!view.inDetach) { + window.setBrowserView(null); + view.webContents?.destroy(); + } + window.webContents?.executeJavaScript(`window.initRubick()`); + view = undefined; + }, 0); }; const getView = () => view; const executeHooks = (hook, data) => { - setTimeout(() => { - if (!view) return; - const evalJs = `if(window.rubick && window.rubick.hooks && typeof window.rubick.hooks.on${hook} === 'function' ) { + if (!view) return; + const evalJs = `if(window.rubick && window.rubick.hooks && typeof window.rubick.hooks.on${hook} === 'function' ) { try { window.rubick.hooks.on${hook}(${data ? JSON.stringify(data) : ''}); } catch(e) {} } `; - view.webContents?.executeJavaScript(evalJs); - }, 300); + view.webContents?.executeJavaScript(evalJs); }; return { diff --git a/src/main/common/api.ts b/src/main/common/api.ts index e08f9f34..61c43c56 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -91,7 +91,7 @@ class API extends DBInstance { }).show(); } window.setSize(window.getSize()[0], 60); - this.removePlugin(null, window); + // this.removePlugin(null, window); // 模板文件 if (!plugin.main) { plugin.tplPath = common.dev() @@ -128,8 +128,10 @@ class API extends DBInstance { } public removePlugin(e, window) { - this.currentPlugin = null; runnerInstance.removeView(window); + setTimeout(() => { + this.currentPlugin = null; + }, 100); } public openPluginDevTools() { diff --git a/src/renderer/App.vue b/src/renderer/App.vue index dbdfe735..c62da667 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,8 +1,5 @@