mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-26 04:19:27 +08:00
♻️ 代码重构
This commit is contained in:
@@ -13,7 +13,7 @@ export default () => {
|
||||
|
||||
const createView = (plugin, window: BrowserWindow) => {
|
||||
const preload = commonConst.dev()
|
||||
? `http://localhost:8080/preload.js`
|
||||
? path.resolve(__static, `../feature/public/preload.js`)
|
||||
: path.resolve(plugin.indexPath, `../`, plugin.preload);
|
||||
|
||||
const ses = session.fromPartition("<" + plugin.name + ">");
|
||||
@@ -38,6 +38,8 @@ export default () => {
|
||||
view.setAutoResize({ width: true });
|
||||
window.setSize(800, 660);
|
||||
view.webContents.openDevTools();
|
||||
executeHooks(plugin.ext, "PluginEnter");
|
||||
executeHooks(plugin.ext, "PluginReady");
|
||||
});
|
||||
};
|
||||
|
||||
@@ -45,11 +47,22 @@ export default () => {
|
||||
if (!view) return;
|
||||
window.removeBrowserView(view);
|
||||
window.setSize(800, 60);
|
||||
executeHooks("PluginOut", null);
|
||||
view = undefined;
|
||||
};
|
||||
|
||||
const getView = () => view;
|
||||
|
||||
const executeHooks = (hook, data) => {
|
||||
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);
|
||||
};
|
||||
|
||||
return {
|
||||
init,
|
||||
getView,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { BrowserWindow, ipcMain } from "electron";
|
||||
import { BrowserWindow, ipcMain, dialog } from "electron";
|
||||
import { runner } from "../browsers";
|
||||
|
||||
const runnerInstance = runner();
|
||||
|
||||
const API: any = {
|
||||
setExpendHeight({ height }: { height: number }, win: BrowserWindow): void {
|
||||
win.setSize(800, height || 60);
|
||||
},
|
||||
openPlugin({ plugin }, window) {
|
||||
runnerInstance.removeView(window);
|
||||
runnerInstance.init(plugin, window);
|
||||
@@ -14,6 +11,22 @@ const API: any = {
|
||||
removePlugin(e, window) {
|
||||
runnerInstance.removeView(window);
|
||||
},
|
||||
hideMainWindow(arg, window) {
|
||||
window.hide();
|
||||
},
|
||||
showMainWindow(arg, window) {
|
||||
window.show();
|
||||
},
|
||||
showOpenDialog({ data }, window) {
|
||||
dialog.showOpenDialogSync(window, data);
|
||||
},
|
||||
setExpendHeight({ data: height }, window: BrowserWindow) {
|
||||
const targetHeight = height;
|
||||
window.setSize(window.getSize()[0], targetHeight);
|
||||
},
|
||||
setSubInput() {
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
export default (mainWindow: BrowserWindow) => {
|
||||
|
||||
Reference in New Issue
Block a user