This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.js
141 lines (118 loc) · 3.25 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const path = require('path');
const url = require('url');
const { app, BrowserWindow, globalShortcut } = require('electron');
const open = require('open');
const { checkForUpdates } = require('./updater');
const Sentry = require('@sentry/electron');
app.commandLine.appendSwitch('disable-http-cache');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
/** @type {BrowserWindow} */
let mainWindow;
let isDev = false;
if (process.env.NODE_ENV && process.env.NODE_ENV === 'development') {
isDev = true;
}
require('@electron/remote/main').initialize();
if (!isDev) {
if (require('electron-squirrel-startup')) {
app.quit();
process.exit(0);
}
app.whenReady().then(() => {
globalShortcut.register('CommandOrControl+R', () => {
console.log('CommandOrControl+R is pressed: Shortcut Disabled');
});
globalShortcut.register('F5', () => {
console.log('F5 is pressed: Shortcut Disabled');
});
});
//! Uncomment to prevent program running after install
// if (process.platform === 'win32') {
// var cmd = process.argv[1];
// if (cmd === '--squirrel-firstrun') {
// app.quit();
// process.exit(0);
// }
// }
Sentry.init({
dsn: 'https://[email protected]/5431856',
environment: process.env.NODE_ENV,
enableNative: true,
debug: true,
attachStacktrace: true,
});
}
function createMainWindow() {
mainWindow = new BrowserWindow({
minWidth: 900,
minHeight: 700,
width: 1000,
height: 750,
frame: false,
darkTheme: true,
backgroundColor: '#1b1b31',
titleBarStyle: 'hidden',
show: false,
icon: `${__dirname}/assets/icon.ico`,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
webSecurity: false,
preload: path.join(__dirname, 'src', 'helpers', 'Sentry', 'sentry.js'),
devTools: true,
worldSafeExecuteJavaScript: true,
allowRunningInsecureContent: false,
},
});
let indexPath;
if (isDev && process.argv.indexOf('--noDevServer') === -1) {
indexPath = url.format({
protocol: 'http:',
host: 'localhost:8080',
pathname: 'index.html',
slashes: true,
});
} else {
indexPath = url.format({
protocol: 'file:',
pathname: path.join(__dirname, 'dist', 'index.html'),
slashes: true,
});
}
// open new window links in the default browser
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
open(url);
});
require('@electron/remote/main').enable(mainWindow.webContents);
mainWindow.menuBarVisible = false;
mainWindow.loadURL(indexPath);
if (!isDev) {
checkForUpdates(mainWindow);
}
// Don't show until we are ready and loaded
mainWindow.once('ready-to-show', () => {
mainWindow.show();
// Open devtools if dev
if (isDev) {
mainWindow.webContents.openDevTools();
}
});
mainWindow.on('closed', () => (mainWindow = null));
}
app.on('ready', () => {
createMainWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createMainWindow();
}
});
// Stop error
app.allowRendererProcessReuse = true;