Skip to content

Commit 401d6da

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-25845
2 parents 4985e8d + a452c2d commit 401d6da

56 files changed

Lines changed: 2418 additions & 1339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ describe("DesktopApplicationMenu", () => {
199199
}),
200200
);
201201

202+
it.effect("never binds Cmd/Ctrl+W to closing the window", () =>
203+
Effect.gen(function* () {
204+
for (const platform of ["darwin", "linux", "win32"] as const) {
205+
const applicationMenuTemplate =
206+
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();
207+
yield* configureMenu(yield* Deferred.make<string>(), applicationMenuTemplate, {
208+
platform,
209+
});
210+
211+
const items: Electron.MenuItemConstructorOptions[] = [];
212+
const collect = (template: readonly Electron.MenuItemConstructorOptions[]) => {
213+
for (const item of template) {
214+
items.push(item);
215+
if (Array.isArray(item.submenu)) collect(item.submenu);
216+
}
217+
};
218+
collect(yield* Deferred.await(applicationMenuTemplate));
219+
220+
assert.isUndefined(
221+
items.find((item) => item.role === "close"),
222+
platform,
223+
);
224+
// Electron's default windowMenu submenu includes a close role.
225+
assert.isUndefined(
226+
items.find((item) => item.role === "windowMenu" && item.submenu === undefined),
227+
platform,
228+
);
229+
assert.isUndefined(
230+
items.find((item) => item.accelerator?.toLowerCase().endsWith("+w")),
231+
platform,
232+
);
233+
}
234+
}),
235+
);
236+
202237
it.effect("reloads the main window even while a browser page has focus", () =>
203238
Effect.gen(function* () {
204239
const selectedAction = yield* Deferred.make<string>();

‎apps/desktop/src/window/DesktopApplicationMenu.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ export const make = Effect.gen(function* () {
200200
},
201201
{ type: "separator" as const },
202202
]),
203-
{ role: environment.platform === "darwin" ? "close" : "quit" },
203+
// Cmd/Ctrl+W belongs to the renderer's tab close; it must never close the window.
204+
environment.platform === "darwin"
205+
? { label: "Close Window", click: (_item, window) => window?.close() }
206+
: { role: "quit" },
204207
],
205208
},
206209
{
@@ -289,7 +292,17 @@ export const make = Effect.gen(function* () {
289292
{ role: "togglefullscreen" },
290293
],
291294
},
292-
{ role: "windowMenu" },
295+
{
296+
// Electron's default Window submenu adds a Ctrl+W close role off macOS.
297+
role: "windowMenu",
298+
submenu: [
299+
{ role: "minimize" },
300+
{ role: "zoom" },
301+
...(environment.platform === "darwin"
302+
? [{ type: "separator" as const }, { role: "front" as const }]
303+
: []),
304+
],
305+
},
293306
{
294307
role: "help",
295308
submenu: [

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ export const make = Effect.gen(function* () {
619619
}
620620
});
621621

622-
// Terminal-close repeats can outlive the terminal; reject them before the native close-window accelerator.
623622
const quitShortcutHandler = makeQuitShortcutHandler({
624623
platform: environment.platform,
625624
getMode: () =>
@@ -645,6 +644,7 @@ export const make = Effect.gen(function* () {
645644
});
646645
window.webContents.on("before-input-event", (event, input) => {
647646
quitShortcutHandler(event, input);
647+
// A held Cmd/Ctrl+W closes one tab or terminal, not each one behind it.
648648
if (input.type !== "keyDown" || !input.isAutoRepeat) return;
649649
const modifier = environment.platform === "darwin" ? input.meta : input.control;
650650
if (modifier && !input.alt && !input.shift && input.key.toLowerCase() === "w") {

‎apps/mobile/src/App.tsx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ import { OverlayPortalHost } from "./components/ui/OverlayPortal";
5151
import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
5252
import { hasCloudPublicConfig } from "./features/cloud/publicConfig";
5353
import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state";
54+
import {
55+
resolvePendingNewTaskPromptLink,
56+
takeNewTaskPromptLink,
57+
} from "./features/prompt-links/newTaskPromptLink";
58+
import {
59+
resolvePendingThreadPromptLink,
60+
takeThreadPromptLink,
61+
} from "./features/prompt-links/threadPromptLink";
5462
import {
5563
disposeOnFoundationReplace,
5664
type FoundationHotModule,
@@ -75,6 +83,7 @@ import {
7583
linkToRootPath,
7684
rootNavigationRef,
7785
} from "./lib/rootNavigation";
86+
import { pruneNewTaskFlowStates } from "./features/threads/new-task-flow-state";
7887
import { pruneNewTaskBranchCheckouts } from "./features/threads/NewTaskDraftRouteScreen";
7988

8089
import "../global.css";
@@ -93,9 +102,13 @@ const linkingConfig = {
93102

94103
function getAppStateFromPath(path: string, options: Parameters<typeof getStateFromPath>[1]) {
95104
return takeScheduledTaskNewLink(
96-
restoreSettingsLinkState(
97-
restoreDraftLinkState(getStateFromPath(path, options), path),
98-
settingsLinkPage(),
105+
takeNewTaskPromptLink(
106+
takeThreadPromptLink(
107+
restoreSettingsLinkState(
108+
restoreDraftLinkState(getStateFromPath(path, options), path),
109+
settingsLinkPage(),
110+
),
111+
),
99112
),
100113
);
101114
}
@@ -130,9 +143,12 @@ const Navigation = createStaticNavigation(RootStack);
130143
function handleNavigationStateChange(state: NavigationState | undefined): void {
131144
recordWorkspaceSelections(state);
132145
presentPendingIncomingShare();
146+
resolvePendingNewTaskPromptLink(state);
147+
resolvePendingThreadPromptLink(state);
133148
if (!state) return;
134149
setAgentNotificationPathname(workspaceLocationFromState(state).pathname);
135150
recordAppShortcutNavigationState(state);
151+
pruneNewTaskFlowStates(state);
136152
pruneNewTaskBranchCheckouts(state);
137153
pruneIncomingShareImports(state);
138154
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
NewTaskThreadSettingsRouteScreen,
9090
} from "./features/threads/ThreadSettingsSheet";
9191
import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
92+
import { newTaskFlowKey } from "./features/threads/new-task-flow-state";
9293
import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
9394
import { SettingsNavigationRouteScreen } from "./features/settings/SettingsNavigationRouteScreen";
9495
import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
@@ -482,9 +483,12 @@ export function workspaceLocationFromState(state: NavigationState) {
482483
? ({ ...state, routes, index: routes.length - 1 } as NavigationState)
483484
: state;
484485
const path = getPathFromState(effectiveState, navigationPathConfig);
486+
const route = effectiveState.routes[effectiveState.index];
485487
return {
486488
pathname: path.startsWith("/") ? path : `/${path}`,
487-
routeKey: effectiveState.routes[effectiveState.index]?.key,
489+
routeKey: route?.key,
490+
routeName: route?.name,
491+
routeKeys: effectiveState.routes.map((stackRoute) => stackRoute.key),
488492
};
489493
}
490494

@@ -500,7 +504,12 @@ function RootStackLayout(props: {
500504
.slice(0, props.state.index + 1)
501505
.filter((route) => !isWorkspaceOverlayRoute(route.name)),
502506
);
503-
const draftRoute = props.state.routes.findLast((route) => route.name === "Thread");
507+
// The flow follows the draft route even while a pushed Thread covers it, so
508+
// its state lives exactly as long as the route.
509+
const draftRoute = props.state.routes.findLast(isDraftThreadRoute);
510+
const draftRouteOnTop =
511+
draftRoute !== undefined &&
512+
props.state.routes.findLast((route) => route.name === "Thread") === draftRoute;
504513
const draftParams = (
505514
draftRoute?.params as { draft?: { draftId?: string | string[] } } | undefined
506515
)?.draft;
@@ -509,7 +518,11 @@ function RootStackLayout(props: {
509518
: draftParams?.draftId;
510519

511520
return (
512-
<NewTaskFlowProvider active={isDraftThreadRoute(draftRoute)} routeDraftId={routeDraftId}>
521+
<NewTaskFlowProvider
522+
active={draftRouteOnTop}
523+
flowKey={draftRoute === undefined ? undefined : newTaskFlowKey(draftRoute)}
524+
routeDraftId={routeDraftId}
525+
>
513526
<HardwareKeyboardCommandProvider pathname={pathname}>
514527
<ShowcaseCaptureCoordinator pathname={pathname} />
515528
<SettingsEnvironmentFilterProvider open={settingsOpen}>
@@ -518,6 +531,8 @@ function RootStackLayout(props: {
518531
<AdaptiveWorkspaceLayout
519532
pathname={workspaceLocation.pathname}
520533
workspaceRouteKey={workspaceLocation.routeKey}
534+
workspaceRouteName={workspaceLocation.routeName}
535+
workspaceRouteKeys={workspaceLocation.routeKeys}
521536
selectedPullRequestKey={selectedPullRequestKey(props.state)}
522537
>
523538
{props.children}

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/files
44
import { environmentSession } from "../../state/session";
55
import { NativeStackScreenOptions } from "../../native/StackHeader";
66
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
7-
import { useEffect, useId, useRef, useState } from "react";
7+
import { useId, useState } from "react";
88
import { Platform, View } from "react-native";
99
import { useSafeAreaInsets } from "react-native-safe-area-context";
1010
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
@@ -431,14 +431,13 @@ function FilesToolbarBottomFade() {
431431
export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
432432
useAdaptiveWorkspacePaneRole("inspector");
433433
const navigation = useNavigation();
434-
const { fileInspector, layout, showAuxiliaryPane } = useAdaptiveWorkspaceLayout();
434+
const { fileInspector, layout } = useAdaptiveWorkspaceLayout();
435435
const [searchQuery, setSearchQuery] = useState("");
436436
const { themeAppearance: highlightTheme } = useAppearancePreferences();
437437
const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
438438
props.route.params,
439439
);
440440
const hasFileInspector = fileInspector.supported && threadId !== null;
441-
const revealedInspectorRef = useRef(false);
442441
const fileAccessSession = useEnvironmentQuery(
443442
environmentId !== null ? environmentSession.sessionStateAtom(environmentId) : null,
444443
);
@@ -511,13 +510,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
511510
theme: highlightTheme,
512511
});
513512
};
514-
useEffect(() => {
515-
if (hasFileInspector && cwd !== null && !revealedInspectorRef.current) {
516-
revealedInspectorRef.current = true;
517-
showAuxiliaryPane("inspector");
518-
}
519-
}, [cwd, hasFileInspector, showAuxiliaryPane]);
520-
521513
if (environmentId === null || (threadId !== null && selectedThread === null)) {
522514
if (hasFileInspector) {
523515
return (

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3too
1010
import { useAtomValue } from "@effect/atom-react";
1111
import { useFocusEffect } from "@react-navigation/native";
1212
import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
13-
import {
14-
use,
15-
useDeferredValue,
16-
useEffect,
17-
useEffectEvent,
18-
useMemo,
19-
useRef,
20-
useState,
21-
type ReactNode,
22-
} from "react";
13+
import { use, useDeferredValue, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
2314
import { Keyboard, Platform, useWindowDimensions, View } from "react-native";
2415
import { KeyboardController, useKeyboardState } from "react-native-keyboard-controller";
2516
import Animated, {
@@ -45,6 +36,7 @@ import { scopedThreadKey } from "../../lib/scopedEntities";
4536
import type { ThreadListFilters } from "../../persistence/mobile-preferences";
4637
import { appAtomRegistry } from "../../state/atom-registry";
4738
import { useProjects } from "../../state/entities";
39+
import { useThreadCwd } from "../../state/use-selected-thread-worktree";
4840
import { environmentThreadShells } from "../../state/threads";
4941
import { mobilePreferencesAtom } from "../../state/preferences";
5042
import {
@@ -128,46 +120,20 @@ export function useRegisterWorkspaceInspector(render: (() => ReactNode) | undefi
128120
);
129121
})();
130122

131-
const focusedRef = useRef(false);
132-
const deactivateRef = useRef<(() => void) | null>(null);
133-
134-
const syncRegistration = useEffectEvent(() => {
135-
if (!focusedRef.current || wrappedRender === undefined) {
136-
deactivateRef.current?.();
137-
return;
138-
}
139-
deactivateRef.current = registerWorkspaceInspector(wrappedRender);
140-
});
141-
142-
useFocusEffect(() => {
143-
focusedRef.current = true;
144-
syncRegistration();
145-
return () => {
146-
focusedRef.current = false;
147-
syncRegistration();
148-
};
149-
});
150-
151-
useEffect(() => {
152-
if (focusedRef.current) {
153-
syncRegistration();
154-
}
155-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Changed pane content replaces its existing native workspace registration.
156-
}, [wrappedRender]);
157-
158-
useEffect(
159-
() => () => {
160-
deactivateRef.current?.();
161-
deactivateRef.current = null;
162-
},
163-
[],
123+
// useFocusEffect re-runs when the renderer changes while focused, so the
124+
// pane always shows this render's content, and its cleanup deactivates on
125+
// blur and unmount.
126+
useFocusEffect(() =>
127+
wrappedRender === undefined ? undefined : registerWorkspaceInspector(wrappedRender),
164128
);
165129
}
166130

167131
export function AdaptiveWorkspaceLayout(props: {
168132
readonly children: ReactNode;
169133
readonly pathname: string;
170134
readonly workspaceRouteKey: string | undefined;
135+
readonly workspaceRouteName: string | undefined;
136+
readonly workspaceRouteKeys: ReadonlyArray<string>;
171137
readonly selectedPullRequestKey?: string | null;
172138
}) {
173139
const preferencesResult = useAtomValue(mobilePreferencesAtom);
@@ -194,6 +160,8 @@ function AdaptiveWorkspaceLayoutContent(
194160
readonly children: ReactNode;
195161
readonly pathname: string;
196162
readonly workspaceRouteKey: string | undefined;
163+
readonly workspaceRouteName: string | undefined;
164+
readonly workspaceRouteKeys: ReadonlyArray<string>;
197165
readonly selectedPullRequestKey?: string | null;
198166
} & {
199167
readonly projectGroupingMode: SidebarProjectGroupingMode;
@@ -348,16 +316,52 @@ function AdaptiveWorkspaceLayoutContent(
348316
const activeThread = parseActiveThreadPath(pathname);
349317
const environmentId = activeThread?.environmentId ?? null;
350318
const threadId = activeThread?.threadId ?? null;
351-
const selectedThreadKey = (() => {
319+
const selectedThreadRef = (() => {
352320
if (environmentId === null || threadId === null) {
353321
return null;
354322
}
355323
try {
356-
return scopedThreadKey(EnvironmentId.make(environmentId), ThreadId.make(threadId));
324+
return {
325+
environmentId: EnvironmentId.make(environmentId),
326+
threadId: ThreadId.make(threadId),
327+
};
357328
} catch {
358329
return null;
359330
}
360331
})();
332+
const selectedThreadKey =
333+
selectedThreadRef === null
334+
? null
335+
: scopedThreadKey(selectedThreadRef.environmentId, selectedThreadRef.threadId);
336+
const isFilesRoute = props.workspaceRouteName === "ThreadFiles";
337+
// Same resolution the Files screen uses: without a cwd it shows "Files unavailable" and
338+
// registers no inspector, so revealing would only hide the sidebar beside that screen.
339+
const filesCwd = useThreadCwd(isFilesRoute && fileInspector.supported ? selectedThreadRef : null);
340+
// Opening a review or the files route reveals its inspector once per route and thread.
341+
// Routes still on the stack remember their reveal, so going back to one keeps the user's choice.
342+
const revealsInspector =
343+
props.workspaceRouteName === "ThreadReview" || (isFilesRoute && filesCwd !== null);
344+
const [revealedInspectors, setRevealedInspectors] = useState<ReadonlyMap<string, string>>(
345+
() => new Map(),
346+
);
347+
if (
348+
revealsInspector &&
349+
props.workspaceRouteKey !== undefined &&
350+
selectedThreadKey !== null &&
351+
revealedInspectors.get(props.workspaceRouteKey) !== selectedThreadKey
352+
) {
353+
const next = new Map<string, string>();
354+
for (const routeKey of props.workspaceRouteKeys) {
355+
const revealedThreadKey = revealedInspectors.get(routeKey);
356+
if (revealedThreadKey !== undefined) {
357+
next.set(routeKey, revealedThreadKey);
358+
}
359+
}
360+
next.set(props.workspaceRouteKey, selectedThreadKey);
361+
setRevealedInspectors(next);
362+
setFocusedAuxiliaryPaneRole("inspector");
363+
setFileInspectorPreferredVisible(true);
364+
}
361365
const [workspaceInspector, setWorkspaceInspector] = useState<{
362366
readonly render: () => ReactNode;
363367
readonly active: boolean;

0 commit comments

Comments
 (0)