From: Andrew Gundersen Date: Fri, 5 Feb 2021 19:21:53 +0000 (-0600) Subject: merged origin/main into main X-Git-Tag: v0.9~100^2 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=64aa442a3c96c30a3e275a1fe1aa1173443218d4;p=mime-chat merged origin/main into main --- 64aa442a3c96c30a3e275a1fe1aa1173443218d4 diff --cc src/background.ts index cf052e0,5b5ceec..0b11170 --- a/src/background.ts +++ b/src/background.ts @@@ -1,27 -1,25 +1,24 @@@ + /* + * Entry point for Crimata electron app. + * "Look on my Works, ye Mighty, and despair!" + */ + "use strict"; - import {initApp} from './background/initApp'; - import {Recorder} from './background/recorder'; - const portAudio = require('naudiodon'); - + import { protocol } from "electron"; + import { initApp } from './background/initApp'; + + // Scheme must be registered before the app is ready + protocol.registerSchemesAsPrivileged([ + { scheme: "app", privileges: { secure: true, standard: true } } + ]); + // Load environment variable + const isDevelopment = process.env.NODE_ENV !== "production"; // NOTE Program Begins Here (async () => { - const isDevelopment = process.env.NODE_ENV !== "production"; - - const recorder = new Recorder({ - channelCount: 1, - sampleFormat: portAudio.SampleFormat16Bit, - sampleRate: 16000, - deviceId: -1, // Use -1 or omit the deviceId to select the default device - closeOnError: true - }, 'binary'); - - try { - // await authenticate method - initApp(isDevelopment); - } catch (e) { - console.log("Error", e); - } + console.log('Starting Crimata electron app.'); + initApp(isDevelopment); -})(); +})(); diff --cc src/background/initApp.ts index 4006055,40de858..6fb9ac3 --- a/src/background/initApp.ts +++ b/src/background/initApp.ts @@@ -1,73 -1,20 +1,19 @@@ - "use strict"; - import { app, protocol, BrowserWindow } from "electron"; - import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; - import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer"; - import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; - import * as path from "path"; + import { app } from "electron"; + import { main } from './run'; + import { windowEmitter } from './windowEmitter'; - let win: BrowserWindow | null; + export function initApp(dev: boolean): void { - function createWindow() { - // Create the browser window. - win = new BrowserWindow({ - width: 350, - height: 500, - resizable: true, + let winActive: boolean; - x: 10, - y: 10, - - webPreferences: { - devTools: false, - // 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); - // NOTE uncomment for dev tools on app launch - if (!process.env.IS_TEST) win.webContents.openDevTools(); - } else { - createProtocol("app"); - // Load the index.html when not in development - win.loadURL("app://./index.html"); - } - - win.webContents.on('did-finish-load', () => { - // do stuff once window has finished loading - }) - - win.on("closed", () => { - win = null; - }); - } - - export function initApp(isDev: boolean){ - - // Scheme must be registered before the app is ready - protocol.registerSchemesAsPrivileged([ - { scheme: "app", privileges: { secure: true, standard: true } } - ]); + windowEmitter.on('window-active', (state: boolean) => { + winActive = state; + }); - // This method will be called when Electron has finished - // initialization and is ready to create browser windows. - // Some APIs can only be used after this event occurs. - app.on("ready", async () => { - if (isDev && !process.env.IS_TEST) { - // Install Vue Devtools - try { - await installExtension(VUEJS_DEVTOOLS); - } catch (e) { - console.error("Vue Devtools failed to install:", e.toString()); - } - } - createWindow(); + app.on("ready", () => { + main(); }); // Quit when all windows are closed.