mirror of
https://github.com/rubickCenter/rubick
synced 2026-01-01 00:39:39 +08:00
✨ 支持插件分离,增加开发者工具功能
This commit is contained in:
57
src/main/browsers/detach.ts
Normal file
57
src/main/browsers/detach.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { app, BrowserWindow, protocol } from "electron";
|
||||
import path from "path";
|
||||
export default () => {
|
||||
let win: any;
|
||||
|
||||
const init = (pluginInfo, viewInfo, view) => {
|
||||
createWindow(pluginInfo, viewInfo, view);
|
||||
};
|
||||
|
||||
const createWindow = async (pluginInfo, viewInfo, view) => {
|
||||
win = new BrowserWindow({
|
||||
height: viewInfo.height,
|
||||
width: viewInfo.width,
|
||||
autoHideMenuBar: true,
|
||||
titleBarStyle: "hidden",
|
||||
trafficLightPosition: { x: 12, y: 21 },
|
||||
title: pluginInfo.pluginName,
|
||||
resizable: true,
|
||||
frame: true,
|
||||
show: false,
|
||||
enableLargerThanScreen: true,
|
||||
x: viewInfo.x,
|
||||
y: viewInfo.y,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true,
|
||||
},
|
||||
});
|
||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||
// Load the url of the dev server if in development mode
|
||||
win.loadURL("http://localhost:8082");
|
||||
} else {
|
||||
win.loadURL(`file://${path.join(__static, "./detach/index.html")}`);
|
||||
}
|
||||
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
|
||||
win.once("ready-to-show", () => {
|
||||
win.setBrowserView(view);
|
||||
win.webContents.executeJavaScript(`window.initDetach(${JSON.stringify(pluginInfo)})`)
|
||||
win.show();
|
||||
});
|
||||
};
|
||||
|
||||
const getWindow = () => win;
|
||||
|
||||
return {
|
||||
init,
|
||||
getWindow,
|
||||
};
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import main from "./main";
|
||||
import runner from "./runner";
|
||||
export { main, runner };
|
||||
import detach from "./detach";
|
||||
export { main, runner, detach };
|
||||
|
||||
@@ -63,7 +63,6 @@ export default () => {
|
||||
window.setSize(800, 660);
|
||||
view.setBounds({ x: 0, y: 60, width: 800, height: 600 });
|
||||
view.setAutoResize({ width: true });
|
||||
commonConst.dev() && view.webContents.openDevTools();
|
||||
executeHooks("PluginEnter", plugin.ext);
|
||||
executeHooks("PluginReady", plugin.ext);
|
||||
window.webContents.executeJavaScript(`window.pluginLoaded()`);
|
||||
|
||||
Reference in New Issue
Block a user