-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
102 lines (96 loc) · 2.8 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
var { app, BrowserWindow, screen, ipcMain } = require('electron');
var mainWindow = null;
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
app.allowRendererProcessReuse = false;
app.commandLine.appendSwitch("disable-background-timer-throttling");
app.commandLine.appendSwitch("disable-backgrounding-occluded-windows");
app.commandLine.appendSwitch("disable-renderer-backgrounding");
app.on('ready', function() {
mainWindow = new BrowserWindow({
width: 9999,
height: 9999,
transparent: true,
backgroundColor: "#00000000",
resizable: false,
frame: false,
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
}
});
const os = require("os")
function getNativeWindowHandle_Int(win) {
let hbuf = win.getNativeWindowHandle()
if (os.endianness() == "LE")
return hbuf.readInt32LE()
else
return hbuf.readInt32BE()
}
mainWindow.setMenu(null)
mainWindow.setMaximizable(false)
mainWindow.setResizable(false)
mainWindow.loadURL('file://' + __dirname + '/index.html');
// mainWindow.openDevTools({mode: 'detach'});
mainWindow.setAlwaysOnTop(true);
if(process.platform === "win32")
mainWindow .hookWindowMessage(278, function(e) {
mainWindow.blur();
mainWindow.focus();
mainWindow.setEnabled(false);
setTimeout(() => {
mainWindow.setEnabled(true);
}, 100);
return true;
});
let windowOnReady = false;
let requireLevel = false;
let processIf = undefined;
mainWindow.on('closed', function() {
mainWindow = null;
});
ipcMain.on('window-close', function() {
mainWindow.close();
if(processIf !== undefined)
processIf.kill(0);
});
const superLevel = () => {
if(process.platform === "win32"){
const handleId = getNativeWindowHandle_Int(mainWindow);
processIf = require('child_process').exec(`windowTop\\win_x64.exe ${handleId}`, {
windowsHide: true
}, (error, stdout) => {
console.log("Windows API monitor quited (error: " + error + ", stdout: " + stdout + ")");
});
}
else{
mainWindow.setAlwaysOnTop(true, "screen-saver");
mainWindow.setVisibleOnAllWorkspaces(true);
}
};
ipcMain.on('window-super-top', function() {
if(windowOnReady === true)
superLevel();
else
requireLevel = true;
});
mainWindow.on('maximize', function () {
// mainWindow.webContents.send('main-window-max');
})
mainWindow.on('unmaximize', function () {
// mainWindow.webContents.send('main-window-unmax');
})
mainWindow.on('ready-to-show', function () {
mainWindow.show();
windowOnReady = true;
if(requireLevel === true){
superLevel();
requireLevel = false;
}
})
});