Skip to content

Commit c0fa553

Browse files
authored
Merge branch 'pingdotgg:main' into fix/resizable-file-explorer
2 parents b95096c + d1f7018 commit c0fa553

170 files changed

Lines changed: 17158 additions & 965 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/ipc/methods/window.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ vi.mock("electron", () => ({
2020
import * as DesktopBackendConfiguration from "../../backend/DesktopBackendConfiguration.ts";
2121
import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts";
2222
import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts";
23+
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
24+
import * as ElectronDialog from "../../electron/ElectronDialog.ts";
25+
import * as ElectronWindow from "../../electron/ElectronWindow.ts";
2326
import {
2427
getLocalEnvironmentBootstraps,
2528
getRelayTelemetryEnabled,
29+
pickProjectFavicon,
2630
probeRemoteEditors,
2731
} from "./window.ts";
2832

@@ -192,6 +196,78 @@ describe("getRelayTelemetryEnabled", () => {
192196
);
193197
});
194198

199+
describe("pickProjectFavicon", () => {
200+
const pickerLayer = (
201+
pickFiles: () => Effect.Effect<Array<string>>,
202+
settings?: DesktopAppSettings.DesktopSettings,
203+
) =>
204+
Layer.mergeAll(
205+
Layer.mock(ElectronDialog.ElectronDialog)({ pickFiles }),
206+
Layer.mock(ElectronWindow.ElectronWindow)({
207+
focusedMainOrFirst: Effect.succeedNone,
208+
}),
209+
DesktopAppSettings.layerTest(settings),
210+
);
211+
212+
it.effect("opens a single-image picker from the project directory", () =>
213+
Effect.gen(function* () {
214+
const pickFiles = vi.fn(() => Effect.succeed(["/pictures/icon.png"]));
215+
const result = yield* pickProjectFavicon
216+
.handler("/project")
217+
.pipe(Effect.provide(pickerLayer(pickFiles)));
218+
219+
assert.strictEqual(result, "/pictures/icon.png");
220+
assert.deepEqual(pickFiles.mock.calls, [
221+
[
222+
{
223+
owner: Option.none(),
224+
defaultPath: Option.some("/project"),
225+
multiple: false,
226+
filters: [
227+
{
228+
name: "Images",
229+
extensions: [
230+
"avif",
231+
"bmp",
232+
"gif",
233+
"ico",
234+
"heic",
235+
"heif",
236+
"jpeg",
237+
"jpg",
238+
"png",
239+
"svg",
240+
"tif",
241+
"tiff",
242+
"webp",
243+
"icns",
244+
],
245+
},
246+
],
247+
},
248+
],
249+
]);
250+
}),
251+
);
252+
253+
it.effect("does not open a picker while the local environment is off", () =>
254+
Effect.gen(function* () {
255+
const pickFiles = vi.fn(() => Effect.succeed(["/pictures/icon.png"]));
256+
const result = yield* pickProjectFavicon.handler("/project").pipe(
257+
Effect.provide(
258+
pickerLayer(pickFiles, {
259+
...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
260+
localEnvironmentEnabled: false,
261+
}),
262+
),
263+
);
264+
265+
assert.strictEqual(result, null);
266+
assert.strictEqual(pickFiles.mock.calls.length, 0);
267+
}),
268+
);
269+
});
270+
195271
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
196272
"finds remote editors installed without PATH launchers",
197273
() =>

‎apps/desktop/src/preview/CdpRelay.test.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ describe("CDP relay", () => {
6565
]);
6666
pending[0]!();
6767
await settle();
68-
expect(send).toHaveBeenNthCalledWith(1, "Page.captureScreenshot", {}, undefined);
69-
expect(send).toHaveBeenNthCalledWith(2, "DOM.enable", {}, "iframe-session");
68+
expect(send).toHaveBeenNthCalledWith(1, "Page.captureScreenshot", {}, undefined, undefined);
69+
expect(send).toHaveBeenNthCalledWith(2, "DOM.enable", {}, "iframe-session", undefined);
7070
expect(written.at(-1)).toEqual({
7171
id: 5,
7272
result: { method: "Page.captureScreenshot" },
@@ -92,7 +92,30 @@ describe("CDP relay", () => {
9292
}),
9393
);
9494
await settle();
95-
expect(send.mock.calls).toEqual([["Runtime.runIfWaitingForDebugger", {}, "iframe-session"]]);
95+
expect(send.mock.calls).toEqual([
96+
["Runtime.runIfWaitingForDebugger", {}, "iframe-session", undefined],
97+
]);
98+
});
99+
100+
// Playwright enables focus emulation on every page it connects to, and Chromium then
101+
// counts the guest as captured: a preview the panel hides keeps its timers unthrottled.
102+
it("acknowledges Playwright's focus emulation without forcing it onto the guest", async () => {
103+
const send = vi.fn(async () => ({}));
104+
const written: Array<Record<string, unknown>> = [];
105+
const relay = createCdpRelayConnection(makeTarget(send), (raw) =>
106+
written.push(JSON.parse(raw)),
107+
);
108+
relay.receive(
109+
JSON.stringify({
110+
id: 1,
111+
method: "Emulation.setFocusEmulationEnabled",
112+
params: { enabled: true },
113+
sessionId: "t3-preview-page",
114+
}),
115+
);
116+
await settle();
117+
expect(written).toEqual([{ id: 1, result: {}, sessionId: "t3-preview-page" }]);
118+
expect(send).not.toHaveBeenCalled();
96119
});
97120

98121
it("routes tab events to the page session once the page is announced", async () => {
@@ -147,7 +170,7 @@ describe("CDP relay extra sessions", () => {
147170
expect(written.find((m) => m["id"] === 4)).toHaveProperty("error");
148171
relay.receive(JSON.stringify({ id: 5, method: "Page.startScreencast", sessionId: extra }));
149172
await settle();
150-
expect(send).toHaveBeenLastCalledWith("Page.startScreencast", {}, undefined);
173+
expect(send).toHaveBeenLastCalledWith("Page.startScreencast", {}, undefined, extra);
151174
written.length = 0;
152175
relay.event("Page.screencastFrame", { data: "x" }, undefined);
153176
expect(written.map((m) => m["sessionId"])).toEqual(["t3-preview-page", extra]);

‎apps/desktop/src/preview/CdpRelay.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export interface CdpRelayTarget {
55
method: string,
66
params: Record<string, unknown>,
77
sessionId: string | undefined,
8+
/** The extra session that sent it, such as a viewer's; the main connection has none. */
9+
owner?: string,
810
) => Promise<unknown>;
11+
readonly sessionDetached?: (owner: string) => void;
912
/** The page's own CDP target id; Playwright keys the main frame by it. */
1013
readonly targetId: () => Promise<string>;
1114
readonly url: () => string;
@@ -111,8 +114,10 @@ export function createCdpRelayConnection(
111114
}
112115
case "Target.detachFromTarget": {
113116
const sessionId = command.params?.["sessionId"];
114-
if (typeof sessionId === "string" && sessionId !== PAGE_SESSION_ID)
117+
if (typeof sessionId === "string" && sessionId !== PAGE_SESSION_ID) {
115118
sessions.delete(sessionId);
119+
target.sessionDetached?.(sessionId);
120+
}
116121
return {};
117122
}
118123
case "Target.setAutoAttach": {
@@ -133,11 +138,15 @@ export function createCdpRelayConnection(
133138

134139
const pageCommand = (command: CdpCommand): Promise<unknown> => {
135140
const child = sessions.get(command.sessionId!) === "page" ? undefined : command.sessionId;
141+
const owner =
142+
child === undefined && command.sessionId !== PAGE_SESSION_ID ? command.sessionId : undefined;
136143
// Child frames/workers pause on auto-attach until resumed; only the main page can skip this command.
137144
if (command.method === "Runtime.runIfWaitingForDebugger" && child === undefined) {
138145
return Promise.resolve({});
139146
}
140-
return target.send(command.method, command.params ?? {}, child);
147+
// Playwright asks for this on every page; the host emulates focus only while it is in use.
148+
if (command.method === "Emulation.setFocusEmulationEnabled") return Promise.resolve({});
149+
return target.send(command.method, command.params ?? {}, child, owner);
141150
};
142151

143152
return {

0 commit comments

Comments
 (0)