generated from sindresorhus/electron-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
110 lines (92 loc) · 2.46 KB
/
index.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
'use strict';
const path = require('path');
const {app, BrowserWindow, Menu} = require('electron');
/// const {autoUpdater} = require('electron-updater');
const {is} = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const contextMenu = require('electron-context-menu');
const {ipcMain} = require('electron');
const isDev = require("electron-is-dev");
const psList = require('ps-list');
const fkill = require('fkill');
unhandled();
debug();
contextMenu();
// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.company.AppName');
// Uncomment this before publishing your first version.
// It's commented out as it throws an error if there are no published versions.
// if (!is.development) {
// const FOUR_HOURS = 1000 * 60 * 60 * 4;
// setInterval(() => {
// autoUpdater.checkForUpdates();
// }, FOUR_HOURS);
//
// autoUpdater.checkForUpdates();
// }
// Prevent window from being garbage collected
let mainWindow;
const createMainWindow = async () => {
const win = new BrowserWindow({
titleBarStyle: 'hidden',
show: false,
width: 600,
height: 400,
webPreferences: {
nodeIntegration: true
}
});
win.on('ready-to-show', () => {
win.show();
});
win.on('closed', () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});
await win.loadURL(
isDev
? "http://localhost:3000"
: `file://${path.join(__dirname, "./build/index.html")}`
);
return win;
};
// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
app.on('window-all-closed', () => {
if (!is.macos) {
app.quit();
}
});
app.on('activate', async () => {
if (!mainWindow) {
mainWindow = await createMainWindow();
}
});
(async () => {
await app.whenReady();
mainWindow = await createMainWindow();
ipcMain.on('request-tasklist-message', async (event) => {
const processList = await psList();
event.reply('request-tasklist-reply', processList)
});
ipcMain.on('kill-process', async (event, arg) => {
try {
await fkill(arg);
event.reply('kill-process-success');
} catch (e) {
event.reply('kill-process-error');
}
});
})();