|
@@ -3,8 +3,6 @@ import { app, BrowserWindow, ipcMain } from 'electron';
|
|
|
import * as path from 'path';
|
|
|
import { format as formatUrl } from 'url';
|
|
|
import { exec } from 'child_process';
|
|
|
-
|
|
|
-
|
|
|
app.allowRendererProcessReuse = false;
|
|
|
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production';
|
|
@@ -12,17 +10,10 @@ const platform = process.platform;
|
|
|
|
|
|
let mainWindow = null, subWindow1 = null, serWindow1;
|
|
|
let random = null;
|
|
|
-
|
|
|
+const version = app.getVersion();
|
|
|
let win1 = null, win2 = null, about = null, esptools = null;
|
|
|
let tmp = null, appIcon = null, menu = null, trayImg = null;
|
|
|
|
|
|
-app.on('web-contents-created', (e, webContents) => {
|
|
|
- webContents.on('new-window', (event, url) => {
|
|
|
- event.preventDefault();
|
|
|
- shell.openExternal(url);
|
|
|
- });
|
|
|
-});
|
|
|
-
|
|
|
// ------------ Keep only one instance of the app running ------------ //
|
|
|
// const singleLock = app.requestSingleInstanceLock();
|
|
|
// !singleLock ? app.quit() : '';
|
|
@@ -33,7 +24,10 @@ if (!gotTheLock) {
|
|
|
app.quit()
|
|
|
} else {
|
|
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
|
|
-
|
|
|
+ if (mainWindow) {
|
|
|
+ if (mainWindow.isMinimized()) mainWindow.restore()
|
|
|
+ mainWindow.focus()
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
// Create myWindow, load the rest of the app, etc...
|
|
@@ -42,7 +36,45 @@ if (!gotTheLock) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const version = app.getVersion();
|
|
|
+// ------------ run auto launch & add ca cert in MacOS ------------ //
|
|
|
+if (platform === 'darwin') {
|
|
|
+ app.dock.hide();
|
|
|
+
|
|
|
+ const sudo = require('sudo-prompt');
|
|
|
+ const AutoLaunch = require('auto-launch');
|
|
|
+ const opts = {
|
|
|
+ name: "AIInnovationEducation",
|
|
|
+ isHidden: false,
|
|
|
+ mac: { useLaunchAgent: true }
|
|
|
+ };
|
|
|
+
|
|
|
+ autoLaunch(opts);
|
|
|
+ exec(`"${path.join(__dirname, '..', 'verifyCert.bash')}"`, (err, stdout) => {
|
|
|
+ if (!err && stdout.indexOf('No') > -1)
|
|
|
+ sudo.exec(
|
|
|
+ `security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "${path.join(__dirname, '..', 'ca.crt')}"`,
|
|
|
+ { name: 'CocoRobo X Uploader' },
|
|
|
+ err => console.log(err)
|
|
|
+ );
|
|
|
+ else if (err)
|
|
|
+ console.error(err);
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Auto launch when computer boot.
|
|
|
+ * @opts {object} Auto lanuch's options
|
|
|
+ * @returns {void} void
|
|
|
+ */
|
|
|
+ function autoLaunch(opts) {
|
|
|
+ const autoLaunch = new AutoLaunch(opts);
|
|
|
+ autoLaunch
|
|
|
+ .isEnabled()
|
|
|
+ .then(enabled => enabled ? '' : autoLaunch.enable())
|
|
|
+ .catch(err => console.error(err));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -81,8 +113,8 @@ ipcMain.on('windowsid', (e, data) => e.returnValue = getWindowsId(data));
|
|
|
|
|
|
// ------------ When app is ready ------------ //
|
|
|
app.on('ready', () => {
|
|
|
- subWindow1 = createSubWindow1();
|
|
|
- serWindow1 = createSubWindow2();
|
|
|
+ createSubWindow1();
|
|
|
+ createSubWindow2();
|
|
|
mainWindow = createMainWindow();
|
|
|
});
|
|
|
|
|
@@ -107,7 +139,7 @@ function createMainWindow() {
|
|
|
}
|
|
|
window.once('ready-to-show', () => window.show());
|
|
|
|
|
|
- window.on('closed', () => window = null);
|
|
|
+ window.on('closed', () => { app.quit() });
|
|
|
|
|
|
window.webContents.on('devtools-opened', () => window.focus());
|
|
|
//window.webContents.openDevTools({ mode: 'undocked' });
|