Skip to content

Commit 83b78f7

Browse files
Merge branch 'main' into fix/issue-33517
2 parents 401a856 + eb6e7fa commit 83b78f7

30 files changed

Lines changed: 271 additions & 173 deletions

‎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: 7 additions & 4 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",
126124
"react-native-gesture-handler": "~3.5.0",
127125
"react-native-image-viewing": "^0.2.2",
128126
"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",
@@ -181,7 +179,12 @@
181179
"expo-video",
182180
"expo-network",
183181
"expo-sharing"
184-
]
182+
],
183+
"ios": {
184+
"exclude": [
185+
"react-native-pdf-jsi"
186+
]
187+
}
185188
}
186189
},
187190
"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/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,10 @@ function AdaptiveWorkspaceLayoutContent(
245245
const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
246246
const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true);
247247
const [nativeInspectorWidthFraction, setNativeInspectorWidthFraction] = useState(0.4);
248+
const horizontalSafeArea =
249+
(nativeMetrics?.safeArea.left ?? 0) + (nativeMetrics?.safeArea.right ?? 0);
248250
const inspectorWidthFor = (fraction: number) =>
249-
nativeInspectorColumnWidth({
250-
viewportWidth,
251-
horizontalSafeArea:
252-
(nativeMetrics?.safeArea.left ?? 0) + (nativeMetrics?.safeArea.right ?? 0),
253-
fraction,
254-
});
251+
nativeInspectorColumnWidth({ viewportWidth, horizontalSafeArea, fraction });
255252
const nativeInspectorWidth = inspectorWidthFor(nativeInspectorWidthFraction);
256253
const [fileInspectorPreferredWidth, setFileInspectorPreferredWidth] = useState<number | null>(
257254
null,
@@ -408,6 +405,7 @@ function AdaptiveWorkspaceLayoutContent(
408405
deriveWorkspacePaneLayout({
409406
layout,
410407
viewportWidth: width,
408+
horizontalSafeArea,
411409
nativeWorkspace,
412410
primarySidebarFloats: sidebarFloats,
413411
primarySidebarPreferredVisible: showPrimarySidebar,
@@ -419,6 +417,7 @@ function AdaptiveWorkspaceLayoutContent(
419417
}),
420418
[
421419
nativeInspectorWidth,
420+
horizontalSafeArea,
422421
fileInspectorPreferredVisible,
423422
fileInspectorPreferredWidth,
424423
inspectorActive,
@@ -438,6 +437,7 @@ function AdaptiveWorkspaceLayoutContent(
438437
: deriveWorkspacePaneLayout({
439438
layout,
440439
viewportWidth: width,
440+
horizontalSafeArea,
441441
nativeWorkspace,
442442
primarySidebarFloats: sidebarFloats,
443443
primarySidebarPreferredVisible: sidebarWithoutKeyboard,
@@ -448,6 +448,7 @@ function AdaptiveWorkspaceLayoutContent(
448448
}).primarySidebarVisible,
449449
[
450450
nativeInspectorWidth,
451+
horizontalSafeArea,
451452
fileInspectorPreferredVisible,
452453
fileInspectorPreferredWidth,
453454
inspectorActive,

‎apps/mobile/src/features/threads/ThreadSettingsSheet.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,19 @@ function ThreadSettingsMainContent(props: {
913913
reportFailure: false,
914914
});
915915
const refreshProviderCatalog = createProviderCatalogRefreshRunner(refreshProvidersCommand);
916+
const registry = use(RegistryContext);
917+
const refreshModelCatalog = useEffectEvent(() => {
918+
const environmentId = session.environmentId;
919+
if (!environmentId) return;
920+
// An older server drops the field and probes every provider.
921+
const config = registry.get(environmentServerConfigsAtom).get(environmentId);
922+
if (config?.environment.capabilities.modelCatalogRefresh !== true) return;
923+
void refreshProvidersCommand({ environmentId, input: { modelCatalogOnly: true } });
924+
});
925+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- asks the server for newly released models when the model list opens
926+
useEffect(() => {
927+
refreshModelCatalog();
928+
}, []);
916929
const [isRefreshingProviders, setIsRefreshingProviders] = useState(false);
917930
const refreshProviders = () => {
918931
if (!session.environmentId || isRefreshingProviders) return;

‎apps/mobile/src/lib/layout.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,27 @@ describe("isPrimarySidebarPinned", () => {
155155

156156
describe("deriveWorkspacePaneLayout", () => {
157157
it.each([
158-
{ width: 1_194, height: 834, suppressed: false },
159-
{ width: 1_032, height: 1_376, suppressed: true },
158+
{ width: 1_194, height: 834, horizontalSafeArea: 0, fraction: 0.4, suppressed: false },
159+
{ width: 1_032, height: 1_376, horizontalSafeArea: 0, fraction: 0.4, suppressed: true },
160+
// The unfolded Duo's system bar leaves no room for the sidebar beside even the narrowest inspector.
161+
{ width: 951, height: 669, horizontalSafeArea: 76, fraction: 0, suppressed: true },
160162
])(
161163
"steps the sidebar aside for the native inspector only when the page gets too narrow ($width wide)",
162-
({ width, height, suppressed }) => {
164+
({ width, height, horizontalSafeArea, fraction, suppressed }) => {
163165
const layout = deriveLayout({ width, height });
164166
for (const primarySidebarPreferredVisible of [true, false]) {
165167
expect(
166168
deriveWorkspacePaneLayout({
167169
layout,
168170
viewportWidth: width,
171+
horizontalSafeArea,
169172
nativeWorkspace: true,
170173
primarySidebarPreferredVisible,
171174
auxiliaryPanePreferredVisible: true,
172175
nativeInspectorWidth: nativeInspectorColumnWidth({
173176
viewportWidth: width,
174-
horizontalSafeArea: 0,
175-
fraction: 0.4,
177+
horizontalSafeArea,
178+
fraction,
176179
}),
177180
}),
178181
).toMatchObject({

0 commit comments

Comments
 (0)