11import { installPermissionUpdateNotice } from "./features/connection/permissionUpdateNotice" ;
2+ import { installComposerAttachmentUploads } from "./state/composer-attachment-uploads" ;
3+ import { installThreadOutboxDelivery } from "./state/threadOutboxDelivery" ;
24import * as Linking from "expo-linking" ;
35import * as SplashScreen from "expo-splash-screen" ;
46import { useEffect } from "react" ;
@@ -7,10 +9,13 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
79import { KeyboardProvider } from "react-native-keyboard-controller" ;
810import { SafeAreaProvider } from "react-native-safe-area-context" ;
911import {
10- createNavigationContainerRef ,
12+ CommonActions ,
13+ createPathConfigForStaticNavigation ,
1114 createStaticNavigation ,
1215 getActionFromState ,
1316 getStateFromPath ,
17+ type NavigationAction ,
18+ type NavigationState ,
1419} from "@react-navigation/native" ;
1520
1621import { RegistryContext } from "@effect/atom-react" ;
@@ -19,12 +24,25 @@ import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet
1924import * as Dialog from "./components/ui/Dialog" ;
2025import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider" ;
2126import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene" ;
22- import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider" ;
27+ import {
28+ presentPendingIncomingShare ,
29+ pruneIncomingShareImports ,
30+ startIncomingShareInbox ,
31+ } from "./features/sharing/IncomingShareProvider" ;
32+ import {
33+ installAgentNotificationNavigation ,
34+ setAgentNotificationPathname ,
35+ } from "./features/agent-awareness/notificationNavigation" ;
36+ import {
37+ installAppShortcuts ,
38+ recordAppShortcutNavigationState ,
39+ } from "./features/shortcuts/appShortcutsRuntime" ;
2340import {
2441 AppearancePreferencesProvider ,
42+ installAppearanceRuntime ,
2543 useAppearancePreferences ,
2644} from "./features/settings/appearance/AppearancePreferencesProvider" ;
27- import { RootStack } from "./Stack" ;
45+ import { RootStack , workspaceLocationFromState } from "./Stack" ;
2846import { appAtomRegistry } from "./state/atom-registry" ;
2947import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts" ;
3048import { environmentThreadShells } from "./state/threads" ;
@@ -38,9 +56,9 @@ import {
3856 type FoundationHotModule ,
3957} from "./lib/foundation-fast-refresh" ;
4058import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme" ;
41- import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
59+ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
4260import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator" ;
43- import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider " ;
61+ import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage " ;
4462import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl" ;
4563import { restoreSettingsLinkState } from "./features/settings/settings-navigation" ;
4664import {
@@ -51,6 +69,13 @@ import {
5169} from "./features/workspace/workspace-selection-store" ;
5270import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection" ;
5371import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics" ;
72+ import {
73+ attachRootNavigation ,
74+ flushRootNavigationQueue ,
75+ linkToRootPath ,
76+ rootNavigationRef ,
77+ } from "./lib/rootNavigation" ;
78+ import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen" ;
5479
5580import "../global.css" ;
5681
@@ -61,6 +86,20 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
6186void SplashScreen . preventAutoHideAsync ( ) . catch ( ( ) => { } ) ;
6287void hydrateWorkspaceSelections ( ) ;
6388
89+ const linkingConfig = {
90+ initialRouteName : "Home" ,
91+ screens : createPathConfigForStaticNavigation ( RootStack , { initialRouteName : "Home" } ) ?? { } ,
92+ } as const ;
93+
94+ function getAppStateFromPath ( path : string , options : Parameters < typeof getStateFromPath > [ 1 ] ) {
95+ return takeScheduledTaskNewLink (
96+ restoreSettingsLinkState (
97+ restoreDraftLinkState ( getStateFromPath ( path , options ) , path ) ,
98+ settingsLinkPage ( ) ,
99+ ) ,
100+ ) ;
101+ }
102+
64103const appLinking = {
65104 prefixes : [ Linking . createURL ( "/" ) , "t3code://" , "t3code-dev://" , "t3code-preview://" ] ,
66105 config : { initialRouteName : "Home" } ,
@@ -73,25 +112,58 @@ const appLinking = {
73112 // Our router handles the selection; React Navigation's type only lists its own actions.
74113 ( workspaceDetailLinkAction ( state ) as ReturnType < typeof getActionFromState > ) ??
75114 getActionFromState ( state , options ) ,
76- getStateFromPath : ( path : string , options : Parameters < typeof getStateFromPath > [ 1 ] ) =>
77- takeScheduledTaskNewLink (
78- restoreSettingsLinkState (
79- restoreDraftLinkState ( getStateFromPath ( path , options ) , path ) ,
80- settingsLinkPage ( ) ,
81- ) ,
82- ) ,
115+ getStateFromPath : getAppStateFromPath ,
83116} ;
84117
118+ function appLinkAction ( href : string ) : NavigationAction {
119+ const state = getAppStateFromPath ( href , linkingConfig ) ;
120+ if ( ! state ) throw new Error ( `Failed to parse the href to a navigation state (${ href } ).` ) ;
121+ return appLinking . getActionFromState ( state , linkingConfig ) ?? CommonActions . reset ( state ) ;
122+ }
123+
124+ function linkToAppPath ( href : string ) : void {
125+ linkToRootPath ( href , appLinkAction ) ;
126+ }
127+
85128const Navigation = createStaticNavigation ( RootStack ) ;
86- const navigationRef = createNavigationContainerRef ( ) ;
129+
130+ function handleNavigationStateChange ( state : NavigationState | undefined ) : void {
131+ recordWorkspaceSelections ( state ) ;
132+ presentPendingIncomingShare ( ) ;
133+ if ( ! state ) return ;
134+ setAgentNotificationPathname ( workspaceLocationFromState ( state ) . pathname ) ;
135+ recordAppShortcutNavigationState ( state ) ;
136+ pruneNewTaskBranchCheckouts ( state ) ;
137+ pruneIncomingShareImports ( state ) ;
138+ }
139+
140+ function handleNavigationReady ( ) : void {
141+ handleNavigationStateChange ( rootNavigationRef . getRootState ( ) ) ;
142+ flushRootNavigationQueue ( ) ;
143+ }
87144
88145declare const module : { readonly hot ?: FoundationHotModule } | undefined ;
89146
90- const disposePermissionUpdateNotice = installPermissionUpdateNotice ( ) ;
91- disposeOnFoundationReplace (
92- typeof module === "undefined" ? undefined : module . hot ,
93- disposePermissionUpdateNotice ,
94- ) ;
147+ const appServiceDisposers = [
148+ installUiRuntimeMemoryWarningGc ( ) ,
149+ subscribeComposerDraftModelReconciliation ( {
150+ registry : appAtomRegistry ,
151+ threadShellAtom : environmentThreadShells . threadShellAtom ,
152+ threadRefsAtom : environmentThreadShells . threadRefsAtom ,
153+ shellStateAtom : environmentShell . stateAtom ,
154+ } ) ,
155+ installAppearanceRuntime ( ) ,
156+ installSubscriptionUsageRefresh ( ) ,
157+ installPermissionUpdateNotice ( ) ,
158+ installThreadOutboxDelivery ( ) ,
159+ installComposerAttachmentUploads ( ) ,
160+ startIncomingShareInbox ( ) ,
161+ installAgentNotificationNavigation ( linkToAppPath ) ,
162+ installAppShortcuts ( linkToAppPath ) ,
163+ ] ;
164+ disposeOnFoundationReplace ( typeof module === "undefined" ? undefined : module . hot , ( ) => {
165+ for ( const dispose of appServiceDisposers ) dispose ( ) ;
166+ } ) ;
95167
96168function SplashScreenCoordinator ( ) {
97169 const { isReady } = useAppearancePreferences ( ) ;
@@ -104,18 +176,6 @@ function SplashScreenCoordinator() {
104176}
105177
106178export default function App ( ) {
107- useUiRuntimeMemoryWarningGc ( ) ;
108- useEffect (
109- ( ) =>
110- subscribeComposerDraftModelReconciliation ( {
111- registry : appAtomRegistry ,
112- threadShellAtom : environmentThreadShells . threadShellAtom ,
113- threadRefsAtom : environmentThreadShells . threadRefsAtom ,
114- shellStateAtom : environmentShell . stateAtom ,
115- } ) ,
116- [ ] ,
117- ) ;
118-
119179 return (
120180 < RegistryContext . Provider value = { appAtomRegistry } >
121181 < CloudAuthProvider >
@@ -138,27 +198,23 @@ function AppContent() {
138198 < GestureHandlerRootView className = "flex-1" >
139199 < KeyboardProvider statusBarTranslucent >
140200 < SafeAreaProvider >
141- < VoiceInputProvider >
142- < StatusBar barStyle = { themeAppearance === "dark" ? "light-content" : "dark-content" } />
143- { /* native-stack needs the theme's dark flag to select dark native headers. */ }
144- < GlobalVoiceInputControl >
145- < NativeLayoutMetricsProvider >
146- < IncomingShareProvider >
147- < Navigation
148- ref = { navigationRef }
149- linking = { appLinking }
150- onReady = { ( ) => recordWorkspaceSelections ( navigationRef . getRootState ( ) ) }
151- theme = { navigationTheme }
152- onStateChange = { recordWorkspaceSelections }
153- />
154- </ IncomingShareProvider >
155- < Dialog . Host />
156- < ThreadArrangementHost />
157- < ProjectChipIconRasterizer />
158- </ NativeLayoutMetricsProvider >
159- </ GlobalVoiceInputControl >
160- < OverlayPortalHost />
161- </ VoiceInputProvider >
201+ < StatusBar barStyle = { themeAppearance === "dark" ? "light-content" : "dark-content" } />
202+ { /* native-stack needs the theme's dark flag to select dark native headers. */ }
203+ < GlobalVoiceInputControl >
204+ < NativeLayoutMetricsProvider >
205+ < Navigation
206+ ref = { attachRootNavigation }
207+ linking = { appLinking }
208+ onReady = { handleNavigationReady }
209+ theme = { navigationTheme }
210+ onStateChange = { handleNavigationStateChange }
211+ />
212+ < Dialog . Host />
213+ < ThreadArrangementHost />
214+ < ProjectChipIconRasterizer />
215+ </ NativeLayoutMetricsProvider >
216+ </ GlobalVoiceInputControl >
217+ < OverlayPortalHost />
162218 </ SafeAreaProvider >
163219 </ KeyboardProvider >
164220 </ GestureHandlerRootView >
0 commit comments