Skip to content

Commit cd5bab0

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-33482
2 parents 4532374 + 6e4711d commit cd5bab0

65 files changed

Lines changed: 1721 additions & 500 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: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import * as Deferred from "effect/Deferred";
44
import * as Effect from "effect/Effect";
55
import * as Layer from "effect/Layer";
66

7-
import type * as Electron from "electron";
7+
import * as Electron from "electron";
8+
import { vi } from "vite-plus/test";
9+
10+
vi.mock("electron", () => ({
11+
webContents: { getAllWebContents: vi.fn(() => []) },
12+
}));
813

914
import * as ElectronApp from "../electron/ElectronApp.ts";
1015
import * as ElectronDialog from "../electron/ElectronDialog.ts";
@@ -227,10 +232,32 @@ describe("DesktopApplicationMenu", () => {
227232
items.find((item) => item.role === "windowMenu" && item.submenu === undefined),
228233
platform,
229234
);
230-
assert.isUndefined(
231-
items.find((item) => item.accelerator?.toLowerCase().endsWith("+w")),
232-
platform,
233-
);
235+
const closeTools = items.find((item) => item.accelerator === "CmdOrCtrl+W");
236+
assert.equal(closeTools?.label, "Close Developer Tools", platform);
237+
assert.isFunction(closeTools?.click);
238+
const appContents = {
239+
isDestroyed: () => false,
240+
isDevToolsFocused: () => false,
241+
closeDevTools: vi.fn(),
242+
};
243+
const inspectedContents = {
244+
...appContents,
245+
isDevToolsFocused: () => true,
246+
closeDevTools: vi.fn(),
247+
};
248+
using allContents = vi
249+
.spyOn(Electron.webContents, "getAllWebContents")
250+
.mockReturnValue([
251+
appContents as unknown as Electron.WebContents,
252+
inspectedContents as unknown as Electron.WebContents,
253+
]);
254+
closeTools?.click?.({} as Electron.MenuItem, undefined, {} as KeyboardEvent);
255+
assert.equal(inspectedContents.closeDevTools.mock.calls.length, 1);
256+
assert.equal(appContents.closeDevTools.mock.calls.length, 0);
257+
258+
allContents.mockReturnValue([appContents as unknown as Electron.WebContents]);
259+
closeTools?.click?.({} as Electron.MenuItem, undefined, {} as KeyboardEvent);
260+
assert.equal(appContents.closeDevTools.mock.calls.length, 0);
234261
}
235262
}),
236263
);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Layer from "effect/Layer";
44
import * as Option from "effect/Option";
55
import * as Schema from "effect/Schema";
66

7-
import type * as Electron from "electron";
7+
import * as Electron from "electron";
88

99
import { makeComponentLogger } from "../app/DesktopObservability.ts";
1010
import * as ElectronDialog from "../electron/ElectronDialog.ts";
@@ -200,6 +200,17 @@ export const make = Effect.gen(function* () {
200200
},
201201
{ type: "separator" as const },
202202
]),
203+
{
204+
label: "Close Developer Tools",
205+
accelerator: "CmdOrCtrl+W",
206+
visible: false,
207+
click: () => {
208+
Electron.webContents
209+
.getAllWebContents()
210+
.find((contents) => !contents.isDestroyed() && contents.isDevToolsFocused())
211+
?.closeDevTools();
212+
},
213+
},
203214
// Cmd/Ctrl+W belongs to the renderer's tab close; it must never close the window.
204215
environment.platform === "darwin"
205216
? { label: "Close Window", click: (_item, window) => window?.close() }

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function makeFakeBrowserWindow() {
9494
replaceMisspelling: vi.fn(),
9595
send: vi.fn(),
9696
setBackgroundThrottling: vi.fn(),
97+
setIgnoreMenuShortcuts: vi.fn(),
9798
setWindowOpenHandler: vi.fn(),
9899
toggleDevTools: vi.fn(),
99100
};
@@ -143,6 +144,7 @@ function makeFakeBrowserWindow() {
143144
reloadIgnoringCache: webContents.reloadIgnoringCache,
144145
toggleDevTools: webContents.toggleDevTools,
145146
navigationHistory: webContents.navigationHistory,
147+
setIgnoreMenuShortcuts: webContents.setIgnoreMenuShortcuts,
146148
send: webContents.send,
147149
setZoomLevel: webContents.setZoomLevel,
148150
setWindowButtonPosition: window.setWindowButtonPosition,
@@ -646,7 +648,7 @@ describe("DesktopWindow", () => {
646648
}),
647649
);
648650

