-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
108 lines (89 loc) · 2.27 KB
/
main.js
File metadata and controls
108 lines (89 loc) · 2.27 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
104
105
106
107
108
const { app, BrowserWindow, ipcMain, globalShortcut, shell } = require('electron');
const Renderer = require('electron/renderer');
const path = require('path');
const Store = require('electron-store').default;
const robot = require('robotjs');
const store = new Store();
let mainWindow;
let isRunning = false;
let intervalId = null;
let keybind = store.get('keybind');
function createWindow() {
mainWindow = new BrowserWindow({
minWidth: 465,
minHeight: 627,
width: 465,
height: 627,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
},
});
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
mainWindow.setMenu(null);
mainWindow.loadFile('index.html');
}
app.whenReady().then(() => {
createWindow();
if (keybind) {
globalShortcut.register(keybind, () => {
if (mainWindow) {
mainWindow.webContents.send('request-interval');
}
});
}
ipcMain.on('send-interval', (event, interval) => {
toggleAutoclicker(interval);
});
ipcMain.on('toggle-autoclicker', (event, interval) => {
toggleAutoclicker(interval);
});
ipcMain.on('set-keybind', (event, newKeybind) => {
if (keybind) {
globalShortcut.unregister(keybind);
}
keybind = newKeybind;
if (newKeybind) {
globalShortcut.register(newKeybind, () => {
toggleAutoclicker();
});
}
store.set('keybind', newKeybind);
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('will-quit', () => {
globalShortcut.unregisterAll();
});
function toggleAutoclicker(interval) {
isRunning = !isRunning;
if (mainWindow) {
mainWindow.webContents.send('autoclicker-status', isRunning);
}
if (isRunning) {
console.log("Autoclicker started. Interval = ",interval);
startClicking(interval);
} else {
console.log("Autoclicker stopped");
stopClicking();
}
}
function startClicking(interval) {
const delay = Number(interval) || 1;
intervalId = setInterval(() => {
robot.mouseClick();
}, delay);
}
function stopClicking() {
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
}