File tree 3 files changed +40
-2
lines changed
arduino-ide-extension/src
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -38,3 +38,26 @@ export function uint8ArrayToString(uint8Array: Uint8Array): string {
38
38
export function stringToUint8Array ( text : string ) : Uint8Array {
39
39
return Uint8Array . from ( text , ( char ) => char . charCodeAt ( 0 ) ) ;
40
40
}
41
+
42
+ export function poolWhile (
43
+ whileCondition : ( ) => boolean ,
44
+ intervalMs : number ,
45
+ timeoutMs : number
46
+ ) : Promise < void > {
47
+ return new Promise ( ( resolve , reject ) => {
48
+ if ( ! whileCondition ) {
49
+ resolve ( ) ;
50
+ }
51
+
52
+ const start = Date . now ( ) ;
53
+ const interval = setInterval ( ( ) => {
54
+ if ( ! whileCondition ( ) ) {
55
+ clearInterval ( interval ) ;
56
+ resolve ( ) ;
57
+ } else if ( Date . now ( ) - start > timeoutMs ) {
58
+ clearInterval ( interval ) ;
59
+ reject ( new Error ( 'Timed out while polling.' ) ) ;
60
+ }
61
+ } , intervalMs ) ;
62
+ } ) ;
63
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import type { AddressInfo } from 'node:net';
30
30
import { isAbsolute , join , resolve } from 'node:path' ;
31
31
import type { Argv } from 'yargs' ;
32
32
import { Sketch } from '../../common/protocol' ;
33
+ import { poolWhile } from '../../common/utils' ;
33
34
import {
34
35
AppInfo ,
35
36
appInfoPropertyLiterals ,
@@ -292,6 +293,16 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
292
293
) ;
293
294
if ( sketchFolderPath ) {
294
295
this . openFilePromise . reject ( new InterruptWorkspaceRestoreError ( ) ) ;
296
+
297
+ // open-file event is triggered before the app is ready and initialWindow is created.
298
+ // Wait for initialWindow to be set before opening the sketch on the first instance.
299
+ // See https://github.com/arduino/arduino-ide/pull/2693
300
+ try {
301
+ await app . whenReady ( ) ;
302
+ if ( ! this . firstWindowId ) {
303
+ await poolWhile ( ( ) => ! this . initialWindow , 100 , 3000 ) ;
304
+ }
305
+ } catch { }
295
306
await this . openSketch ( sketchFolderPath ) ;
296
307
}
297
308
}
@@ -890,7 +901,10 @@ const fallbackFrontendAppConfig: FrontendApplicationConfig = {
890
901
defaultIconTheme : 'none' ,
891
902
validatePreferencesSchema : false ,
892
903
defaultLocale : '' ,
893
- electron : { showWindowEarly : true , uriScheme : 'custom://arduino-ide' } ,
904
+ electron : {
905
+ showWindowEarly : true ,
906
+ uriScheme : 'arduino-ide' ,
907
+ } ,
894
908
reloadOnReconnect : true ,
895
909
} ;
896
910
Original file line number Diff line number Diff line change 67
67
"defaultIconTheme" : " none" ,
68
68
"validatePreferencesSchema" : false ,
69
69
"electron" : {
70
- "showWindowEarly" : true
70
+ "showWindowEarly" : true ,
71
+ "uriScheme" : " arduino-ide"
71
72
},
72
73
"reloadOnReconnect" : true ,
73
74
"preferences" : {
You can’t perform that action at this time.
0 commit comments