@@ -9,10 +9,13 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
99import { KeyboardProvider } from "react-native-keyboard-controller" ;
1010import { SafeAreaProvider } from "react-native-safe-area-context" ;
1111import {
12- createNavigationContainerRef ,
12+ CommonActions ,
13+ createPathConfigForStaticNavigation ,
1314 createStaticNavigation ,
1415 getActionFromState ,
1516 getStateFromPath ,
17+ type NavigationAction ,
18+ type NavigationState ,
1619} from "@react-navigation/native" ;
1720
1821import { RegistryContext } from "@effect/atom-react" ;
@@ -21,12 +24,24 @@ import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet
2124import * as Dialog from "./components/ui/Dialog" ;
2225import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider" ;
2326import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene" ;
24- 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" ;
2539import {
2640 AppearancePreferencesProvider ,
41+ installAppearanceRuntime ,
2742 useAppearancePreferences ,
2843} from "./features/settings/appearance/AppearancePreferencesProvider" ;
29- import { RootStack } from "./Stack" ;
44+ import { RootStack , workspaceLocationFromState } from "./Stack" ;
3045import { appAtomRegistry } from "./state/atom-registry" ;
3146import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts" ;
3247import { environmentThreadShells } from "./state/threads" ;
@@ -40,8 +55,9 @@ import {
4055 type FoundationHotModule ,
4156} from "./lib/foundation-fast-refresh" ;
4257import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme" ;
43- import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
58+ import { installUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc" ;
4459import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator" ;
60+ import { installSubscriptionUsageRefresh } from "./widgets/useSubscriptionUsage" ;
4561import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl" ;
4662import { restoreSettingsLinkState } from "./features/settings/settings-navigation" ;
4763import {
@@ -52,6 +68,13 @@ import {
5268} from "./features/workspace/workspace-selection-store" ;
5369import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection" ;
5470import { 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" ;
5578
5679import "../global.css" ;
5780
@@ -62,6 +85,20 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
6285void SplashScreen . preventAutoHideAsync ( ) . catch ( ( ) => { } ) ;
6386void hydrateWorkspaceSelections ( ) ;
6487
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+
65102const appLinking = {
66103 prefixes : [ Linking . createURL ( "/" ) , "t3code://" , "t3code-dev://" , "t3code-preview://" ] ,
67104 config : { initialRouteName : "Home" } ,
@@ -74,24 +111,53 @@ const appLinking = {
74111 // Our router handles the selection; React Navigation's type only lists its own actions.
75112 ( workspaceDetailLinkAction ( state ) as ReturnType < typeof getActionFromState > ) ??
76113 getActionFromState ( state , options ) ,
77- getStateFromPath : ( path : string , options : Parameters < typeof getStateFromPath > [ 1 ] ) =>
78- takeScheduledTaskNewLink (
79- restoreSettingsLinkState (
80- restoreDraftLinkState ( getStateFromPath ( path , options ) , path ) ,
81- settingsLinkPage ( ) ,
82- ) ,
83- ) ,
114+ getStateFromPath : getAppStateFromPath ,
84115} ;
85116
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+
86127const Navigation = createStaticNavigation ( RootStack ) ;
87- 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+ }
88142
89143declare const module : { readonly hot ?: FoundationHotModule } | undefined ;
90144
91145const 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 ( ) ,
92155 installPermissionUpdateNotice ( ) ,
93156 installThreadOutboxDelivery ( ) ,
94157 installComposerAttachmentUploads ( ) ,
158+ startIncomingShareInbox ( ) ,
159+ installAgentNotificationNavigation ( linkToAppPath ) ,
160+ installAppShortcuts ( linkToAppPath ) ,
95161] ;
96162disposeOnFoundationReplace ( typeof module === "undefined" ? undefined : module . hot , ( ) => {
97163 for ( const dispose of appServiceDisposers ) dispose ( ) ;
@@ -108,18 +174,6 @@ function SplashScreenCoordinator() {
108174}
109175
110176export default function App ( ) {
111- useUiRuntimeMemoryWarningGc ( ) ;
112- useEffect (
113- ( ) =>
114- subscribeComposerDraftModelReconciliation ( {
115- registry : appAtomRegistry ,
116- threadShellAtom : environmentThreadShells . threadShellAtom ,
117- threadRefsAtom : environmentThreadShells . threadRefsAtom ,
118- shellStateAtom : environmentShell . stateAtom ,
119- } ) ,
120- [ ] ,
121- ) ;
122-
123177 return (
124178 < RegistryContext . Provider value = { appAtomRegistry } >
125179 < CloudAuthProvider >
@@ -146,15 +200,13 @@ function AppContent() {
146200 { /* native-stack needs the theme's dark flag to select dark native headers. */ }
147201 < GlobalVoiceInputControl >
148202 < NativeLayoutMetricsProvider >
149- < IncomingShareProvider >
150- < Navigation
151- ref = { navigationRef }
152- linking = { appLinking }
153- onReady = { ( ) => recordWorkspaceSelections ( navigationRef . getRootState ( ) ) }
154- theme = { navigationTheme }
155- onStateChange = { recordWorkspaceSelections }
156- />
157- </ IncomingShareProvider >
203+ < Navigation
204+ ref = { attachRootNavigation }
205+ linking = { appLinking }
206+ onReady = { handleNavigationReady }
207+ theme = { navigationTheme }
208+ onStateChange = { handleNavigationStateChange }
209+ />
158210 < Dialog . Host />
159211 < ThreadArrangementHost />
160212 < ProjectChipIconRasterizer />
0 commit comments