主界面开发&插件运行容器开发&菜单开发

This commit is contained in:
muwoo
2021-11-26 17:22:45 +08:00
parent 072d57f068
commit 766ba46dcc
59 changed files with 29326 additions and 244 deletions

3
src/main/@types/index.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
declare module "main" {
export function main(): any
}

View File

@@ -1,3 +1,3 @@
import main from "./main";
console.log(111);
export { main };
import runner from "./runner";
export { main, runner };

View File

@@ -0,0 +1,56 @@
import { app, BrowserWindow } from "electron";
export default () => {
let win;
const init = (plugin) => {
if (win === null || win === undefined) {
createWindow(plugin);
}
};
const createWindow = (plugin) => {
win = new BrowserWindow({
autoHideMenuBar: true,
width: 800,
height: 800,
alwaysOnTop: true,
resizable: false,
focusable: true,
show: false,
webPreferences: {
webSecurity: false,
nodeIntegration: true,
contextIsolation: false,
devTools: true,
webviewTag: true,
},
});
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
win.loadURL("http://localhost:8080" as string);
} else {
// Load the index.html when not in development
win.loadURL(`file://${__static}/runner/index.html`);
}
win.webContents.on("dom-ready", () => {
win.webContents.executeJavaScript(`window.setPluginInfo(${JSON.stringify(plugin)})`);
});
win.once("ready-to-show", () => {
win.show();
});
win.on("closed", () => {
win = undefined;
});
};
const getWindow = () => win;
return {
init,
getWindow,
};
};

25
src/main/common/api.ts Normal file
View File

@@ -0,0 +1,25 @@
import { BrowserWindow, ipcMain } 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}) {
console.log(plugin);
runnerInstance.init(plugin);
},
};
export default (mainWindow: BrowserWindow) => {
// 响应 preload.js 事件
ipcMain.on("msg-trigger", async (event, arg) => {
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow;
const data = await API[arg.type](arg, window);
event.returnValue = data;
// event.sender.send(`msg-back-${arg.type}`, data);
});
};

View File

@@ -2,6 +2,9 @@
import { app, globalShortcut, protocol, BrowserWindow } from "electron";
import { main } from "./browsers";
import commonConst from "../common/utils/commonConst";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import API from "./common/api";
class App {
private windowCreator: { init: () => void; getWindow: () => BrowserWindow };
@@ -42,6 +45,7 @@ class App {
onReady() {
const readyFunction = () => {
this.createWindow();
API(this.windowCreator.getWindow());
// this.init()
// createTray(this.windowCreator.getWindow())
// autoUpdate()