Skip to content

Commit 2ea4218

Browse files
authored
Merge branch 'main' into fix/claude-macos-keychain-config-dir
2 parents 1e9b2fa + 0418301 commit 2ea4218

16 files changed

Lines changed: 581 additions & 72 deletions

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
getAppBranding,
3636
getLocalEnvironmentBootstraps,
3737
getLocalEnvironmentBearerToken,
38+
getWindowFullscreenState,
3839
openExternal,
3940
pickFolder,
4041
setTheme,
@@ -48,6 +49,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
4849
yield* PreviewIpc.installPreviewEventForwarding();
4950

5051
yield* ipc.handleSync(getAppBranding);
52+
yield* ipc.handleSync(getWindowFullscreenState);
5153
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
5254
yield* ipc.handle(getLocalEnvironmentBearerToken);
5355

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const SET_THEME_CHANNEL = "desktop:set-theme";
44
export const CONTEXT_MENU_CHANNEL = "desktop:context-menu";
55
export const OPEN_EXTERNAL_CHANNEL = "desktop:open-external";
66
export const MENU_ACTION_CHANNEL = "desktop:menu-action";
7+
export const GET_WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:get-window-fullscreen-state";
8+
export const WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:window-fullscreen-state";
79
export const UPDATE_STATE_CHANNEL = "desktop:update-state";
810
export const UPDATE_GET_STATE_CHANNEL = "desktop:update-get-state";
911
export const UPDATE_SET_CHANNEL_CHANNEL = "desktop:update-set-channel";

‎apps/desktop/src/ipc/methods/window.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { assert, describe, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
3+
import * as Layer from "effect/Layer";
34
import * as Option from "effect/Option";
45

6+
import type * as Electron from "electron";
7+
58
import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
69
import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts";
7-
import { getLocalEnvironmentBootstraps } from "./window.ts";
10+
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
11+
import { getLocalEnvironmentBootstraps, getWindowFullscreenState } from "./window.ts";
812

913
const readyWslConfig: DesktopBackendManager.DesktopBackendStartConfig = {
1014
executablePath: "wsl.exe",
@@ -126,3 +130,19 @@ describe("getLocalEnvironmentBootstraps", () => {
126130
}).pipe(Effect.provide(DesktopBackendPool.layerTest([stoppedInstance])));
127131
});
128132
});
133+
134+
describe("getWindowFullscreenState", () => {
135+
it.effect("reads the current native window state", () => {
136+
const window = { isFullScreen: () => true } as Electron.BrowserWindow;
137+
138+
return Effect.gen(function* () {
139+
assert.isTrue(yield* getWindowFullscreenState.handler());
140+
}).pipe(
141+
Effect.provide(
142+
Layer.mock(ElectronWindow.ElectronWindow)({
143+
currentMainOrFirst: Effect.succeed(Option.some(window)),
144+
}),
145+
),
146+
);
147+
});
148+
});

‎apps/desktop/src/ipc/methods/window.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export const getAppBranding = DesktopIpc.makeSyncIpcMethod({
5555
}),
5656
});
5757

