123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 'use strict';
- if (require('electron-squirrel-startup')) return;
- if (handleSquirrelEvent()) {
-
- return;
- }
- const electron = require('electron');
- const app = electron.app;
- const BrowserWindow = electron.BrowserWindow;
- const checkDialout = require("./back-end/checkDialout");
- const ipcHandlers = require('./back-end/ipcHandlers');
- const isProd = process.execPath.search('electron-prebuilt') === -1;
- let mainWindow = null;
- app.on('window-all-closed', () => {
-
-
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
- function launchApp() {
-
- mainWindow.webContents.session.clearCache(() => {
- ipcHandlers();
-
- if (!isProd) {
- mainWindow.loadURL('http://localhost:3000/');
- } else {
- mainWindow.loadURL('file://' + __dirname + '/front-end/index.html');
- }
- });
- }
- function launchLinuxHelper() {
-
- mainWindow.loadURL('file://' + __dirname + '/front-end/linux-help.html');
- }
- app.on('ready', function () {
-
- mainWindow = new BrowserWindow({
- width: 520,
- height: 300,
- 'min-width': 520,
- 'min-height': 300,
- 'accept-first-mouse': true
- });
- if (process.platform === "linux") {
- checkDialout(launchApp, err => {
- if (err.message === checkDialout.ERROR_MESSAGES.USER_NOT_IN_DIALOUT) {
- launchLinuxHelper();
- } else {
-
- launchApp();
- }
- });
- } else {
- launchApp();
- }
-
- if (!isProd) mainWindow.webContents.openDevTools();
-
- mainWindow.on('closed', () => {
-
-
-
- mainWindow = null;
- });
- });
- function handleSquirrelEvent() {
- if (process.argv.length === 1) {
- return false;
- }
- const ChildProcess = require('child_process');
- const path = require('path');
- const appFolder = path.resolve(process.execPath, '..');
- const rootAtomFolder = path.resolve(appFolder, '..');
- const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
- const exeName = path.basename(process.execPath);
- const spawn = function (command, args) {
- let spawnedProcess, error;
- try {
- spawnedProcess = ChildProcess.spawn(command, args, { detached: true });
- } catch (error) { }
- return spawnedProcess;
- };
- const spawnUpdate = function (args) {
- return spawn(updateDotExe, args);
- };
- const squirrelEvent = process.argv[1];
- switch (squirrelEvent) {
- case '--squirrel-install':
- case '--squirrel-updated':
-
-
-
-
-
- spawnUpdate(['--createShortcut', exeName]);
- setTimeout(app.quit, 1000);
- return true;
- case '--squirrel-uninstall':
-
-
-
- spawnUpdate(['--removeShortcut', exeName]);
- setTimeout(app.quit, 1000);
- return true;
- case '--squirrel-obsolete':
-
-
-
- app.quit();
- return true;
- }
- }
|