@@ -19,17 +19,95 @@ function pathToFileURL(filePath) {
1919 return `file:///${ formattedPath } ` ;
2020}
2121
22+ // Create configuration with proper isDev detection and build config
23+ const isDev = ! app . isPackaged ;
24+ const config = createConfig ( isDev , buildConfig ) ;
25+
26+ // Set up IPC handlers early to ensure they're registered before window creation
27+ let win ;
28+ let currentStatus = 'Playing Sploder' ;
29+
30+ // Set up IPC handlers for window control
31+ ipcMain . handle ( 'window-minimize' , ( event ) => {
32+ const webContents = event . sender ;
33+ const browserWindow = BrowserWindow . fromWebContents ( webContents ) ;
34+
35+ if ( browserWindow ) {
36+ browserWindow . minimize ( ) ;
37+ return true ;
38+ }
39+ return false ;
40+ } ) ;
41+
42+ ipcMain . handle ( 'window-maximize' , ( event ) => {
43+ const webContents = event . sender ;
44+ const browserWindow = BrowserWindow . fromWebContents ( webContents ) ;
45+
46+ if ( browserWindow ) {
47+ if ( browserWindow . isMaximized ( ) ) {
48+ browserWindow . unmaximize ( ) ;
49+ return false ;
50+ } else {
51+ browserWindow . maximize ( ) ;
52+ return true ;
53+ }
54+ }
55+ return false ;
56+ } ) ;
57+
58+ ipcMain . handle ( 'window-close' , ( event ) => {
59+ const webContents = event . sender ;
60+ const browserWindow = BrowserWindow . fromWebContents ( webContents ) ;
61+
62+ if ( browserWindow ) {
63+ browserWindow . close ( ) ;
64+ return true ;
65+ }
66+ return false ;
67+ } ) ;
68+
69+ ipcMain . handle ( 'window-is-maximized' , ( event ) => {
70+ const webContents = event . sender ;
71+ const browserWindow = BrowserWindow . fromWebContents ( webContents ) ;
72+
73+ if ( browserWindow ) {
74+ return browserWindow . isMaximized ( ) ;
75+ }
76+ return false ;
77+ } ) ;
78+
79+ ipcMain . handle ( 'get-rpc-info' , async ( event ) => {
80+ if ( ! win ) return '' ;
81+ try {
82+ const status = await win . webContents . executeJavaScript ( 'window.rpcinfo || ""' ) ;
83+ currentStatus = status || 'Playing Sploder' ;
84+ return status ;
85+ } catch ( error ) {
86+ return '' ;
87+ }
88+ } ) ;
89+
90+ ipcMain . handle ( 'update-rpc-status' , ( event , status ) => {
91+ if ( status ) {
92+ currentStatus = status ;
93+ }
94+ return currentStatus ;
95+ } ) ;
96+
97+ ipcMain . handle ( 'get-config' , ( event ) => {
98+ return config ;
99+ } ) ;
100+
101+ ipcMain . handle ( 'get-url' , ( event , endpoint ) => {
102+ return config . getUrl ( endpoint ) ;
103+ } ) ;
104+
22105// If not on windows, disable RPC
23106let DiscordRPC ;
24107if ( process . platform == "win32" ) {
25108 DiscordRPC = require ( 'discord-rpc' ) ;
26109}
27- let win ;
28110let pluginName ;
29- const isDev = ! app . isPackaged ;
30-
31- // Create configuration with proper isDev detection and build config
32- const config = createConfig ( isDev , buildConfig ) ;
33111
34112let rendererPath , preloadPath ;
35113if ( isDev ) {
@@ -233,7 +311,7 @@ app.on("window-all-closed", function () {
233311} ) ;
234312
235313
236- if ( process . platform == "win32" ) {
314+ // if (process.platform == "win32") {
237315 const clientId = '915116210570539058' ;
238316 const rpc = new DiscordRPC . Client ( { transport : 'ipc' } ) ;
239317 const startTimestamp = new Date ( ) ;
@@ -242,12 +320,11 @@ if (process.platform == "win32") {
242320 if ( ! rpc || ! win ) {
243321 return ;
244322 }
245- const boops = await win . webContents . executeJavaScript ( 'rpcinfo' ) ;
246323 rpc . setActivity ( {
247- details : ` ${ boops } ` ,
324+ details : currentStatus ,
248325 startTimestamp,
249326 largeImageKey : 'icon' ,
250- largeImageText : ` ${ boops } `
327+ largeImageText : currentStatus
251328 } ) ;
252329 }
253330
@@ -259,7 +336,7 @@ if (process.platform == "win32") {
259336 } ) ;
260337
261338 rpc . login ( { clientId } ) . catch ( ) ;
262- }
339+ // }
263340
264341// Set up IPC handlers for window control
265342ipcMain . handle ( 'window-minimize' , ( event ) => {
@@ -317,12 +394,22 @@ ipcMain.handle('window-is-maximized', (event) => {
317394ipcMain . handle ( 'get-rpc-info' , async ( event ) => {
318395 if ( ! win ) return '' ;
319396 try {
320- return await win . webContents . executeJavaScript ( 'rpcinfo' ) ;
397+ const status = await win . webContents . executeJavaScript ( 'window.rpcinfo || ""' ) ;
398+ currentStatus = status || 'Playing Sploder' ;
399+ return status ;
321400 } catch ( error ) {
322401 return '' ;
323402 }
324403} ) ;
325404
405+ // Handler to update RPC status from renderer
406+ ipcMain . handle ( 'update-rpc-status' , ( event , status ) => {
407+ if ( status ) {
408+ currentStatus = status ;
409+ }
410+ return currentStatus ;
411+ } ) ;
412+
326413// Handler to provide application configuration to the renderer
327414ipcMain . handle ( 'get-config' , ( event ) => {
328415 return config ;
0 commit comments