75 lines
1.5 KiB
TypeScript
75 lines
1.5 KiB
TypeScript
|
|
"use strict";
|
|
|
|
import { app } from "electron";
|
|
import { createWindow } from './window';
|
|
import { initSession } from './session';
|
|
import { initAudioIO, stopStream } from './audio';
|
|
import { backgroundMitt } from '@/modules/emitter';
|
|
|
|
let win: boolean;
|
|
|
|
// Listen for window creation.
|
|
backgroundMitt.on('window-active', (state: boolean) => {
|
|
win = state;
|
|
});
|
|
|
|
// Run when electron app is initialized.
|
|
async function main() {
|
|
console.log("MAIN:Initializing Electron App.")
|
|
|
|
// Must wait til window is created.
|
|
await createWindow();
|
|
|
|
// Instantiate socket session with crimata-platorm.
|
|
initSession();
|
|
|
|
// Begin audio stream.
|
|
initAudioIO();
|
|
|
|
}
|
|
|
|
// Root function of app.
|
|
export function initApp(dev: boolean): void {
|
|
|
|
// On initial startup.
|
|
app.on("ready", () => {
|
|
main()
|
|
});
|
|
|
|
// Quit app on window closed.
|
|
app.on("window-all-closed", () => {
|
|
console.log("MAIN:Quitting app.")
|
|
app.quit()
|
|
});
|
|
|
|
// Shutdown audio streams peacefully.
|
|
app.on("before-quit", () => {
|
|
stopStream()
|
|
});
|
|
|
|
// When user clicks app icon (re-open)
|
|
app.on("activate", () => {
|
|
|
|
if (!win) {
|
|
createWindow();
|
|
}
|
|
|
|
});
|
|
|
|
// Exit cleanly on request from parent process in development mode.
|
|
if (dev) {
|
|
if (process.platform === "win32") {
|
|
process.on("message", data => {
|
|
if (data === "graceful-exit") {
|
|
app.quit();
|
|
}
|
|
});
|
|
} else {
|
|
process.on("SIGTERM", () => {
|
|
app.quit();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|