-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
103 lines (89 loc) · 2.67 KB
/
main.js
File metadata and controls
103 lines (89 loc) · 2.67 KB
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
const { executeDwm, redraw } = require('./build/Release/micaElectron');
// # function to remove the frame of window
function removeFrame(window) {
const HWND = window.getNativeWindowHandle()["readInt32LE"]();
const bounds = window.getBounds();
window.hide();
redraw(HWND, bounds.x, bounds.y, bounds.width, bounds.height, 0x0020);
window.show();
}
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
// # Enable transparent
app.commandLine.appendSwitch("enable-transparent-visuals");
app.on('ready', () => {
// @ Create a browserwindow
const mainWindow = new BrowserWindow({
width: 980,
height: 740,
minWidth: 980,
minHeight: 740,
frame: false,
titlebarStyle: 'hidden',
autoHideMenuBar: true,
backgroundColor: '#000000ff', // Transparent background
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, './files/class/preload.js')
},
});
// @ Get the HWND
const HWND = mainWindow.getNativeWindowHandle()["readInt32LE"]();
let params = 2;
let value = 1;
// @Load file
// mainWindow.webContents.openDevTools()
mainWindow.loadFile(path.join(__dirname, 'files', 'index.html'));
// @show window when file loaded
mainWindow.webContents.once('dom-ready', () => {
mainWindow.show();
});
let hasFrame = false; // false to remvoe the window titlebar
let frameRemoved = false;
mainWindow.on('show', () => {
if (!frameRemoved) {
frameRemoved = true;
if (!hasFrame) {
removeFrame(mainWindow); // remove the frame when window is shown
setInterval(() => executeDwm(HWND, params, value), 60); // refresh effect
}
// execute effect when window is shown
executeDwm(HWND, params, value);
}
});
// @ Minimize app
ipcMain.on('minimizeApp', () => {
//console.log('Clicked on minimizeBtn')
mainWindow.minimize()
})
// @ Maximize Restore app
ipcMain.on('maximizeRestoreApp', () => {
if (mainWindow.isMaximized()) {
//console.log('Clicked on maxResBtn and the window was restored')
mainWindow.restore()
} else {
mainWindow.maximize()
//console.log('Clicked on maxResBtn and the window was maximized')
}
})
// @ Check if is maximized
mainWindow.on('maximize', () => {
mainWindow.webContents.send('isMaximized')
})
// @ Check if is restored
mainWindow.on('unmaximize', () => {
mainWindow.webContents.send('isRestored')
})
// @ Close app
ipcMain.on('closeApp', () => {
//console.log('Clicked on closeBtn')
mainWindow.close()
})
const iconName = path.join(__dirname, './files/img/iconForDragAndDrop.png');
ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({
file: path.join(__dirname, filePath),
icon: iconName,
})
})
});