-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
86 lines (69 loc) · 2.34 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
const { app, BrowserWindow, globalShortcut, screen } = require('electron');
const path = require('path');
const { exec } = require('child_process');
const os = require('os');
const hs = os.hostname();
let user = 'user';
exec('echo $(ldapsearch uid=$USER | grep cn )', (e, out, err) => {
user = out.slice(4);
});
let mainWindow;
const createWindow = async () => {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
mainWindow = new BrowserWindow({
height: height,
width: width,
fullscreen: true,
frame: false,
closable: false,
movable: false,
backgroundColor: '#000000',
webPreferences: {
devTools: false,
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
},
kiosk: true
});
mainWindow.loadURL('http://localhost:3000');
globalShortcut.register('Control+Alt+=', () => {
mainWindow.closable = true;
mainWindow.close();
app.quit();
});
globalShortcut.register('CommandOrControl+R', () => {});
globalShortcut.register('CommandOrControl+Tab', () => {});
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.send('message-from-main', [user, hs.split('.')[0]]);
mainWindow.webContents.on('before-input-event', (event, input) => {
if (input.type === 'keyDown') {
const disabledKeys = ['=', '-'];
if ((input.control || input.meta) && disabledKeys.includes(input.key)) {
event.preventDefault();
}
if (input.control && input.key === ',') {
mainWindow.webContents.openDevTools();
}
}
});
});
mainWindow.on('did-fail-load', (event, errorCode, errorDescription) => {
console.error('Failed to load URL:', errorDescription);
});
mainWindow.on('unresponsive', () => {
console.error('Window is unresponsive');
});
mainWindow.on('crashed', () => {
console.error('Window has crashed');
});
};
app.whenReady().then(() => {
createWindow();
});
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});