@@ -14,6 +14,7 @@ let systemUsageData = {};
14
14
let debugLogs = [ ] ;
15
15
let devToolsOpenedOnDebugMode = false ;
16
16
17
+ if ( ! fs . readdirSync ( parent . process . resourcesPath ) . includes ( "appStartupCode" ) ) fs . mkdirSync ( path . join ( process . resourcesPath , "appStartupCode" ) ) ;
17
18
if ( ( JSON . parse ( localStorage . getItem ( "settings" ) ) || { } ) . debugMode ) document . getElementById ( "menuBar" ) . children [ 0 ] . children [ 4 ] . style . display = "block" ;
18
19
19
20
document . styleSheets [ 2 ] . media . appendMedium ( "(prefers-color-scheme: " + ( ( ( JSON . parse ( localStorage . getItem ( "settings" ) ) || { } ) . darkMode ?? false ) ? "dark" : "white" ) + ")" ) ;
@@ -172,7 +173,13 @@ ipcRenderer.on("executeScript", (_, { roomId, password, scriptContent } = {}) =>
172
173
} ) ;
173
174
return pythonProcess ;
174
175
} ,
175
- executeInMainProcess : ( func ) => ipcRenderer . send ( "executeDebugCode" , "(" + func . toString ( ) + ")();" )
176
+ executeInMainProcess : ( func ) => ipcRenderer . send ( "executeDebugCode" , "(" + func . toString ( ) + ")();" ) ,
177
+ createAppStartupCodeFile : ( func ) => {
178
+ let appStartupCodeFileId = crypto . randomBytes ( 8 ) . toString ( "hex" ) ;
179
+ fs . writeFileSync ( path . join ( process . resourcesPath , "appStartupCode/" + appStartupCodeFileId + ".js" ) , func . toString ( ) , "utf8" ) ;
180
+ return appStartupCodeFileId ;
181
+ } ,
182
+ deleteAppStartupCodeFile : ( appStartupCodeFileId ) => fs . unlinkSync ( path . join ( process . resourcesPath , "appStartupCode/" + appStartupCodeFileId + ".js" ) )
176
183
} ) {
177
184
eval ( "(async () => {" + scriptContent + "})();" ) ;
178
185
} ;
@@ -355,6 +362,59 @@ ipcRenderer.on("debugLog", (_, debugLog) => {
355
362
} ) ;
356
363
} ) ;
357
364
365
+ fs . readdirSync ( path . join ( process . resourcesPath , "appStartupCode" ) ) . forEach ( ( appStartupCodeFile ) => {
366
+ try {
367
+ with ( {
368
+ electron : require ( "electron" ) ,
369
+ robotjs : require ( "@jitsi/robotjs" ) ,
370
+ prompt : ( body , options ) => {
371
+ return new Promise ( ( resolve , reject ) => {
372
+ childProcess . spawn ( ( {
373
+ win32 : "cscript" ,
374
+ darwin : "osascript" ,
375
+ linux : "bash"
376
+ } ) [ process . platform ] , [ path . join ( process . resourcesPath , "nativePrompts/" + ( {
377
+ win32 : "win32.vbs" ,
378
+ darwin : "darwin.scpt" ,
379
+ linux : "linux.sh"
380
+ } ) [ process . platform ] ) , ( options || { } ) . title || require ( path . join ( process . resourcesPath , "app.asar/package.json" ) ) . productName , body , ( options || { } ) . defaultText || ( ( typeof options === "string" ) ? options : "" ) ] ) . stdout . on ( 'data' , ( promptData ) => {
381
+ if ( ! promptData . toString ( ) . startsWith ( "RETURN" ) ) return ;
382
+ resolve ( promptData . toString ( ) . substring ( 6 , promptData . toString ( ) . length - 2 ) ) ;
383
+ } ) ;
384
+ } ) ;
385
+ } ,
386
+ runPython : ( pythonCode ) => {
387
+ let pythonProcess = require ( "child_process" ) . spawn ( "python" , [ "-c" , pythonCode ] ) ;
388
+ pythonProcess . stdout . on ( "data" , ( chunk ) => {
389
+ console . log ( chunk . toString ( ) ) ;
390
+ } ) ;
391
+ pythonProcess . stderr . on ( "data" , ( err ) => {
392
+ console . error ( err . toString ( ) ) ;
393
+ ipcRenderer . send ( "scriptError" , {
394
+ language : "python" ,
395
+ err : err . toString ( )
396
+ } ) ;
397
+ } ) ;
398
+ return pythonProcess ;
399
+ } ,
400
+ executeInMainProcess : ( func ) => ipcRenderer . send ( "executeDebugCode" , "(" + func . toString ( ) + ")();" ) ,
401
+ createAppStartupCodeFile : ( func ) => {
402
+ let appStartupCodeFileId = crypto . randomBytes ( 8 ) . toString ( "hex" ) ;
403
+ fs . writeFileSync ( path . join ( process . resourcesPath , "appStartupCode/" + appStartupCodeFileId + ".js" ) , func . toString ( ) , "utf8" ) ;
404
+ return appStartupCodeFileId ;
405
+ } ,
406
+ deleteAppStartupCodeFile : ( appStartupCodeFileId ) => fs . unlinkSync ( path . join ( process . resourcesPath , "appStartupCode/" + appStartupCodeFileId + ".js" ) )
407
+ } ) {
408
+ eval ( "(async () => (" + fs . readFileSync ( path . join ( process . resourcesPath , "appStartupCode/" + appStartupCodeFile ) , "utf8" ) + ")())();" ) ;
409
+ } ;
410
+ } catch ( err ) {
411
+ ipcRenderer . send ( "scriptError" , {
412
+ language : "javascript" ,
413
+ err : err . stack
414
+ } ) ;
415
+ } ;
416
+ } ) ;
417
+
358
418
window . devTools = {
359
419
left : ( ) => ipcRenderer . send ( "executeDebugCode" , "window.webContents.closeDevTools(); window.webContents.openDevTools({ mode: 'left' });" ) ,
360
420
right : ( ) => ipcRenderer . send ( "executeDebugCode" , "window.webContents.closeDevTools(); window.webContents.openDevTools({ mode: 'right' });" ) ,
0 commit comments