mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-26 12:42:34 +08:00
✨ 主界面开发&插件运行容器开发&菜单开发
This commit is contained in:
3
src/main/@types/index.d.ts
vendored
Normal file
3
src/main/@types/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare module "main" {
|
||||
export function main(): any
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
import main from "./main";
|
||||
console.log(111);
|
||||
export { main };
|
||||
import runner from "./runner";
|
||||
export { main, runner };
|
||||
|
||||
56
src/main/browsers/runner.ts
Normal file
56
src/main/browsers/runner.ts
Normal 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
25
src/main/common/api.ts
Normal 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);
|
||||
});
|
||||
};
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user