94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
|
|
"use strict";
|
|
|
|
import { app, dialog } from "electron";
|
|
import { createWindow } from './window';
|
|
import { initSession } from './session';
|
|
import { initAudioIO } from './audio';
|
|
import { backgroundMitt } from '@/modules/emitter';
|
|
|
|
let win: boolean;
|
|
|
|
// Listen for window creation.
|
|
backgroundMitt.on('window-active', (state: boolean) => {
|
|
win = state;
|
|
});
|
|
|
|
// Auto updating.
|
|
const { autoUpdater } = require('electron-updater')
|
|
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' }
|
|
|
|
autoUpdater.on('update-available', (info: any) => {
|
|
console.log(`Update available: ${info.version}`)
|
|
})
|
|
|
|
autoUpdater.on('update-downloaded', (info: any) => {
|
|
|
|
const updateDialog = {
|
|
type: 'info',
|
|
buttons: ['Restart', 'Later'],
|
|
title: 'Application Update',
|
|
message: info.version,
|
|
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
|
|
}
|
|
|
|
dialog.showMessageBox(updateDialog).then((returnValue) => {
|
|
if (returnValue.response === 0) autoUpdater.quitAndInstall()
|
|
})
|
|
|
|
})
|
|
|
|
// 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", () => {
|
|
|
|
// Check for updates every 2min.
|
|
setInterval(() => {
|
|
autoUpdater.checkForUpdates()
|
|
}, 5000) // 5s for development.
|
|
|
|
main()
|
|
});
|
|
|
|
// Must keep to ensure app doesn't quit on close.
|
|
app.on("before-quit", () => {
|
|
});
|
|
|
|
// Must keep to ensure app doesn't quit on close.
|
|
app.on("window-all-closed", () => {
|
|
});
|
|
|
|
// 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) {
|
|
process.on("SIGTERM", () => {
|
|
app.quit();
|
|
});
|
|
}
|
|
}
|
|
|