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,24 @@ 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+ startIncomingShareInbox ,
30+ } from "./features/sharing/IncomingShareProvider" ;
31+ import {
32+ installAgentNotificationNavigation ,
33+ setAgentNotificationPathname ,
34+ } from "./features/agent-awareness/notificationNavigation" ;
35+ import {
36+ installAppShortcuts ,
37+ recordAppShortcutNavigationState ,
38+ } from "./features/shortcuts/appShortcutsRuntime" ;
2339import {
2440 AppearancePreferencesProvider ,
41+ installAppearanceRuntime ,
2542 useAppearancePreferences ,
2643} from "./features/settings/appearance/AppearancePreferencesProvider" ;
27- import { RootStack } from "./Stack" ;
44+ import { RootStack , workspaceLocationFromState } from "./Stack" ;
2845import { appAtomRegistry } from "./state/atom-registry" ;
2946import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts" ;
3047import { environmentThreadShells } from "./state/threads" ;
@@ -38,9 +55,9 @@ import {
3855 type FoundationHotModule ,
3956} from "./lib/foundation-fast-refresh" ;
4057import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme" ;
41- import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
58+ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
4259import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator" ;
43- import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider " ;
60+ import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage " ;
4461import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl" ;
4562import { restoreSettingsLinkState } from "./features/settings/settings-navigation" ;
4663import {
@@ -51,6 +68,13 @@ import {
5168} from "./features/workspace/workspace-selection-store" ;
5269import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection" ;
5370import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics" ;
71+ import {
72+ attachRootNavigation ,
73+ flushRootNavigationQueue ,
74+ linkToRootPath ,
75+ rootNavigationRef ,
76+ } from "./lib/rootNavigation" ;
77+ import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen" ;
5478
5579import "../global.css" ;
5680
@@ -61,6 +85,20 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
6185void SplashScreen . preventAutoHideAsync ( ) . catch ( ( ) => { } ) ;
6286void hydrateWorkspaceSelections ( ) ;
6387
88+ const linkingConfig = {
89+ initialRouteName : "Home" ,
90+ screens : createPathConfigForStaticNavigation ( RootStack , { initialRouteName : "Home" } ) ?? { } ,
91+ } as const ;
92+
93+ function getAppStateFromPath ( path : string , options : Parameters < typeof getStateFromPath > [ 1 ] ) {
94+ return takeScheduledTaskNewLink (
95+ restoreSettingsLinkState (
96+ restoreDraftLinkState ( getStateFromPath ( path , options ) , path ) ,
97+ settingsLinkPage ( ) ,
98+ ) ,
99+ ) ;
100+ }
101+
64102const appLinking = {
65103 prefixes : [ Linking . createURL ( "/" ) , "t3code://" , "t3code-dev://" , "t3code-preview://" ] ,
66104 config : { initialRouteName : "Home" } ,
@@ -73,25 +111,57 @@ const appLinking = {
73111 // Our router handles the selection; React Navigation's type only lists its own actions.
74112 ( workspaceDetailLinkAction ( state ) as ReturnType < typeof getActionFromState > ) ??
75113 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- ) ,
114+ getStateFromPath : getAppStateFromPath ,
83115} ;
84116
117+ function appLinkAction ( href : string ) : NavigationAction {
118+ const state = getAppStateFromPath ( href , linkingConfig ) ;
119+ if ( ! state ) throw new Error ( `Failed to parse the href to a navigation state (${ href } ).` ) ;
120+ return appLinking . getActionFromState ( state , linkingConfig ) ?? CommonActions . reset ( state ) ;
121+ }
122+
123+ function linkToAppPath ( href : string ) : void {
124+ linkToRootPath ( href , appLinkAction ) ;
125+ }
126+
85127const Navigation = createStaticNavigation ( RootStack ) ;
86- const navigationRef = createNavigationContainerRef ( ) ;
128+
129+ function handleNavigationStateChange ( state : NavigationState | undefined ) : void {
130+ recordWorkspaceSelections ( state ) ;
131+ presentPendingIncomingShare ( ) ;
132+ if ( ! state ) return ;
133+ setAgentNotificationPathname ( workspaceLocationFromState ( state ) . pathname ) ;
134+ recordAppShortcutNavigationState ( state ) ;
135+ pruneNewTaskBranchCheckouts ( state ) ;
136+ }
137+
138+ function handleNavigationReady ( ) : void {
139+ handleNavigationStateChange ( rootNavigationRef . getRootState ( ) ) ;
140+ flushRootNavigationQueue ( ) ;
141+ }
87142
88143declare const module : { readonly hot ?: FoundationHotModule } | undefined ;
89144
90- const disposePermissionUpdateNotice = installPermissionUpdateNotice ( ) ;
91- disposeOnFoundationReplace (
92- typeof module === "undefined" ? undefined : module . hot ,
93- disposePermissionUpdateNotice ,
94- ) ;
145+ const appServiceDisposers = [
146+ installUiRuntimeMemoryWarningGc ( ) ,
147+ subscribeComposerDraftModelReconciliation ( {
148+ registry : appAtomRegistry ,
149+ threadShellAtom : environmentThreadShells . threadShellAtom ,
150+ threadRefsAtom : environmentThreadShells . threadRefsAtom ,
151+ shellStateAtom : environmentShell . stateAtom ,
152+ } ) ,
153+ installAppearanceRuntime ( ) ,
154+ installSubscriptionUsageRefresh ( ) ,
155+ installPermissionUpdateNotice ( ) ,
156+ installThreadOutboxDelivery ( ) ,
157+ installComposerAttachmentUploads ( ) ,
158+ startIncomingShareInbox ( ) ,
159+ installAgentNotificationNavigation ( linkToAppPath ) ,
160+ installAppShortcuts ( linkToAppPath ) ,
161+ ] ;
162+ disposeOnFoundationReplace ( typeof module === "undefined" ? undefined : module . hot , ( ) => {
163+ for ( const dispose of appServiceDisposers ) dispose ( ) ;
164+ } ) ;
95165
96166function SplashScreenCoordinator ( ) {
97167 const { isReady } = useAppearancePreferences ( ) ;
@@ -104,18 +174,6 @@ function SplashScreenCoordinator() {
104174}
105175
106176export 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-
119177 return (
120178 < RegistryContext . Provider value = { appAtomRegistry } >
121179 < CloudAuthProvider >
@@ -138,27 +196,23 @@ function AppContent() {
138196 < GestureHandlerRootView className = "flex-1" >
139197 < KeyboardProvider statusBarTranslucent >
140198 < 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 >
199+ < StatusBar barStyle = { themeAppearance === "dark" ? "light-content" : "dark-content" } />
200+ { /* native-stack needs the theme's dark flag to select dark native headers. */ }
201+ < GlobalVoiceInputControl >
202+ < NativeLayoutMetricsProvider >
203+ < Navigation
204+ ref = { attachRootNavigation }
205+ linking = { appLinking }
206+ onReady = { handleNavigationReady }
207+ theme = { navigationTheme }
208+ onStateChange = { handleNavigationStateChange }
209+ />
210+ < Dialog . Host />
211+ < ThreadArrangementHost />
212+ < ProjectChipIconRasterizer />
213+ </ NativeLayoutMetricsProvider >
214+ </ GlobalVoiceInputControl >
215+ < OverlayPortalHost />
162216 </ SafeAreaProvider >
163217 </ KeyboardProvider >
164218 </ GestureHandlerRootView >
0 commit comments