@@ -41,6 +41,7 @@ import {
41
41
import { getTelemetryReporter } from "../utilities/telemetry" ;
42
42
import { ToolKey , ToolsManager } from "./tools" ;
43
43
import { UtilsInterface } from "../common/utils" ;
44
+ import { getAppRoutes } from "../utilities/getFileBasedRoutes" ;
44
45
45
46
const DEVICE_SETTINGS_KEY = "device_settings_v4" ;
46
47
@@ -106,6 +107,11 @@ export class Project
106
107
this . trySelectingInitialDevice ( ) ;
107
108
this . deviceManager . addListener ( "deviceRemoved" , this . removeDeviceListener ) ;
108
109
this . isCachedBuildStale = false ;
110
+ this . dependencyManager . checkProjectUsesExpoRouter ( ) . then ( ( result ) => {
111
+ if ( result ) {
112
+ this . initializeFileBasedRoutes ( "onAppReady" ) ;
113
+ }
114
+ } ) ;
109
115
110
116
this . fileWatcher = watchProjectFiles ( ( ) => {
111
117
this . checkIfNativeChanged ( ) ;
@@ -129,6 +135,11 @@ export class Project
129
135
130
136
onStateChange = ( state : StartupMessage ) : void => {
131
137
this . updateProjectStateForDevice ( this . projectState . selectedDevice ! , { startupMessage : state } ) ;
138
+ this . dependencyManager . checkProjectUsesExpoRouter ( ) . then ( ( result ) => {
139
+ if ( result ) {
140
+ this . initializeFileBasedRoutes ( "now" ) ;
141
+ }
142
+ } ) ;
132
143
} ;
133
144
//#endregion
134
145
@@ -138,6 +149,9 @@ export class Project
138
149
case "navigationChanged" :
139
150
this . eventEmitter . emit ( "navigationChanged" , payload ) ;
140
151
break ;
152
+ case "navigationInit" :
153
+ this . eventEmitter . emit ( "navigationInit" , payload ) ;
154
+ break ;
141
155
case "fastRefreshStarted" :
142
156
this . updateProjectState ( { status : "refreshing" } ) ;
143
157
break ;
@@ -267,6 +281,19 @@ export class Project
267
281
await this . utils . showToast ( "Copied from device clipboard" , 2000 ) ;
268
282
}
269
283
284
+ private async initializeFileBasedRoutes ( type : "onAppReady" | "now" ) {
285
+ const routes = await getAppRoutes ( ) ;
286
+ if ( type === "onAppReady" ) {
287
+ this . devtools . addListener ( ( name ) => {
288
+ if ( name === "RNIDE_appReady" ) {
289
+ this . devtools . send ( "RNIDE_loadFileBasedRoutes" , routes ) ;
290
+ }
291
+ } ) ;
292
+ } else {
293
+ this . devtools . send ( "RNIDE_loadFileBasedRoutes" , routes ) ;
294
+ }
295
+ }
296
+
270
297
onBundleError ( ) : void {
271
298
this . updateProjectState ( { status : "bundleError" } ) ;
272
299
}
@@ -450,28 +477,34 @@ export class Project
450
477
}
451
478
452
479
public async reload ( type : ReloadAction ) : Promise < boolean > {
453
- this . updateProjectState ( { status : "starting" , startupMessage : StartupMessage . Restarting } ) ;
480
+ try {
481
+ this . updateProjectState ( { status : "starting" , startupMessage : StartupMessage . Restarting } ) ;
454
482
455
- getTelemetryReporter ( ) . sendTelemetryEvent ( "url-bar:reload-requested" , {
456
- platform : this . projectState . selectedDevice ?. platform ,
457
- method : type ,
458
- } ) ;
483
+ getTelemetryReporter ( ) . sendTelemetryEvent ( "url-bar:reload-requested" , {
484
+ platform : this . projectState . selectedDevice ?. platform ,
485
+ method : type ,
486
+ } ) ;
459
487
460
- // this action needs to be handled outside of device session as it resets the device session itself
461
- if ( type === "reboot" ) {
462
- const deviceInfo = this . projectState . selectedDevice ! ;
463
- await this . start ( true , false ) ;
464
- await this . selectDevice ( deviceInfo ) ;
465
- return true ;
466
- }
488
+ // this action needs to be handled outside of device session as it resets the device session itself
489
+ if ( type === "reboot" ) {
490
+ const deviceInfo = this . projectState . selectedDevice ! ;
491
+ await this . start ( true , false ) ;
492
+ await this . selectDevice ( deviceInfo ) ;
493
+ return true ;
494
+ }
467
495
468
- const success = ( await this . deviceSession ?. perform ( type ) ) ?? false ;
469
- if ( success ) {
470
- this . updateProjectState ( { status : "running" } ) ;
471
- } else {
472
- window . showErrorMessage ( "Failed to reload, you may try another reload option." , "Dismiss" ) ;
496
+ const success = ( await this . deviceSession ?. perform ( type ) ) ?? false ;
497
+ if ( success ) {
498
+ this . updateProjectState ( { status : "running" } ) ;
499
+ } else {
500
+ window . showErrorMessage ( "Failed to reload, you may try another reload option." , "Dismiss" ) ;
501
+ }
502
+ return success ;
503
+ } finally {
504
+ if ( await this . dependencyManager . checkProjectUsesExpoRouter ( ) ) {
505
+ await this . initializeFileBasedRoutes ( "onAppReady" ) ;
506
+ }
473
507
}
474
- return success ;
475
508
}
476
509
477
510
private async start ( restart : boolean , resetMetroCache : boolean ) {
0 commit comments