@@ -9,9 +9,12 @@ import { GestureHandlerRootView } from "react-native-gesture-handler"; |
9 | 9 | import { KeyboardProvider } from "react-native-keyboard-controller"; |
10 | 10 | import { SafeAreaProvider } from "react-native-safe-area-context"; |
11 | 11 | import { |
| 12 | + CommonActions, |
| 13 | + createPathConfigForStaticNavigation, |
12 | 14 | createStaticNavigation, |
13 | 15 | getActionFromState, |
14 | 16 | getStateFromPath, |
| 17 | + type NavigationAction, |
15 | 18 | type NavigationState, |
16 | 19 | } from "@react-navigation/native"; |
17 | 20 |
|
@@ -21,12 +24,24 @@ import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet |
21 | 24 | import * as Dialog from "./components/ui/Dialog"; |
22 | 25 | import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider"; |
23 | 26 | import { 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"; |
25 | 39 | import { |
26 | 40 | AppearancePreferencesProvider, |
| 41 | + installAppearanceRuntime, |
27 | 42 | useAppearancePreferences, |
28 | 43 | } from "./features/settings/appearance/AppearancePreferencesProvider"; |
29 | | -import { RootStack } from "./Stack"; |
| 44 | +import { RootStack, workspaceLocationFromState } from "./Stack"; |
30 | 45 | import { appAtomRegistry } from "./state/atom-registry"; |
31 | 46 | import { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts"; |
32 | 47 | import { environmentThreadShells } from "./state/threads"; |
@@ -53,7 +68,12 @@ import { |
53 | 68 | } from "./features/workspace/workspace-selection-store"; |
54 | 69 | import { workspaceDetailLinkAction } from "./features/workspace/workspace-detail-selection"; |
55 | 70 | import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics"; |
56 | | -import { attachRootNavigation, rootNavigationRef } from "./lib/rootNavigation"; |
| 71 | +import { |
| 72 | + attachRootNavigation, |
| 73 | + flushRootNavigationQueue, |
| 74 | + linkToRootPath, |
| 75 | + rootNavigationRef, |
| 76 | +} from "./lib/rootNavigation"; |
57 | 77 | import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen"; |
58 | 78 |
|
59 | 79 | import "../global.css"; |
@@ -65,6 +85,20 @@ if (process.env.EXPO_PUBLIC_SHOWCASE === "1") { |
65 | 85 | void SplashScreen.preventAutoHideAsync().catch(() => {}); |
66 | 86 | void hydrateWorkspaceSelections(); |
67 | 87 |
|
| 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 | + |
68 | 102 | const appLinking = { |
69 | 103 | prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"], |
70 | 104 | config: { initialRouteName: "Home" }, |
@@ -77,24 +111,33 @@ const appLinking = { |
77 | 111 | // Our router handles the selection; React Navigation's type only lists its own actions. |
78 | 112 | (workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ?? |
79 | 113 | getActionFromState(state, options), |
80 | | - getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) => |
81 | | - takeScheduledTaskNewLink( |
82 | | - restoreSettingsLinkState( |
83 | | - restoreDraftLinkState(getStateFromPath(path, options), path), |
84 | | - settingsLinkPage(), |
85 | | - ), |
86 | | - ), |
| 114 | + getStateFromPath: getAppStateFromPath, |
87 | 115 | }; |
88 | 116 |
|
| 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 | + |
89 | 127 | const Navigation = createStaticNavigation(RootStack); |
90 | 128 |
|
91 | 129 | function handleNavigationStateChange(state: NavigationState | undefined): void { |
92 | 130 | recordWorkspaceSelections(state); |
93 | | - if (state) pruneNewTaskBranchCheckouts(state); |
| 131 | + presentPendingIncomingShare(); |
| 132 | + if (!state) return; |
| 133 | + setAgentNotificationPathname(workspaceLocationFromState(state).pathname); |
| 134 | + recordAppShortcutNavigationState(state); |
| 135 | + pruneNewTaskBranchCheckouts(state); |
94 | 136 | } |
95 | 137 |
|
96 | 138 | function handleNavigationReady(): void { |
97 | 139 | handleNavigationStateChange(rootNavigationRef.getRootState()); |
| 140 | + flushRootNavigationQueue(); |
98 | 141 | } |
99 | 142 |
|
100 | 143 | declare const module: { readonly hot?: FoundationHotModule } | undefined; |
@@ -107,10 +150,14 @@ const appServiceDisposers = [ |
107 | 150 | threadRefsAtom: environmentThreadShells.threadRefsAtom, |
108 | 151 | shellStateAtom: environmentShell.stateAtom, |
109 | 152 | }), |
| 153 | + installAppearanceRuntime(), |
110 | 154 | installSubscriptionUsageRefresh(), |
111 | 155 | installPermissionUpdateNotice(), |
112 | 156 | installThreadOutboxDelivery(), |
113 | 157 | installComposerAttachmentUploads(), |
| 158 | + startIncomingShareInbox(), |
| 159 | + installAgentNotificationNavigation(linkToAppPath), |
| 160 | + installAppShortcuts(linkToAppPath), |
114 | 161 | ]; |
115 | 162 | disposeOnFoundationReplace(typeof module === "undefined" ? undefined : module.hot, () => { |
116 | 163 | for (const dispose of appServiceDisposers) dispose(); |
@@ -153,15 +200,13 @@ function AppContent() { |
153 | 200 | {/* native-stack needs the theme's dark flag to select dark native headers. */} |
154 | 201 | <GlobalVoiceInputControl> |
155 | 202 | <NativeLayoutMetricsProvider> |
156 | | - <IncomingShareProvider> |
157 | | - <Navigation |
158 | | - ref={attachRootNavigation} |
159 | | - linking={appLinking} |
160 | | - onReady={handleNavigationReady} |
161 | | - theme={navigationTheme} |
162 | | - onStateChange={handleNavigationStateChange} |
163 | | - /> |
164 | | - </IncomingShareProvider> |
| 203 | + <Navigation |
| 204 | + ref={attachRootNavigation} |
| 205 | + linking={appLinking} |
| 206 | + onReady={handleNavigationReady} |
| 207 | + theme={navigationTheme} |
| 208 | + onStateChange={handleNavigationStateChange} |
| 209 | + /> |
165 | 210 | <Dialog.Host /> |
166 | 211 | <ThreadArrangementHost /> |
167 | 212 | <ProjectChipIconRasterizer /> |
|