-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
54 lines (45 loc) · 1.43 KB
/
index.mjs
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
/* Copyright (c) 2024 Zenin Easa Panthakkalakath */
import { app, BrowserWindow, screen, ipcMain } from 'electron';
import robot from '@meadowsjared/robotjs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { updateElectronApp } from 'update-electron-app';
updateElectronApp();
const __dirname = dirname(fileURLToPath(import.meta.url));
function createWindow() {
const mainWindow = new BrowserWindow({
width: screen.getPrimaryDisplay().workAreaSize.width,
height: screen.getPrimaryDisplay().workAreaSize.height,
frame: false,
transparent: true,
title: 'Joycast',
webPreferences: {
preload: join(__dirname, 'preload.mjs'),
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadFile('DesktopApp/index.html');
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
app.quit();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// Information regarding joystick event is communicated here
ipcMain.handle('robotKeyToggleAction', (_event, action) => {
robot.keyToggle(action.button, action.upOrDown);
});
ipcMain.handle('robotKeyTapAction', (_event, button) => {
robot.keyTap(button);
try {
robot.keyTap(button);
return true;
} catch (error) {
return false;
}
});