mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-26 22:52:48 +08:00
🐛 修复 #221 & 性能优化,支持插件窗口池
This commit is contained in:
parent
6dffd1a793
commit
61b4e37fe0
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve --port 8083",
|
"serve": "vue-cli-service serve --port 8084",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rubick",
|
"name": "rubick",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"author": "muwoo <2424880409@qq.com>",
|
"author": "muwoo <2424880409@qq.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -52,7 +52,7 @@ export default () => {
|
|||||||
});
|
});
|
||||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||||
// Load the url of the dev server if in development mode
|
// Load the url of the dev server if in development mode
|
||||||
win.loadURL('http://localhost:8083');
|
win.loadURL('http://localhost:8084');
|
||||||
} else {
|
} else {
|
||||||
win.loadURL(`file://${path.join(__static, './guide/index.html')}`);
|
win.loadURL(`file://${path.join(__static, './guide/index.html')}`);
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,60 @@ const getPreloadPath = (plugin, pluginIndexPath) => {
|
|||||||
return path.resolve(getRelativePath(pluginIndexPath), `../`, preload);
|
return path.resolve(getRelativePath(pluginIndexPath), `../`, preload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const viewPoolManager = () => {
|
||||||
|
const viewPool: any = {
|
||||||
|
views: [],
|
||||||
|
};
|
||||||
|
const maxLen = 4;
|
||||||
|
return {
|
||||||
|
getView(pluginName) {
|
||||||
|
return viewPool.views.find((view) => view.pluginName === pluginName);
|
||||||
|
},
|
||||||
|
addView(pluginName, view) {
|
||||||
|
if (this.getView(pluginName)) return;
|
||||||
|
if (viewPool.views.length > maxLen) {
|
||||||
|
viewPool.views.shift();
|
||||||
|
}
|
||||||
|
viewPool.views.push({
|
||||||
|
pluginName,
|
||||||
|
view,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
let view;
|
let view;
|
||||||
|
const viewInstance = viewPoolManager();
|
||||||
|
|
||||||
|
const viewReadyFn = async (window, { pluginSetting, ext }) => {
|
||||||
|
if (!view) return;
|
||||||
|
const height = pluginSetting && pluginSetting.height;
|
||||||
|
window.setSize(800, height || 660);
|
||||||
|
view.setBounds({ x: 0, y: 60, width: 800, height: height || 600 });
|
||||||
|
view.setAutoResize({ width: true });
|
||||||
|
executeHooks('PluginEnter', ext);
|
||||||
|
executeHooks('PluginReady', ext);
|
||||||
|
const config = await localConfig.getConfig();
|
||||||
|
const darkMode = config.perf.common.darkMode;
|
||||||
|
darkMode &&
|
||||||
|
view.webContents.executeJavaScript(
|
||||||
|
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
||||||
|
);
|
||||||
|
window.webContents.executeJavaScript(`window.pluginLoaded()`);
|
||||||
|
};
|
||||||
|
|
||||||
const init = (plugin, window: BrowserWindow) => {
|
const init = (plugin, window: BrowserWindow) => {
|
||||||
if (view === null || view === undefined) {
|
if (view === null || view === undefined) {
|
||||||
|
if (viewInstance.getView(plugin.name) && !commonConst.dev()) {
|
||||||
|
view = viewInstance.getView(plugin.name).view;
|
||||||
|
window.setBrowserView(view);
|
||||||
|
view.inited = true;
|
||||||
|
viewReadyFn(window, plugin);
|
||||||
|
} else {
|
||||||
createView(plugin, window);
|
createView(plugin, window);
|
||||||
|
viewInstance.addView(plugin.name, view);
|
||||||
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
require('@electron/remote/main').enable(view.webContents);
|
require('@electron/remote/main').enable(view.webContents);
|
||||||
}
|
}
|
||||||
@ -75,26 +123,16 @@ export default () => {
|
|||||||
webviewTag: true,
|
webviewTag: true,
|
||||||
preload,
|
preload,
|
||||||
session: ses,
|
session: ses,
|
||||||
|
defaultFontSize: 14,
|
||||||
|
defaultFontFamily: {
|
||||||
|
standard: 'system-ui',
|
||||||
|
serif: 'system-ui',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
window.setBrowserView(view);
|
window.setBrowserView(view);
|
||||||
view.webContents.loadURL(pluginIndexPath);
|
view.webContents.loadURL(pluginIndexPath);
|
||||||
view.webContents.once('dom-ready', async () => {
|
view.webContents.once('dom-ready', () => viewReadyFn(window, plugin));
|
||||||
if (!view) return;
|
|
||||||
const height = pluginSetting && pluginSetting.height;
|
|
||||||
window.setSize(800, height || 660);
|
|
||||||
view.setBounds({ x: 0, y: 60, width: 800, height: height || 600 });
|
|
||||||
view.setAutoResize({ width: true });
|
|
||||||
executeHooks('PluginEnter', plugin.ext);
|
|
||||||
executeHooks('PluginReady', plugin.ext);
|
|
||||||
const config = await localConfig.getConfig();
|
|
||||||
const darkMode = config.perf.common.darkMode;
|
|
||||||
darkMode &&
|
|
||||||
view.webContents.executeJavaScript(
|
|
||||||
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
|
||||||
);
|
|
||||||
window.webContents.executeJavaScript(`window.pluginLoaded()`);
|
|
||||||
});
|
|
||||||
// 修复请求跨域问题
|
// 修复请求跨域问题
|
||||||
view.webContents.session.webRequest.onBeforeSendHeaders(
|
view.webContents.session.webRequest.onBeforeSendHeaders(
|
||||||
(details, callback) => {
|
(details, callback) => {
|
||||||
|
@ -33,6 +33,10 @@ class API extends DBInstance {
|
|||||||
event.returnValue = data;
|
event.returnValue = data;
|
||||||
// event.sender.send(`msg-back-${arg.type}`, data);
|
// event.sender.send(`msg-back-${arg.type}`, data);
|
||||||
});
|
});
|
||||||
|
// 按 ESC 退出插件
|
||||||
|
mainWindow.webContents.on('before-input-event', (event, input) =>
|
||||||
|
this.__EscapeKeyDown(event, input, mainWindow)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCurrentWindow = (window, e) => {
|
public getCurrentWindow = (window, e) => {
|
||||||
@ -81,16 +85,13 @@ class API extends DBInstance {
|
|||||||
})})`
|
})})`
|
||||||
);
|
);
|
||||||
window.show();
|
window.show();
|
||||||
// 按 ESC 退出插件
|
const view = runnerInstance.getView();
|
||||||
window.webContents.on('before-input-event', (event, input) =>
|
if (!view.inited) {
|
||||||
this.__EscapeKeyDown(event, input, window)
|
view.webContents.on('before-input-event', (event, input) =>
|
||||||
);
|
|
||||||
runnerInstance
|
|
||||||
.getView()
|
|
||||||
.webContents.on('before-input-event', (event, input) =>
|
|
||||||
this.__EscapeKeyDown(event, input, window)
|
this.__EscapeKeyDown(event, input, window)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public removePlugin(e, window) {
|
public removePlugin(e, window) {
|
||||||
this.currentPlugin = null;
|
this.currentPlugin = null;
|
||||||
|
@ -19,7 +19,7 @@ function searchKeyValues(lists, value, strict = false) {
|
|||||||
if (item.type === 'regex' && !strict) {
|
if (item.type === 'regex' && !strict) {
|
||||||
return formatReg(item.match).test(value);
|
return formatReg(item.match).test(value);
|
||||||
}
|
}
|
||||||
if (item.type === 'over') {
|
if (item.type === 'over' && !strict) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -15,7 +15,7 @@ export default function pluginClickEvent({ plugin, fe, cmd, ext, openPlugin }) {
|
|||||||
// 模板文件
|
// 模板文件
|
||||||
if (!plugin.main) {
|
if (!plugin.main) {
|
||||||
pluginDist.tplPath = commonConst.dev()
|
pluginDist.tplPath = commonConst.dev()
|
||||||
? 'http://localhost:8082/#/'
|
? 'http://localhost:8083/#/'
|
||||||
: `file://${__static}/tpl/index.html`;
|
: `file://${__static}/tpl/index.html`;
|
||||||
}
|
}
|
||||||
// 插件市场
|
// 插件市场
|
||||||
|
Loading…
x
Reference in New Issue
Block a user