58+
export const getWindowFullscreenState = DesktopIpc.makeSyncIpcMethod({
59+
channel: IpcChannels.GET_WINDOW_FULLSCREEN_STATE_CHANNEL,
60+
result: Schema.Boolean,
61+
handler: Effect.fn("desktop.ipc.window.getWindowFullscreenState")(function* () {
62+
const electronWindow = yield* ElectronWindow.ElectronWindow;
63+
const window = yield* electronWindow.currentMainOrFirst;
64+
return Option.isSome(window) && window.value.isFullScreen();
65+
}),
66+
});
67+
5868
export const getLocalEnvironmentBootstraps = DesktopIpc.makeSyncIpcMethod({
5969
channel: IpcChannels.GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL,
6070
result: Schema.Array(DesktopEnvironmentBootstrapSchema),

‎apps/desktop/src/preload.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ contextBridge.exposeInMainWorld("desktopBridge", {
116116
ipcRenderer.removeListener(IpcChannels.MENU_ACTION_CHANNEL, wrappedListener);
117117
};
118118
},
119+
getWindowFullscreenState: () =>
120+
ipcRenderer.sendSync(IpcChannels.GET_WINDOW_FULLSCREEN_STATE_CHANNEL) === true,
121+
onWindowFullscreenStateChange: (listener) => {
122+
const wrappedListener = (_event: Electron.IpcRendererEvent, fullscreen: unknown) => {
123+
if (typeof fullscreen !== "boolean") return;
124+
listener(fullscreen);
125+
};
126+
127+
ipcRenderer.on(IpcChannels.WINDOW_FULLSCREEN_STATE_CHANNEL, wrappedListener);
128+
return () => {
129+
ipcRenderer.removeListener(IpcChannels.WINDOW_FULLSCREEN_STATE_CHANNEL, wrappedListener);
130+
};
131+
},
119132
getUpdateState: () => ipcRenderer.invoke(IpcChannels.UPDATE_GET_STATE_CHANNEL),
120133
setUpdateChannel: (channel) =>
121134
ipcRenderer.invoke(IpcChannels.UPDATE_SET_CHANNEL_CHANNEL, channel),

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as ElectronMenu from "../electron/ElectronMenu.ts";
2828
import * as ElectronShell from "../electron/ElectronShell.ts";
2929
import * as ElectronTheme from "../electron/ElectronTheme.ts";
3030
import * as ElectronWindow from "../electron/ElectronWindow.ts";
31-
import { MENU_ACTION_CHANNEL } from "../ipc/channels.ts";
31+
import { MENU_ACTION_CHANNEL, WINDOW_FULLSCREEN_STATE_CHANNEL } from "../ipc/channels.ts";
3232
import * as DesktopServerExposure from "../backend/DesktopServerExposure.ts";
3333
import * as DesktopWindow from "./DesktopWindow.ts";
3434
import * as PreviewManager from "../preview/Manager.ts";
@@ -46,6 +46,7 @@ const environmentInput = {
4646
} satisfies DesktopEnvironment.MakeDesktopEnvironmentInput;
4747

4848
function makeFakeBrowserWindow() {
49+
const windowListeners = new Map<string, (...args: readonly unknown[]) => void>();
4950
const webContentsListeners = new Map<string, (...args: readonly unknown[]) => void>();
5051
const webContents = {
5152
copyImageAt: vi.fn(),
@@ -66,10 +67,13 @@ function makeFakeBrowserWindow() {
6667
close: vi.fn(),
6768
focus: vi.fn(),
6869
isDestroyed: vi.fn(() => false),
70+
isFullScreen: vi.fn(() => false),
6971
isMinimized: vi.fn(() => false),
7072
isVisible: vi.fn(() => true),
7173
loadURL: vi.fn(() => Promise.resolve()),
72-
on: vi.fn(),
74+
on: vi.fn((eventName: string, listener: (...args: readonly unknown[]) => void) => {
75+
windowListeners.set(eventName, listener);
76+
}),
7377
once: vi.fn(),
7478
restore: vi.fn(),
7579
setBackgroundColor: vi.fn(),
@@ -88,6 +92,7 @@ function makeFakeBrowserWindow() {
8892
send: webContents.send,
8993
setAutoHideCursor: window.setAutoHideCursor,
9094
webContentsListeners,
95+
windowListeners,
9196
};
9297
}
9398

@@ -338,6 +343,37 @@ describe("DesktopWindow", () => {
338343
}),
339344
);
340345

346+
it.effect("publishes native macOS fullscreen changes to the renderer", () =>
347+
Effect.gen(function* () {
348+
const fakeWindow = makeFakeBrowserWindow();
349+
const createCount = yield* Ref.make(0);
350+
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
351+
const layer = makeTestLayer({
352+
window: fakeWindow.window,
353+
createCount,
354+
mainWindow,
355+
});
356+
357+
yield* Effect.gen(function* () {
358+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
359+
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
360+
361+
const enterFullscreen = fakeWindow.windowListeners.get("enter-full-screen");
362+
const leaveFullscreen = fakeWindow.windowListeners.get("leave-full-screen");
363+
if (!enterFullscreen || !leaveFullscreen) {
364+
return yield* Effect.die("fullscreen listeners were not registered");
365+
}
366+
367+
enterFullscreen();
368+
leaveFullscreen();
369+
assert.deepEqual(fakeWindow.send.mock.calls, [
370+
[WINDOW_FULLSCREEN_STATE_CHANNEL, true],
371+
[WINDOW_FULLSCREEN_STATE_CHANNEL, false],
372+
]);
373+
}).pipe(Effect.provide(layer));
374+
}),
375+
);
376+
341377
it.effect("recovers when the development renderer is temporarily unreachable", () =>
342378
Effect.gen(function* () {
343379
const fakeWindow = makeFakeBrowserWindow();

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getDesktopUrl } from "../electron/ElectronProtocol.ts";
1515
import * as ElectronShell from "../electron/ElectronShell.ts";
1616
import * as ElectronTheme from "../electron/ElectronTheme.ts";
1717
import * as ElectronWindow from "../electron/ElectronWindow.ts";
18-
import { MENU_ACTION_CHANNEL } from "../ipc/channels.ts";
18+
import { MENU_ACTION_CHANNEL, WINDOW_FULLSCREEN_STATE_CHANNEL } from "../ipc/channels.ts";
1919
import * as PreviewManager from "../preview/Manager.ts";
2020

2121
const TITLEBAR_HEIGHT = 40;
@@ -365,6 +365,15 @@ export const make = Effect.gen(function* () {
365365
window.setTitle(environment.displayName);
366366
});
367367

368+
if (environment.platform === "darwin") {
369+
window.on("enter-full-screen", () => {
370+
window.webContents.send(WINDOW_FULLSCREEN_STATE_CHANNEL, true);
371+
});
372+
window.on("leave-full-screen", () => {
373+
window.webContents.send(WINDOW_FULLSCREEN_STATE_CHANNEL, false);
374+
});
375+
}
376+
368377
let developmentLoadRetryIndex = 0;
369378
let developmentLoadRetryFiber: Fiber.Fiber<void, never> | undefined;
370379
const clearDevelopmentLoadRetry = () => {
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import type { NativeReviewDiffRow } from "./nativeReviewDiffSurface";
4+
import type { NativeReviewDiffFile } from "./nativeReviewDiffTypes";
5+
import { highlightNativeReviewDiffVisibleRows } from "./nativeReviewDiffHighlighter";
6+
7+
const TYPESCRIPT_FILE: NativeReviewDiffFile = {
8+
id: "file-1",
9+
path: "example.ts",
10+
language: "typescript",
11+
additions: 0,
12+
deletions: 0,
13+
};
14+
15+
function makeLine(
16+
input: Pick<NativeReviewDiffRow, "id" | "content" | "change" | "oldLineNumber" | "newLineNumber">,
17+
): NativeReviewDiffRow {
18+
return {
19+
kind: "line",
20+
fileId: TYPESCRIPT_FILE.id,
21+
...input,
22+
};
23+
}
24+
25+
function makeHunk(id: string): NativeReviewDiffRow {
26+
return {
27+
kind: "hunk",
28+
id,
29+
fileId: TYPESCRIPT_FILE.id,
30+
text: "@@",
31+
};
32+
}
33+
34+
function highlight(
35+
rows: ReadonlyArray<NativeReviewDiffRow>,
36+
alreadyHighlightedRowIds?: ReadonlySet<string>,
37+
) {
38+
return highlightNativeReviewDiffVisibleRows({
39+
rows,
40+
files: [TYPESCRIPT_FILE],
41+
scheme: "dark",
42+
engine: "javascript",
43+
firstRowIndex: 0,
44+
lastRowIndex: rows.length - 1,
45+
overscanRows: 0,
46+
maxRows: 100,
47+
alreadyHighlightedRowIds,
48+
});
49+
}
50+
51+
describe("highlightNativeReviewDiffVisibleRows", () => {
52+
it("does not carry grammar state across hunk boundaries", async () => {
53+
const exportRow = makeLine({
54+
id: "export-row",
55+
content: "export async function run() {}",
56+
change: "add",
57+
oldLineNumber: null,
58+
newLineNumber: 100,
59+
});
60+
const rows = [
61+
makeHunk("hunk-1"),
62+
makeLine({
63+
id: "import-open",
64+
content: "import {",
65+
change: "context",
66+
oldLineNumber: 1,
67+
newLineNumber: 1,
68+
}),
69+
makeLine({
70+
id: "import-entry",
71+
content: " Model,",
72+
change: "context",
73+
oldLineNumber: 2,
74+
newLineNumber: 2,
75+
}),
76+
makeHunk("hunk-2"),
77+
exportRow,
78+
];
79+
80+
const [highlighted, standalone] = await Promise.all([
81+
highlight(rows),
82+
highlight([makeHunk("standalone-hunk"), exportRow]),
83+
]);
84+
85+
expect(highlighted.tokensByRowId[exportRow.id]).toEqual(standalone.tokensByRowId[exportRow.id]);
86+
});
87+
88+
it("keeps grammar state across inline comment rows", async () => {
89+
const openingRow = makeLine({
90+
id: "template-open",
91+
content: "const message = `open",
92+
change: "add",
93+
oldLineNumber: null,
94+
newLineNumber: 1,
95+
});
96+
const closingRow = makeLine({
97+
id: "template-close",
98+
content: "closed`;",
99+
change: "add",
100+
oldLineNumber: null,
101+
newLineNumber: 2,
102+
});
103+
const trailingRow = makeLine({
104+
id: "trailing-row",
105+
content: "export const answer = 42;",
106+
change: "add",
107+
oldLineNumber: null,
108+
newLineNumber: 3,
109+
});
110+
const commentRow: NativeReviewDiffRow = {
111+
kind: "comment",
112+
id: "comment-1",
113+
fileId: TYPESCRIPT_FILE.id,
114+
commentText: "Review note",
115+
};
116+
117+
const [withComment, contiguous] = await Promise.all([
118+
highlight([openingRow, commentRow, closingRow, trailingRow]),
119+
highlight([openingRow, closingRow, trailingRow]),
120+
]);
121+
122+
expect(withComment.tokensByRowId).toEqual(contiguous.tokensByRowId);
123+
});
124+
125+
it("does not join unhighlighted rows across cached gaps", async () => {
126+
const trailingRow = makeLine({
127+
id: "trailing-row",
128+
content: "export const answer = 42;",
129+
change: "add",
130+
oldLineNumber: null,
131+
newLineNumber: 3,
132+
});
133+
const rows = [
134+
makeLine({
135+
id: "template-open",
136+
content: "const message = `open",
137+
change: "add",
138+
oldLineNumber: null,
139+
newLineNumber: 1,
140+
}),
141+
makeLine({
142+
id: "template-close",
143+
content: "closed`;",
144+
change: "add",
145+
oldLineNumber: null,
146+
newLineNumber: 2,
147+
}),
148+
trailingRow,
149+
];
150+
151+
const [highlighted, standalone] = await Promise.all([
152+
highlight(rows, new Set(["template-close"])),
153+
highlight([trailingRow]),
154+
]);
155+
156+
expect(highlighted.tokensByRowId[trailingRow.id]).toEqual(
157+
standalone.tokensByRowId[trailingRow.id],
158+
);
159+
});
160+
161+
it("keeps deletion grammar state out of addition rows", async () => {
162+
const additionRow = makeLine({
163+
id: "addition-row",
164+
content: "export const answer = 42;",
165+
change: "add",
166+
oldLineNumber: null,
167+
newLineNumber: 1,
168+
});
169+
const rows = [
170+
makeLine({
171+
id: "deletion-row",
172+
content: "const removed = `open",
173+
change: "delete",
174+
oldLineNumber: 1,
175+
newLineNumber: null,
176+
}),
177+
additionRow,
178+
];
179+
180+
const [highlighted, standalone] = await Promise.all([
181+
highlight(rows),
182+
highlight([additionRow]),
183+
]);
184+
185+
expect(highlighted.tokensByRowId[additionRow.id]).toEqual(
186+
standalone.tokensByRowId[additionRow.id],
187+
);
188+
});
189+
});

0 commit comments

Comments
 (0)