mime-chat/src/background/createWindow.ts
2021-02-04 21:25:09 -06:00

38 lines
1.1 KiB
TypeScript

"use strict";
import { BrowserWindow } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import * as path from "path";
export function createWindow(options: {
width: number;
height: number;
resizable: boolean;
}): BrowserWindow {
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");
}
return win;
}