环境:vue+electron+electron-builder
background.js
import { app } from 'electron'
import Launch from './wins/launch.js'
app.on('ready', () => {
const LaunchPage=new Launch({
width:600,
height:500
})
LaunchPage.init()
})
import { BrowserWindow } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
const events = require("events");
const winConfig = {
show: false,
frame: false,
focusable: true,
resizable: false,
webPreferences: {
nodeIntergration: true,
contextIsolation: false,
},
};
class Launch extends events {
constructor(confInfo) {
super();
this.confInfo = confInfo;
this.conf = Object.assign({}, winConfig, confInfo);
this.windowInstance = new BrowserWindow(this.conf);
// this.windowInstance.loadURL(`${process.env.WEBPACK_DEV_SERVER_URL}/#/launchPage`)
console.log(process.env.WEBPACK_DEV_SERVER_URL);
if (process.env.WEBPACK_DEV_SERVER_URL) {
this.windowInstance.loadURL(
`${process.env.WEBPACK_DEV_SERVER_URL}#/launchPage`
);
if (!process.env.IS_TEST) this.windowInstance.webContents.openDevTools();
} else {
createProtocol("app");
this.windowInstance.loadURL("app://./index.html/#/launchPage");
}
}
init() {
this.windowInstance.once("ready-to-show", () => {
this.windowInstance.show();
});
}
}
export default Launch;