649-
it.effect("blocks only repeated Cmd+W input before it reaches the native window menu", () =>
651+
it.effect("leaves Cmd+W to the renderer and blocks repeated presses", () =>
650652
Effect.gen(function* () {
651653
const fakeWindow = makeFakeBrowserWindow();
652654
const createCount = yield* Ref.make(0);
@@ -687,6 +689,13 @@ describe("DesktopWindow", () => {
687689
prevented = false;
688690
beforeInput(event, { ...input, meta: false });
689691
assert.isFalse(prevented);
692+
693+
assert.deepEqual(
694+
fakeWindow.setIgnoreMenuShortcuts.mock.calls.map(([ignore]) => ignore),
695+
[true, true, false],
696+
);
697+
beforeInput(event, { ...input, key: "r", isAutoRepeat: false });
698+
assert.isFalse(fakeWindow.setIgnoreMenuShortcuts.mock.lastCall?.[0]);
690699
}).pipe(Effect.provide(layer));
691700
}),
692701
);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ export const make = Effect.gen(function* () {
677677
});
678678
window.webContents.on("before-input-event", (event, input) => {
679679
quitShortcutHandler(event, input);
680+
// Cmd/Ctrl+W reaches the renderer; DevTools uses the native menu shortcut.
681+
window.webContents.setIgnoreMenuShortcuts(
682+
(environment.platform === "darwin" ? input.meta : input.control) &&
683+
!input.alt &&
684+
!input.shift &&
685+
input.key.toLowerCase() === "w",
686+
);
680687
// A held Cmd/Ctrl+W closes one tab or terminal, not each one behind it.
681688
if (input.type !== "keyDown" || !input.isAutoRepeat) return;
682689
const modifier = environment.platform === "darwin" ? input.meta : input.control;

‎apps/mobile/app.config.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ const config: ExpoConfig = {
326326
},
327327
plugins: [
328328
"expo-asset",
329-
"react-native-pdf-jsi",
330329
[
331330
"expo-font",
332331
{

‎apps/mobile/package.json‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"@pierre/diffs": "catalog:",
6464
"@pierre/highlights": "catalog:",
6565
"@react-native-ai/apple": "0.12.0",
66-
"@react-native-async-storage/async-storage": "3.1.1",
6766
"@react-native-menu/menu": "^2.0.0",
6867
"@react-navigation/elements": "2.9.45",
6968
"@react-navigation/native": "7.5.1",
@@ -121,13 +120,12 @@
121120
"react": "catalog:",
122121
"react-dom": "catalog:",
123122
"react-native": "0.88.1",
124-
"react-native-blob-util": "0.25.1",
125123
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-t3.18-497fbe63.tgz",
126-
"react-native-gesture-handler": "~3.3.0",
124+
"react-native-gesture-handler": "~3.5.0",
127125
"react-native-image-viewing": "^0.2.2",
128-
"react-native-keyboard-controller": "1.22.8",
126+
"react-native-keyboard-controller": "1.23.0",
129127
"react-native-nitro-modules": "0.37.2",
130-
"react-native-pdf-jsi": "5.0.0",
128+
"react-native-pdf-jsi": "6.1.0",
131129
"react-native-reanimated": "4.7.1",
132130
"react-native-safe-area-context": "~5.11.1",
133131
"react-native-screens": "file:deps/react-native-screens-5.0.0-t3.48.tgz",
@@ -164,6 +162,7 @@
164162
"react-native-keyboard-controller",
165163
"react-native-screens",
166164
"react-native-enriched-markdown",
165+
"react-native-gesture-handler",
167166
"react-native-svg",
168167
"react-native-worklets"
169168
]
@@ -180,7 +179,12 @@
180179
"expo-video",
181180
"expo-network",
182181
"expo-sharing"
183-
]
182+
],
183+
"ios": {
184+
"exclude": [
185+
"react-native-pdf-jsi"
186+
]
187+
}
184188
}
185189
},
186190
"reanimated": {

‎apps/mobile/src/components/PdfPreview.android.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ export function PdfPreview(props: { readonly uri: string }) {
7272
return (
7373
<Pdf
7474
source={{ uri: localUri }}
75-
page={pdfInitialPage(props.uri)}
76-
fitPolicy={0}
77-
trustAllCerts={false}
75+
initialPage={pdfInitialPage(props.uri) - 1}
7876
enableAnnotationRendering
7977
enableDoubleTapZoom
80-
onPressLink={(href) => {
78+
onLinkPress={({ url: href }) => {
8179
const url = pdfLinkUrl(href, props.uri);
8280
if (url !== null) void tryOpenExternalUrl(url, "file-preview");
8381
}}

‎apps/mobile/src/connection/environment-cache-store.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ORCHESTRATION_CACHE_SCHEMA_VERSION,
33
ORCHESTRATION_THREAD_CACHE_SCHEMA_VERSION,
44
COMPACT_THREAD_CACHE_SCHEMA_VERSION,
5+
type ConnectionPersistenceError,
56
StoredOrchestrationThreadSnapshot,
67
} from "@t3tools/client-runtime/platform";
78
import {
@@ -19,6 +20,7 @@ import {
1920
import { describe, expect, it } from "@effect/vitest";
2021
import * as DateTime from "effect/DateTime";
2122
import * as Effect from "effect/Effect";
23+
import * as Fiber from "effect/Fiber";
2224
import * as Logger from "effect/Logger";
2325
import * as Option from "effect/Option";
2426
import * as Schema from "effect/Schema";
@@ -213,6 +215,35 @@ function threadSnapshotWithItems(): OrchestrationV2ThreadDetailSnapshot {
213215
};
214216
}
215217

218+
// More rows than one encoding chunk, so a cold save yields to the host mid-encode.
219+
function threadSnapshotWithManyItems(
220+
snapshotSequence: number,
221+
message = "A settled local notice.",
222+
): OrchestrationV2ThreadDetailSnapshot {
223+
const base = threadSnapshotWithItems();
224+
const turnItems = Array.from({ length: 40 }, (_, index) => ({
225+
...base.projection.turnItems[0]!,
226+
id: TurnItemId.make(`notice-${snapshotSequence}-${index}`),
227+
ordinal: index,
228+
message,
229+
}));
230+
return {
231+
...THREAD_SNAPSHOT,
232+
snapshotSequence,
233+
projection: {
234+
...THREAD_SNAPSHOT.projection,
235+
turnItems,
236+
visibleTurnItems: turnItems.map((item, position) => ({
237+
position,
238+
visibility: "local" as const,
239+
sourceThreadId: THREAD_ID,
240+
sourceItemId: item.id,
241+
item,
242+
})),
243+
},
244+
};
245+
}
246+
216247
function makeDatabase() {
217248
const values = new Map<string, string>();
218249
const schemaVersions = new Map<string, number>();
@@ -608,6 +639,53 @@ describe("mobile SQLite environment cache store", () => {
608639
}).pipe(Effect.provide(Logger.layer([logger], { mergeWithExisting: false })));
609640
});
610641

642+
it.effect("does not write a save that a removal, clear, or newer save overtook", () =>
643+
Effect.gen(function* () {
644+
const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
645+
const overtake = Effect.fn("overtake")(function* (
646+
later: (
647+
store: Effect.Success<ReturnType<typeof make>>,
648+
) => Effect.Effect<void, ConnectionPersistenceError>,
649+
) {
650+
const memory = makeDatabase();
651+
const store = yield* make().pipe(
652+
Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
653+
);
654+
const older = yield* store
655+
.saveThread(ENVIRONMENT_ID, threadSnapshotWithManyItems(1))
656+
.pipe(Effect.forkChild({ startImmediately: true }));
657+
yield* later(store);
658+
yield* Fiber.join(older);
659+
return { memory, store };
660+
});
661+
662+
const removed = yield* overtake((store) => store.removeThread(ENVIRONMENT_ID, THREAD_ID));
663+
expect(removed.memory.values.has(id)).toBe(false);
664+
const cleared = yield* overtake((store) => store.clear(ENVIRONMENT_ID));
665+
expect(cleared.memory.values.has(id)).toBe(false);
666+
const replaced = yield* overtake((store) =>
667+
store.saveThread(ENVIRONMENT_ID, { ...THREAD_SNAPSHOT, snapshotSequence: 2 }),
668+
);
669+
const kept = yield* replaced.store.loadThread(ENVIRONMENT_ID, THREAD_ID);
670+
expect(Option.getOrThrow(kept).snapshotSequence).toBe(2);
671+
}),
672+
);
673+
674+
it.effect("removes the older copy of a thread that grew past the cache limit", () =>
675+
Effect.gen(function* () {
676+
const memory = makeDatabase();
677+
const store = yield* make().pipe(
678+
Effect.provideService(MobileDatabase.MobileDatabase, memory.database),
679+
);
680+
const id = cacheId(ENVIRONMENT_ID, "thread", THREAD_ID);
681+
yield* store.saveThread(ENVIRONMENT_ID, threadSnapshotWithItems());
682+
expect(memory.values.has(id)).toBe(true);
683+
yield* store.saveThread(ENVIRONMENT_ID, threadSnapshotWithManyItems(2, "x".repeat(200_000)));
684+
expect(memory.values.has(id)).toBe(false);
685+
expect(memory.removed).toEqual([id]);
686+
}),
687+
);
688+
611689
it.effect("deletes a corrupt cache record and treats it as a miss", () =>
612690
Effect.gen(function* () {
613691
const memory = makeDatabase();

‎apps/mobile/src/connection/environment-cache-store.ts‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import {
22
ORCHESTRATION_CACHE_SCHEMA_VERSION,
33
COMPACT_THREAD_CACHE_SCHEMA_VERSION,
44
decodeStoredThreadSnapshot,
5-
encodeStoredThreadSnapshot,
65
Persistence,
76
makeStoredShellSnapshotEncoder,
7+
makeStoredThreadSnapshotEncoder,
8+
makeThreadCacheWriteOrder,
89
} from "@t3tools/client-runtime/platform";
910
import { type EnvironmentId, ServerConfig, VcsListRefsResult } from "@t3tools/contracts";
1011
import * as Effect from "effect/Effect";
@@ -96,6 +97,8 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
9697
const database = yield* MobileDatabase.MobileDatabase;
9798
attachProjectFaviconDatabase(database);
9899
const encodeStoredShellSnapshot = makeStoredShellSnapshotEncoder();
100+
const encodeStoredThreadSnapshot = makeStoredThreadSnapshotEncoder({ format: "compact" });
101+
const threadWriteOrder = makeThreadCacheWriteOrder();
99102
return Persistence.EnvironmentCacheStore.of({
100103
loadShell: Effect.fn("MobileEnvironmentCache.loadShell")((environmentId) =>
101104
loadDecodedCache({
@@ -156,20 +159,32 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
156159
),
157160
saveThread: Effect.fn("MobileEnvironmentCache.saveThread")(function* (environmentId, snapshot) {
158161
const threadId = snapshot.projection.thread.id;
162+
const isLatest = threadWriteOrder.beginSave(environmentId, threadId);
159163
const payload = yield* encodeStoredThreadSnapshot({
160164
environmentId,
161165
threadId,
162166
snapshot,
163167
}).pipe(Effect.mapError((cause) => persistenceError("save-thread", cause)));
164-
yield* database
165-
.saveCache(environmentId, "thread", threadId, COMPACT_THREAD_CACHE_SCHEMA_VERSION, payload)
166-
.pipe(Effect.mapError(mapDatabaseError("save-thread")));
168+
if (!isLatest()) return;
169+
// An older copy of a thread now too large to keep would paint stale on reopen.
170+
yield* Option.match(payload, {
171+
onNone: () => database.removeCache(environmentId, "thread", threadId),
172+
onSome: (encoded) =>
173+
database.saveCache(
174+
environmentId,
175+
"thread",
176+
threadId,
177+
COMPACT_THREAD_CACHE_SCHEMA_VERSION,
178+
encoded,
179+
),
180+
}).pipe(Effect.mapError(mapDatabaseError("save-thread")));
167181
}),
168-
removeThread: Effect.fn("MobileEnvironmentCache.removeThread")((environmentId, threadId) =>
169-
database
182+
removeThread: Effect.fn("MobileEnvironmentCache.removeThread")((environmentId, threadId) => {
183+
threadWriteOrder.removeThread(environmentId, threadId);
184+
return database
170185
.removeCache(environmentId, "thread", threadId)
171-
.pipe(Effect.mapError(mapDatabaseError("remove-thread"))),
172-
),
186+
.pipe(Effect.mapError(mapDatabaseError("remove-thread")));
187+
}),
173188
loadServerConfig: Effect.fn("MobileEnvironmentCache.loadServerConfig")((environmentId) =>
174189
loadDecodedCache({
175190
database,
@@ -237,12 +252,13 @@ export const make = Effect.fn("MobileEnvironmentCacheStore.make")(function* () {
237252
.clearCacheKind(environmentId, "vcs-refs")
238253
.pipe(Effect.mapError(mapDatabaseError("clear-vcs-refs"))),
239254
),
240-
clear: Effect.fn("MobileEnvironmentCache.clear")((environmentId) =>
241-
Effect.promise(() => projectFaviconDatabaseCache.clearEnvironment(environmentId)).pipe(
255+
clear: Effect.fn("MobileEnvironmentCache.clear")((environmentId) => {
256+
threadWriteOrder.clearEnvironment(environmentId);
257+
return Effect.promise(() => projectFaviconDatabaseCache.clearEnvironment(environmentId)).pipe(
242258
Effect.andThen(database.clearEnvironmentCache(environmentId)),
243259
Effect.mapError(mapDatabaseError("clear-environment")),
244-
),
245-
),
260+
);
261+
}),
246262
});
247263
});
248264

‎apps/mobile/src/features/home/thread-swipe-actions.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
391391
}
392392
}, [commitPrimaryAction, content, fullSwipeAction, onDelete]);
393393
const handleRelease = useCallback(
394-
(translation: SharedValue<number>) => {
394+
(translation: SharedValue<number>, canceled: boolean) => {
395395
"worklet";
396396
if (dismissing.value) return true;
397-
if (-translation.value >= fullSwipeThreshold) {
397+
if (!canceled && -translation.value >= fullSwipeThreshold) {
398398
runOnJS(commitFullSwipe)();
399399
return true;
400400
}

0 commit comments

Comments
 (0)