+ /*
+ * 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);
-})();
+})();
-
"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.