@@ -27,7 +27,7 @@ import { log as logToFile, setup as setupFileLog } from 'node-log-rotate';
27
27
import { fork } from 'node:child_process' ;
28
28
import { promises as fs , rm , rmSync } from 'node:fs' ;
29
29
import type { AddressInfo } from 'node:net' ;
30
- import { isAbsolute , join , resolve } from 'node:path' ;
30
+ import path from 'node:path' ;
31
31
import { Sketch } from '../../common/protocol' ;
32
32
import {
33
33
AppInfo ,
@@ -226,9 +226,12 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
226
226
const appPath = app . getAppPath ( ) ;
227
227
let traceFile : string | undefined ;
228
228
if ( appPath ) {
229
- const tracesPath = join ( appPath , 'traces' ) ;
229
+ const tracesPath = path . join ( appPath , 'traces' ) ;
230
230
await fs . mkdir ( tracesPath , { recursive : true } ) ;
231
- traceFile = join ( tracesPath , `trace-${ new Date ( ) . toISOString ( ) } .trace` ) ;
231
+ traceFile = path . join (
232
+ tracesPath ,
233
+ `trace-${ new Date ( ) . toISOString ( ) } .trace`
234
+ ) ;
232
235
}
233
236
console . log ( '>>> Content tracing has started...' ) ;
234
237
await contentTracing . startRecording ( traceOptions ) ;
@@ -270,11 +273,11 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
270
273
maybePath : string ,
271
274
cwd : string
272
275
) : Promise < string | undefined > {
273
- if ( isAbsolute ( maybePath ) ) {
276
+ if ( path . isAbsolute ( maybePath ) ) {
274
277
return maybePath ;
275
278
}
276
279
try {
277
- const resolved = await fs . realpath ( resolve ( cwd , maybePath ) ) ;
280
+ const resolved = await fs . realpath ( path . resolve ( cwd , maybePath ) ) ;
278
281
return resolved ;
279
282
} catch ( err ) {
280
283
if ( ErrnoException . isENOENT ( err ) ) {
@@ -505,13 +508,38 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
505
508
}
506
509
507
510
protected override getDefaultOptions ( ) : TheiaBrowserWindowOptions {
508
- const options = super . getDefaultOptions ( ) ;
509
- if ( ! options . webPreferences ) {
510
- options . webPreferences = { } ;
511
- }
512
- options . webPreferences . v8CacheOptions = 'bypassHeatCheck' ; // TODO: verify this. VS Code use this V8 option.
513
- options . minWidth = 680 ;
514
- options . minHeight = 593 ;
511
+ // When opening IDE2 by double clicking on the ino file (for example, from Finder or Explorer), the frontend app config is not yet set.
512
+ // This customized default options method ensures that getting the frontend config is failsafe.
513
+ // https://github.com/arduino/arduino-ide/pull/2287#issuecomment-1818828569
514
+ const config = this . _config ?? {
515
+ applicationName : '' ,
516
+ electron : { windowOptions : { } } ,
517
+ } ;
518
+ const options : TheiaBrowserWindowOptions = {
519
+ show : false ,
520
+ title : config . applicationName ,
521
+ minWidth : 680 ,
522
+ minHeight : 593 ,
523
+ webPreferences : {
524
+ // `global` is undefined when `true`.
525
+ contextIsolation : true ,
526
+ sandbox : false ,
527
+ nodeIntegration : false ,
528
+ // Setting the following option to `true` causes some features to break, somehow.
529
+ // Issue: https://github.com/eclipse-theia/theia/issues/8577
530
+ nodeIntegrationInWorker : false ,
531
+ preload : path
532
+ . resolve (
533
+ this . globals . THEIA_APP_PROJECT_PATH ,
534
+ 'lib' ,
535
+ 'frontend' ,
536
+ 'preload.js'
537
+ )
538
+ . toString ( ) ,
539
+ v8CacheOptions : 'bypassHeatCheck' , // TODO: verify this. VS Code use this V8 option.
540
+ } ,
541
+ ...( config . electron ?. windowOptions || { } ) ,
542
+ } ;
515
543
return options ;
516
544
}
517
545
@@ -777,7 +805,13 @@ async function updateFrontendApplicationConfigFromPackageJson(
777
805
try {
778
806
const modulePath = __filename ;
779
807
// must go from `./lib/backend/electron-main.js` to `./package.json` when the app is webpacked.
780
- const packageJsonPath = join ( modulePath , '..' , '..' , '..' , 'package.json' ) ;
808
+ const packageJsonPath = path . join (
809
+ modulePath ,
810
+ '..' ,
811
+ '..' ,
812
+ '..' ,
813
+ 'package.json'
814
+ ) ;
781
815
console . debug (
782
816
`Checking for frontend application configuration customizations. Module path: ${ modulePath } , destination 'package.json': ${ packageJsonPath } `
783
817
) ;
0 commit comments