|
1 | | -const { app, globalShortcut, BrowserWindow, session } = require('electron'); |
2 | | -const path = require('path'); |
3 | | -const { switchFullscreenState } = require('./windowManager.js'); |
| 1 | +const { app, BrowserWindow } = require('electron'); |
4 | 2 |
|
5 | | -var homePage = 'https://robotics-sensors.github.io'; |
6 | | -var userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.3'; |
| 3 | +// Application configuration |
| 4 | +const appConfig = { |
| 5 | + homePageURL: 'https://robotics-sensors.github.io', |
| 6 | + userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.3', |
| 7 | +}; |
7 | 8 |
|
8 | | -console.log('Using user agent: ' + userAgent); |
9 | | -console.log('Process arguments: ' + process.argv); |
| 9 | +console.log(`Using user agent: ${appConfig.userAgent}`); |
| 10 | +console.log(`Process arguments: ${process.argv}`); |
10 | 11 |
|
| 12 | +// Configure Electron command line switches |
11 | 13 | app.commandLine.appendSwitch('enable-features', 'VaapiVideoDecoder,WaylandWindowDecorations,RawDraw'); |
12 | | - |
13 | | -app.commandLine.appendSwitch( |
14 | | - 'disable-features', |
15 | | - 'UseChromeOSDirectVideoDecoder' |
16 | | -); |
| 14 | +app.commandLine.appendSwitch('disable-features', 'UseChromeOSDirectVideoDecoder'); |
17 | 15 | app.commandLine.appendSwitch('enable-accelerated-mjpeg-decode'); |
18 | | -app.commandLine.appendSwitch('enable-accelerated-video'); |
19 | | -app.commandLine.appendSwitch('ignore-gpu-blocklist'); |
20 | | -app.commandLine.appendSwitch('enable-native-gpu-memory-buffers'); |
21 | | -app.commandLine.appendSwitch('enable-gpu-rasterization'); |
22 | | -app.commandLine.appendSwitch('enable-zero-copy'); |
23 | | -app.commandLine.appendSwitch('enable-gpu-memory-buffer-video-frames'); |
24 | | -app.commandLine.appendSwitch('use-gl'); |
25 | 16 |
|
26 | | -async function createWindow() { |
| 17 | +// Create the main application window |
| 18 | +async function createMainWindow() { |
27 | 19 | const mainWindow = new BrowserWindow({ |
28 | 20 | fullscreenable: true, |
29 | 21 | webPreferences: { |
30 | | - preload: path.join(__dirname, 'preload.js'), |
31 | 22 | contextIsolation: false, |
32 | | - userAgent: userAgent, |
| 23 | + userAgent: appConfig.userAgent, |
33 | 24 | }, |
34 | 25 | }); |
35 | 26 |
|
36 | | - if (process.argv.includes('--direct-start')) { |
37 | | - mainWindow.loadURL(homePage); |
38 | | - } else { |
39 | | - mainWindow.loadURL(homePage); |
40 | | - } |
41 | | - |
| 27 | + await mainWindow.loadURL(appConfig.homePageURL); |
| 28 | + return mainWindow; |
42 | 29 | } |
43 | 30 |
|
| 31 | +// Initialize the application |
44 | 32 | app.whenReady().then(async () => { |
45 | | - createWindow(); |
| 33 | + await createMainWindow(); |
46 | 34 |
|
47 | | - app.on('activate', async function() { |
| 35 | + app.on('activate', async () => { |
48 | 36 | if (BrowserWindow.getAllWindows().length === 0) { |
49 | | - createWindow(); |
| 37 | + await createMainWindow(); |
50 | 38 | } |
51 | 39 | }); |
52 | 40 |
|
53 | | - const { globalShortcut, BrowserWindow } = require('electron'); |
54 | | - |
55 | | - // Register global shortcuts |
56 | | - const window = BrowserWindow.getAllWindows()[0]; |
57 | | - globalShortcut.register('Super+F', async () => { |
58 | | - switchFullscreenState(window); |
59 | | - }); |
60 | | - |
61 | | - globalShortcut.register('F11', async () => { |
62 | | - switchFullscreenState(window); |
63 | | - }); |
64 | | - |
65 | | - globalShortcut.register('Alt+F4', async () => { |
66 | | - app.quit(); |
67 | | - }); |
68 | | - |
69 | | - globalShortcut.register('Alt+Home', async () => { |
70 | | - window.loadURL(homePage); |
71 | | - }); |
72 | | - |
73 | | - globalShortcut.register('F4', async () => { |
74 | | - app.quit(); |
75 | | - }); |
76 | | - |
77 | | - globalShortcut.register('Control+Shift+I', () => { |
78 | | - window.webContents.toggleDevTools(); |
79 | | - }); |
80 | | - |
81 | | - globalShortcut.register('Esc', async () => { |
82 | | - // Handle 'Esc' key press event |
83 | | - window.webContents.sendInputEvent({ |
84 | | - type: 'keyDown', |
85 | | - keyCode: 'Esc' |
86 | | - }); |
87 | | - window.webContents.sendInputEvent({ |
88 | | - type: 'char', |
89 | | - keyCode: 'Esc' |
90 | | - }); |
91 | | - window.webContents.sendInputEvent({ |
92 | | - type: 'keyUp', |
93 | | - keyCode: 'Esc' |
94 | | - }); |
95 | | - }); |
96 | | -}); |
97 | | - |
98 | | -app.on('browser-window-created', async function(e, window) { |
99 | | - window.setBackgroundColor('#1A1D1F'); |
100 | | - window.setMenu(null); |
101 | | - |
102 | | - window.webContents.setUserAgent(userAgent); |
103 | | - |
104 | | - window.webContents.on('new-window', (event, url) => { |
105 | | - event.preventDefault(); |
106 | | - BrowserWindow.getAllWindows()[0].loadURL(url); |
| 41 | + // Quit the application when all windows are closed |
| 42 | + app.on('window-all-closed', async () => { |
| 43 | + if (process.platform !== 'darwin') { |
| 44 | + app.quit(); |
| 45 | + } |
107 | 46 | }); |
108 | | - |
109 | | -}); |
110 | | - |
111 | | -app.on('will-quit', async () => { |
112 | | - globalShortcut.unregisterAll(); |
113 | | -}); |
114 | | - |
115 | | -app.on('window-all-closed', async function() { |
116 | | - if (process.platform !== 'darwin') { |
117 | | - app.quit(); |
118 | | - } |
119 | 47 | }); |
0 commit comments