mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-28 13:45:49 +08:00
🎉 初始化项目 electron13 + vue3 + typescript
This commit is contained in:
66
src/main/browsers/main.ts
Normal file
66
src/main/browsers/main.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { app, BrowserWindow, protocol } from "electron";
|
||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||
export default () => {
|
||||
let win: any;
|
||||
|
||||
const init = () => {
|
||||
createWindow();
|
||||
};
|
||||
|
||||
const createWindow = async () => {
|
||||
win = new BrowserWindow({
|
||||
height: 600,
|
||||
useContentSize: true,
|
||||
resizable: true,
|
||||
width: 800,
|
||||
frame: false,
|
||||
title: "拉比克",
|
||||
show: false,
|
||||
skipTaskbar: true,
|
||||
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(process.env.WEBPACK_DEV_SERVER_URL as string);
|
||||
} else {
|
||||
createProtocol("app");
|
||||
// Load the index.html when not in development
|
||||
win.loadURL("app://./index.html");
|
||||
}
|
||||
|
||||
protocol.interceptFileProtocol("image", (req, callback) => {
|
||||
const url = req.url.substr(8);
|
||||
callback(decodeURI(url));
|
||||
});
|
||||
|
||||
win.once("ready-to-show", () => {
|
||||
win.show();
|
||||
// 非隐藏式启动需要显示主窗口
|
||||
if (!app.getLoginItemSettings().wasOpenedAsHidden) {
|
||||
win.show();
|
||||
}
|
||||
});
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
|
||||
// 判断失焦是否隐藏
|
||||
win.on("blur", () => {
|
||||
app.isPackaged && win.hide();
|
||||
});
|
||||
};
|
||||
|
||||
const getWindow = () => win;
|
||||
|
||||
return {
|
||||
init,
|
||||
getWindow,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user