42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
"use strict";
|
|
|
|
import { BrowserWindow } from "electron";
|
|
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
|
import * as path from "path";
|
|
|
|
interface WindowSettings {
|
|
width: number;
|
|
height: number;
|
|
resizable: boolean;
|
|
}
|
|
|
|
export const createWindow = async (options: WindowSettings): Promise<BrowserWindow> => {
|
|
return new Promise((resolve, reject) => {
|
|
const win: BrowserWindow = new BrowserWindow({
|
|
width: options.width,
|
|
height: options.height,
|
|
resizable: options.resizable,
|
|
webPreferences: {
|
|
// Use pluginOptions.nodeIntegration, leave this alone
|
|
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
|
|
nodeIntegration: (process.env
|
|
.ELECTRON_NODE_INTEGRATION as unknown) as boolean,
|
|
preload: path.join(__dirname, "preload.js")
|
|
}
|
|
});
|
|
|
|
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");
|
|
}
|
|
|
|
win.webContents.on('did-finish-load', () => {
|
|
resolve(win);
|
|
});
|
|
})
|
|
}
|
|
|