🐛 fix hooks triggering issue

This commit is contained in:
layyback 2024-07-18 16:46:33 +08:00
parent 2053491782
commit 6b9d5182bf
3 changed files with 25 additions and 22 deletions

View File

@ -72,6 +72,8 @@ export default () => {
view.setAutoResize({ width: true, height: true }); view.setAutoResize({ width: true, height: true });
executeHooks('PluginEnter', ext); executeHooks('PluginEnter', ext);
executeHooks('PluginReady', ext); executeHooks('PluginReady', ext);
console.log('enterrrr');
const config = await localConfig.getConfig(); const config = await localConfig.getConfig();
const darkMode = config.perf.common.darkMode; const darkMode = config.perf.common.darkMode;
darkMode && darkMode &&
@ -175,31 +177,29 @@ export default () => {
const removeView = (window: BrowserWindow) => { const removeView = (window: BrowserWindow) => {
if (!view) return; if (!view) return;
window.removeBrowserView(view);
if (!view.inDetach) {
window.setBrowserView(null);
view.webContents?.destroy();
}
// window.setSize(800, 60);
executeHooks('PluginOut', null); executeHooks('PluginOut', null);
window.webContents?.executeJavaScript(`window.initRubick()`); setTimeout(() => {
view = undefined; window.removeBrowserView(view);
if (!view.inDetach) {
window.setBrowserView(null);
view.webContents?.destroy();
}
window.webContents?.executeJavaScript(`window.initRubick()`);
view = undefined;
}, 0);
}; };
const getView = () => view; const getView = () => view;
const executeHooks = (hook, data) => { const executeHooks = (hook, data) => {
setTimeout(() => { if (!view) return;
if (!view) return; const evalJs = `if(window.rubick && window.rubick.hooks && typeof window.rubick.hooks.on${hook} === 'function' ) {
const evalJs = `if(window.rubick && window.rubick.hooks && typeof window.rubick.hooks.on${hook} === 'function' ) {
try { try {
window.rubick.hooks.on${hook}(${data ? JSON.stringify(data) : ''}); window.rubick.hooks.on${hook}(${data ? JSON.stringify(data) : ''});
} catch(e) {} } catch(e) {}
} }
`; `;
view.webContents?.executeJavaScript(evalJs); view.webContents?.executeJavaScript(evalJs);
}, 300);
}; };
return { return {

View File

@ -91,7 +91,7 @@ class API extends DBInstance {
}).show(); }).show();
} }
window.setSize(window.getSize()[0], 60); window.setSize(window.getSize()[0], 60);
this.removePlugin(null, window); // this.removePlugin(null, window);
// 模板文件 // 模板文件
if (!plugin.main) { if (!plugin.main) {
plugin.tplPath = common.dev() plugin.tplPath = common.dev()
@ -128,8 +128,10 @@ class API extends DBInstance {
} }
public removePlugin(e, window) { public removePlugin(e, window) {
this.currentPlugin = null;
runnerInstance.removeView(window); runnerInstance.removeView(window);
setTimeout(() => {
this.currentPlugin = null;
}, 100);
} }
public openPluginDevTools() { public openPluginDevTools() {

View File

@ -1,8 +1,5 @@
<template> <template>
<div <div id="components-layout" @mousedown="onMouseDown">
id="components-layout"
@mousedown="onMouseDown"
>
<Search <Search
:currentPlugin="currentPlugin" :currentPlugin="currentPlugin"
@changeCurrent="changeIndex" @changeCurrent="changeIndex"
@ -94,7 +91,9 @@ watch(
window.rubick.setExpendHeight( window.rubick.setExpendHeight(
getWindowHeight( getWindowHeight(
options.value, options.value,
(pluginLoading.value || !config.value.perf.common.history) ? [] : pluginHistory.value pluginLoading.value || !config.value.perf.common.history
? []
: pluginHistory.value
) )
); );
}, },
@ -161,7 +160,9 @@ const choosePlugin = (plugin) => {
}); });
if (hasRemove) { if (hasRemove) {
const result = window.rubick.db.get(PLUGIN_HISTORY) || {}; const result = window.rubick.db.get(PLUGIN_HISTORY) || {};
const history = result.data.filter(item => item.originName !== currentChoose.originName); const history = result.data.filter(
(item) => item.originName !== currentChoose.originName
);
setPluginHistory(history); setPluginHistory(history);
return message.warning('插件已被卸载!'); return message.warning('插件已被卸载!');
} }