-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
182 lines (145 loc) · 3.72 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var fs = require('fs');
const electron = require('electron');
const log = require('electron-log');
const { dialog } = require('electron');
require('@electron/remote/main').initialize()
log.info("starte watchdog");
global.sharedObject = {
prop1: process.argv
}
if (fs.existsSync("watchdog")) {
eval(fs.readFileSync('watchdog/assets/js/settings.js') + '');
} else {
eval(fs.readFileSync('assets/js/settings.js') + '');
}
// dafür sorgen das die devtools angezeigt werden
require('electron-debug')({
showDevTools: false,
isEnabled: true
});
const app = electron.app
const Tray = electron.Tray
const Menu = electron.Menu
const { ipcMain } = require('electron')
const BrowserWindow = electron.BrowserWindow
const path = require('path')
const url = require('url')
let mainWindow
let tray
function createWindow() {
tray = new Tray(__dirname + '/images/abas.ico');
tray.setToolTip('abas-watchdog');
mainWindow = new BrowserWindow({
icon: __dirname + '/images/abas.ico',
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false
}
});
mainWindow.setMenu(null);
//mainWindow.openDevTools();
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
var force_quit = false;
var menu = [];
menu.push({
label: 'show',
type: 'normal',
click: function() {
mainWindow.show();
}
});
menu.push({
label: 'settings',
type: 'normal',
click: function() {
mainWindow.webContents.send('message', 'ping');
}
});
if (settings.allow_devtools) {
menu.push({
label: 'devtools',
type: 'normal',
click: function() {
mainWindow.webContents.openDevTools();
}
});
}
if (settings.allow_quit) {
menu.push({
type: 'separator'
});
menu.push({
label: 'quit',
type: 'normal',
click: function() {
force_quit = true;
mainWindow.close();
}
});
}
const contextMenu = Menu.buildFromTemplate(menu);
tray.setContextMenu(contextMenu);
tray.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show()
});
mainWindow.on('show', () => {
//tray.setHighlightMode('always');
});
mainWindow.on('hide', () => {
//tray.setHighlightMode('never');
});
// Hauptfenster wird nicht geschlossen nur versteckt
mainWindow.on('close', function(e) {
if (!force_quit) {
e.preventDefault();
mainWindow.hide();
}
});
mainWindow.hide();
require("@electron/remote/main").enable(mainWindow.webContents)
}
/*
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
//if (!mainWindow.isVisible()) mainWindow.show();
//if (mainWindow.isMinimized()) mainWindow.restore();
//mainWindow.focus();
}
});
*/
var shouldQuit = !app.requestSingleInstanceLock();
if (shouldQuit) {
app.quit();
return;
}
app.on('ready', createWindow)
app.on('window-all-closed', function() {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function() {
if (mainWindow === null) {
createWindow()
}
})
process.on("uncaughtException", (err) => {
log.error(err);
const messageBoxOptions = {
type: "error",
title: "Fehler",
message: err
};
dialog.showMessageBoxSync(messageBoxOptions);
// I believe it used to be the case that doing a "throw err;" here would
// terminate the process, but now it appears that you have to use's Electron's
// app module to exit (process.exit(1) seems to not terminate the process)
app.exit(1);
});