支持插件分离,增加开发者工具功能

This commit is contained in:
muwoo
2022-01-04 14:03:25 +08:00
parent c69be6c24f
commit 19cd77b26c
29 changed files with 13717 additions and 15 deletions

View 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,
};
};

View File

@@ -1,3 +1,4 @@
import main from "./main";
import runner from "./runner";
export { main, runner };
import detach from "./detach";
export { main, runner, detach };

View File

@@ -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()`);