refactor tests for readability + linting fixes

This commit is contained in:
Enrique Hernandez 2021-02-10 23:04:53 -06:00
commit 57fce6d6cc
12 changed files with 123 additions and 318 deletions

60
src/background/window.ts Normal file
View file

@ -0,0 +1,60 @@
"use strict";
import { BrowserWindow, ipcMain } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import { backgroundMitt } from './emitter';
import { sendMessage } from './session';
import * as path from "path";
interface WindowSettings {
width: number;
height: number;
resizable: boolean;
}
interface TextMessage {
audio: 0;
content: string;
}
const handleMessage = (_event, arg: TextMessage | Buffer ) => {
sendMessage(arg);
}
const windowMount = (): void => {
backgroundMitt.emit('window-active', true);
ipcMain.on('send-message', handleMessage);
}
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', () => {
windowMount();
resolve(win);
});
});
};