2020-04-30 17:48:53 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-08-03 17:59:15 +02:00
|
|
|
import { app, BrowserWindow, /* session, */ nativeImage, Menu } from 'electron';
|
2020-04-30 17:48:53 +02:00
|
|
|
import * as path from 'path';
|
2021-01-25 09:28:57 +01:00
|
|
|
import Store from 'electron-store';
|
2021-09-21 11:16:07 +02:00
|
|
|
import * as remoteMain from '@electron/remote/main';
|
2021-01-25 09:28:57 +01:00
|
|
|
|
2020-05-14 15:21:57 +02:00
|
|
|
import ipcHandlers from './ipc-handlers';
|
2020-05-11 18:05:34 +02:00
|
|
|
|
2021-09-21 11:16:07 +02:00
|
|
|
// remoteMain.initialize();
|
2021-01-25 09:28:57 +01:00
|
|
|
Store.initRenderer();
|
|
|
|
|
2020-06-14 19:02:07 +02:00
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production';
|
2020-09-15 14:44:29 +02:00
|
|
|
const gotTheLock = app.requestSingleInstanceLock();
|
|
|
|
|
2020-04-30 17:48:53 +02:00
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
|
|
|
|
|
|
|
// global reference to mainWindow (necessary to prevent window from being garbage collected)
|
|
|
|
let mainWindow;
|
|
|
|
|
2020-07-29 15:56:29 +02:00
|
|
|
async function createMainWindow () {
|
2020-05-31 17:56:33 +02:00
|
|
|
const icon = require('../renderer/images/logo-32.png');
|
2020-04-30 17:48:53 +02:00
|
|
|
const window = new BrowserWindow({
|
2020-07-31 15:45:32 +02:00
|
|
|
width: 1024,
|
|
|
|
height: 800,
|
2020-05-30 12:54:05 +02:00
|
|
|
minWidth: 900,
|
2020-07-31 15:45:32 +02:00
|
|
|
minHeight: 550,
|
2020-05-07 17:45:04 +02:00
|
|
|
title: 'Antares',
|
|
|
|
autoHideMenuBar: true,
|
2020-05-31 17:56:33 +02:00
|
|
|
icon: nativeImage.createFromDataURL(icon.default),
|
2020-04-30 17:48:53 +02:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
2021-04-26 10:07:47 +02:00
|
|
|
contextIsolation: false,
|
2020-07-29 15:56:29 +02:00
|
|
|
'web-security': false,
|
2020-07-31 18:16:28 +02:00
|
|
|
spellcheck: false
|
2020-06-02 19:13:57 +02:00
|
|
|
},
|
|
|
|
frame: false,
|
|
|
|
backgroundColor: '#1d1d1d'
|
2020-04-30 17:48:53 +02:00
|
|
|
});
|
|
|
|
|
2021-09-21 11:16:07 +02:00
|
|
|
remoteMain.enable(window.webContents);
|
|
|
|
|
2021-04-26 10:07:47 +02:00
|
|
|
try {
|
2021-06-24 21:49:46 +02:00
|
|
|
if (isDevelopment) { //
|
2021-04-26 10:07:47 +02:00
|
|
|
await window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`);
|
|
|
|
|
2021-06-24 21:49:46 +02:00
|
|
|
// const { default: installExtension, VUEJS3_DEVTOOLS } = require('electron-devtools-installer');
|
2021-04-26 10:07:47 +02:00
|
|
|
|
2021-06-24 21:49:46 +02:00
|
|
|
// const oldDevToolsID = session.defaultSession.getAllExtensions().find(ext => ext.name === 'Vue.js devtools').id;
|
|
|
|
// session.defaultSession.removeExtension(oldDevToolsID);
|
|
|
|
// const toolName = await installExtension(VUEJS3_DEVTOOLS);
|
|
|
|
// console.log(toolName, 'installed');
|
2021-04-26 10:07:47 +02:00
|
|
|
}
|
2021-06-18 21:08:21 +02:00
|
|
|
else
|
|
|
|
await window.loadURL(new URL(`file:///${path.join(__dirname, 'index.html')}`).href);
|
2020-04-30 17:48:53 +02:00
|
|
|
}
|
2021-04-26 10:07:47 +02:00
|
|
|
catch (err) {
|
|
|
|
console.log(err);
|
2020-07-29 15:56:29 +02:00
|
|
|
}
|
2020-04-30 17:48:53 +02:00
|
|
|
|
|
|
|
window.on('closed', () => {
|
|
|
|
mainWindow = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
window.webContents.on('devtools-opened', () => {
|
|
|
|
window.focus();
|
|
|
|
setImmediate(() => {
|
|
|
|
window.focus();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return window;
|
|
|
|
};
|
|
|
|
|
2020-09-15 14:44:29 +02:00
|
|
|
if (!gotTheLock)
|
|
|
|
app.quit();
|
|
|
|
else {
|
2021-04-26 10:07:47 +02:00
|
|
|
require('@electron/remote/main').initialize();
|
|
|
|
|
2020-09-15 14:44:29 +02:00
|
|
|
// Initialize ipcHandlers
|
|
|
|
ipcHandlers();
|
2020-07-30 19:12:29 +02:00
|
|
|
|
2020-09-15 14:44:29 +02:00
|
|
|
// quit application when all windows are closed
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
// on macOS it is common for applications to stay open until the user explicitly quits
|
|
|
|
if (process.platform !== 'darwin')
|
|
|
|
app.quit();
|
|
|
|
});
|
2020-04-30 17:48:53 +02:00
|
|
|
|
2021-04-26 10:07:47 +02:00
|
|
|
app.on('activate', async () => {
|
2020-09-15 14:44:29 +02:00
|
|
|
// on macOS it is common to re-create a window even after all windows have been closed
|
2021-04-26 10:07:47 +02:00
|
|
|
if (mainWindow === null) {
|
|
|
|
mainWindow = await createMainWindow();
|
2021-04-30 14:14:01 +02:00
|
|
|
if (isDevelopment)
|
|
|
|
mainWindow.webContents.openDevTools();
|
2021-04-26 10:07:47 +02:00
|
|
|
}
|
2020-09-15 14:44:29 +02:00
|
|
|
});
|
2020-04-30 17:48:53 +02:00
|
|
|
|
2020-09-15 14:44:29 +02:00
|
|
|
// create main BrowserWindow when electron is ready
|
2020-12-18 18:44:32 +01:00
|
|
|
app.on('ready', async () => {
|
2021-04-26 10:07:47 +02:00
|
|
|
mainWindow = await createMainWindow();
|
2021-08-03 17:59:15 +02:00
|
|
|
Menu.setApplicationMenu(null);
|
2021-09-15 15:31:57 +02:00
|
|
|
|
2021-04-30 14:14:01 +02:00
|
|
|
if (isDevelopment)
|
|
|
|
mainWindow.webContents.openDevTools();
|
2021-09-15 15:31:57 +02:00
|
|
|
|
|
|
|
process.on('uncaughtException', error => {
|
|
|
|
mainWindow.webContents.send('unhandled-exception', error);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('unhandledRejection', error => {
|
|
|
|
mainWindow.webContents.send('unhandled-exception', error);
|
|
|
|
});
|
2020-09-15 14:44:29 +02:00
|
|
|
});
|
|
|
|
}
|