Skip to content

Commit 53b6290

Browse files
authored
Merge branch 'main' into t3/mobile-chosen-images
2 parents 5f6c774 + 1eb4071 commit 53b6290

220 files changed

Lines changed: 8605 additions & 2324 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/preview/BrowserImport/Sources.test.ts‎

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,237 @@ describe("cookieDatabaseCandidatePaths", () => {
318318

319319
const firefox = BROWSER_IMPORT_SOURCES.find((source) => source.id === "firefox")!;
320320

321+
const zen = BROWSER_IMPORT_SOURCES.find((source) => source.id === "zen")!;
322+
323+
describe("Zen", () => {
324+
it.effect("resolves Zen's native user-data roots on every supported platform", () =>
325+
run(
326+
Effect.gen(function* () {
327+
const darwinContext = yield* sourcePathContext.pipe(
328+
Effect.provideService(HostProcess.Environment, { HOME: "/Users/zen-user" }),
329+
Effect.provideService(HostProcess.Platform, "darwin"),
330+
);
331+
const windowsContext = yield* sourcePathContext.pipe(
332+
Effect.provideService(HostProcess.Environment, {
333+
HOME: "C:\\Users\\zen-user",
334+
APPDATA: "C:\\Users\\zen-user\\AppData\\Roaming",
335+
}),
336+
Effect.provideService(HostProcess.Platform, "win32"),
337+
);
338+
const linuxContext = yield* sourcePathContext.pipe(
339+
Effect.provideService(HostProcess.Environment, { HOME: "/home/zen-user" }),
340+
Effect.provideService(HostProcess.Platform, "linux"),
341+
);
342+
343+
assert.equal(zen.name, "Zen");
344+
assert.equal(zen.engine, "firefox");
345+
assert.deepEqual([...zen.platforms], ["darwin", "win32", "linux"]);
346+
assert.equal(
347+
zen.userDataDirectory(darwinContext),
348+
darwinContext.path.join("/Users/zen-user", "Library", "Application Support", "zen"),
349+
);
350+
assert.equal(
351+
zen.userDataDirectory(windowsContext),
352+
windowsContext.path.join("C:\\Users\\zen-user\\AppData\\Roaming", "zen"),
353+
);
354+
assert.equal(
355+
zen.userDataDirectory(linuxContext),
356+
linuxContext.path.join("/home/zen-user", ".config", "zen"),
357+
);
358+
assert.deepEqual(zen.alternateLinuxRoots?.(linuxContext), [
359+
linuxContext.path.join("/home/zen-user", ".zen"),
360+
linuxContext.path.join("/home/zen-user", ".var", "app", "app.zen_browser.zen", "zen"),
361+
]);
362+
}),
363+
),
364+
);
365+
366+
it.effect("discovers Zen profiles through its Firefox-compatible metadata", () =>
367+
run(
368+
Effect.gen(function* () {
369+
const fileSystem = yield* FileSystem.FileSystem;
370+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-zen-" });
371+
const context = yield* sourcePathContext.pipe(
372+
Effect.provideService(HostProcess.Environment, { HOME: home }),
373+
Effect.provideService(HostProcess.Platform, "darwin"),
374+
);
375+
const root = zen.userDataDirectory(context)!;
376+
yield* fileSystem.makeDirectory(root, { recursive: true });
377+
const profile = context.path.join(root, "Profiles", "zen.default");
378+
yield* fileSystem.makeDirectory(profile, { recursive: true });
379+
yield* writeFirefoxCookieDatabase(context.path.join(profile, "cookies.sqlite"), 2, 1);
380+
yield* fileSystem.makeDirectory(context.path.join(root, "Profiles", "empty.default"), {
381+
recursive: true,
382+
});
383+
yield* fileSystem.writeFileString(
384+
context.path.join(root, "profiles.ini"),
385+
[
386+
"[Profile0]",
387+
"Name=Zen",
388+
"IsRelative=1",
389+
"Path=Profiles/zen.default",
390+
"ZenAvatarPath=chrome://browser/content/zen-avatars/avatar-55.svg",
391+
"Default=1",
392+
"",
393+
"[Profile1]",
394+
"Name=Empty",
395+
"IsRelative=1",
396+
"Path=Profiles/empty.default",
397+
"",
398+
].join("\n"),
399+
);
400+
401+
assert.deepEqual(yield* listSourceProfiles(zen, context), [
402+
{
403+
directory: context.path.join("Profiles", "zen.default"),
404+
name: "Zen",
405+
cookieCount: 2,
406+
},
407+
]);
408+
assert.isTrue(yield* isSourceInstalled(zen, context));
409+
assert.isFalse(yield* isSourceRunning(zen, context));
410+
assert.equal(
411+
yield* resolveCookieDatabase(zen, context, context.path.join("Profiles", "zen.default")),
412+
context.path.join(profile, "cookies.sqlite"),
413+
);
414+
}),
415+
),
416+
);
417+
418+
it.effect("discovers Zen profiles in both current and legacy Linux roots", () =>
419+
run(
420+
Effect.gen(function* () {
421+
const fileSystem = yield* FileSystem.FileSystem;
422+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-zen-linux-" });
423+
const context = yield* sourcePathContext.pipe(
424+
Effect.provideService(HostProcess.Environment, { HOME: home }),
425+
Effect.provideService(HostProcess.Platform, "linux"),
426+
);
427+
const currentRoot = context.path.join(home, ".config", "zen");
428+
const legacyRoot = context.path.join(home, ".zen");
429+
const currentProfile = context.path.join(currentRoot, "current.default");
430+
const legacyProfile = context.path.join(legacyRoot, "legacy.default");
431+
432+
for (const [root, profile, name] of [
433+
[currentRoot, currentProfile, "Current"],
434+
[legacyRoot, legacyProfile, "Legacy"],
435+
] as const) {
436+
yield* fileSystem.makeDirectory(profile, { recursive: true });
437+
yield* writeFirefoxCookieDatabase(context.path.join(profile, "cookies.sqlite"), 1, 0);
438+
yield* fileSystem.writeFileString(
439+
context.path.join(root, "profiles.ini"),
440+
[
441+
"[Profile0]",
442+
`Name=${name}`,
443+
"IsRelative=1",
444+
`Path=${context.path.basename(profile)}`,
445+
].join("\n"),
446+
);
447+
}
448+
449+
assert.deepEqual(yield* listSourceProfiles(zen, context), [
450+
{ directory: "current.default", name: "Current", cookieCount: 1 },
451+
{ directory: legacyProfile, name: "Legacy", cookieCount: 1 },
452+
]);
453+
assert.isTrue(yield* isSourceInstalled(zen, context));
454+
assert.equal(
455+
yield* resolveCookieDatabase(zen, context, legacyProfile),
456+
context.path.join(legacyProfile, "cookies.sqlite"),
457+
);
458+
459+
yield* fileSystem.writeFileString(
460+
context.path.join(currentRoot, "profiles.ini"),
461+
`[Profile0]\nName=Shared\nIsRelative=0\nPath=${legacyProfile}\n`,
462+
);
463+
assert.deepEqual(yield* listSourceProfiles(zen, context), [
464+
{ directory: legacyProfile, name: "Shared", cookieCount: 1 },
465+
]);
466+
467+
yield* fileSystem.remove(currentRoot, { recursive: true });
468+
assert.isTrue(yield* isSourceInstalled(zen, context));
469+
assert.deepEqual(yield* listSourceProfiles(zen, context), [
470+
{ directory: legacyProfile, name: "Legacy", cookieCount: 1 },
471+
]);
472+
}),
473+
),
474+
);
475+
476+
it.effect("discovers a Flatpak-only Zen installation and resolves its cookies", () =>
477+
run(
478+
Effect.gen(function* () {
479+
const fileSystem = yield* FileSystem.FileSystem;
480+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-zen-flatpak-" });
481+
const context = yield* sourcePathContext.pipe(
482+
Effect.provideService(HostProcess.Environment, { HOME: home }),
483+
Effect.provideService(HostProcess.Platform, "linux"),
484+
);
485+
const root = context.path.join(home, ".var", "app", "app.zen_browser.zen", "zen");
486+
const profile = context.path.join(root, "flatpak.default");
487+
yield* fileSystem.makeDirectory(profile, { recursive: true });
488+
yield* writeFirefoxCookieDatabase(context.path.join(profile, "cookies.sqlite"), 2, 1);
489+
yield* fileSystem.writeFileString(
490+
context.path.join(root, "profiles.ini"),
491+
"[Profile0]\nName=Flatpak\nIsRelative=1\nPath=flatpak.default\n",
492+
);
493+
494+
assert.deepEqual(yield* listSourceProfiles(zen, context), [
495+
{ directory: profile, name: "Flatpak", cookieCount: 2 },
496+
]);
497+
assert.isTrue(yield* isSourceInstalled(zen, context));
498+
assert.equal(
499+
yield* resolveCookieDatabase(zen, context, profile),
500+
context.path.join(profile, "cookies.sqlite"),
501+
);
502+
}),
503+
),
504+
);
505+
506+
it.effect("does not mistake Firefox Snap installs for Zen profiles", () =>
507+
run(
508+
Effect.gen(function* () {
509+
const fileSystem = yield* FileSystem.FileSystem;
510+
const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-zen-snap-" });
511+
const context = yield* sourcePathContext.pipe(
512+
Effect.provideService(HostProcess.Environment, { HOME: home }),
513+
Effect.provideService(HostProcess.Platform, "linux"),
514+
);
515+
const zenRoot = context.path.join(home, ".config", "zen");
516+
const snapRoot = context.path.join(
517+
home,
518+
"snap",
519+
"firefox",
520+
"common",
521+
".mozilla",
522+
"firefox",
523+
);
524+
const zenProfile = context.path.join(zenRoot, "zen.default");
525+
const snapProfile = context.path.join(snapRoot, "snap.default");
526+
for (const root of [zenRoot, snapRoot]) {
527+
const profile = root === zenRoot ? zenProfile : snapProfile;
528+
yield* fileSystem.makeDirectory(profile, { recursive: true });
529+
yield* writeFirefoxCookieDatabase(context.path.join(profile, "cookies.sqlite"), 1, 0);
530+
yield* fileSystem.writeFileString(
531+
context.path.join(root, "profiles.ini"),
532+
[
533+
"[Profile0]",
534+
"Name=Personal",
535+
"IsRelative=1",
536+
`Path=${profile === zenProfile ? "zen.default" : "snap.default"}`,
537+
].join("\n"),
538+
);
539+
}
540+
541+
const profiles = yield* listSourceProfiles(zen, context);
542+
assert.deepEqual(
543+
profiles.map((profile) => profile.directory),
544+
["zen.default"],
545+
);
546+
assert.isTrue(yield* isSourceInstalled(zen, context));
547+
}),
548+
),
549+
);
550+
});
551+
321552
describe("Firefox Snap profiles", () => {
322553
it.effect.skipIf(!symlinksSupported)(
323554
"finds Snap profiles with or without profiles.ini and checks their locks",

‎apps/desktop/src/preview/BrowserImport/Sources.ts‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface BrowserImportSourceDefinition {
2626
readonly engine: BrowserImportEngine;
2727
readonly platforms: ReadonlyArray<NodeJS.Platform>;
2828
readonly userDataDirectory: (context: BrowserImportPathContext) => string | undefined;
29+
readonly alternateLinuxRoots?: (context: BrowserImportPathContext) => ReadonlyArray<string>;
2930
readonly keychainService?: string;
3031
readonly keychainAccount?: string;
3132
readonly linuxSecretApplication?: string;
@@ -169,6 +170,26 @@ export const BROWSER_IMPORT_SOURCES: ReadonlyArray<BrowserImportSourceDefinition
169170
}
170171
return context.path.join(context.home, ".mozilla", "firefox");
171172
},
173+
alternateLinuxRoots: (context) => [
174+
context.path.join(context.home, "snap", "firefox", "common", ".mozilla", "firefox"),
175+
],
176+
},
177+
{
178+
id: "zen",
179+
name: "Zen",
180+
engine: "firefox",
181+
platforms: ["darwin", "win32", "linux"],
182+
userDataDirectory: (context) => {
183+
if (context.platform === "darwin") return macApplicationSupport(context, "zen");
184+
if (context.platform === "win32") {
185+
return context.appData ? context.path.join(context.appData, "zen") : undefined;
186+
}
187+
return context.path.join(context.home, ".config", "zen");
188+
},
189+
alternateLinuxRoots: (context) => [
190+
context.path.join(context.home, ".zen"),
191+
context.path.join(context.home, ".var", "app", "app.zen_browser.zen", "zen"),
192+
],
172193
},
173194
];
174195

@@ -470,7 +491,7 @@ const listSourceProfilesInDirectory = Effect.fnUntraced(function* (
470491
);
471492
});
472493

473-
/** Keep Snap profile paths absolute so reads and locks distinguish native and Snap installations. */
494+
/** Keep alternate-root profile paths absolute so cookie reads and locks use the correct installation. */
474495
export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProfiles")(function* (
475496
definition: BrowserImportSourceDefinition,
476497
context: BrowserImportPathContext,
@@ -481,10 +502,7 @@ export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProf
481502

482503
const root = definition.userDataDirectory(context);
483504
if (root === undefined) return [];
484-
const roots = [
485-
root,
486-
context.path.join(context.home, "snap", "firefox", "common", ".mozilla", "firefox"),
487-
];
505+
const roots = [root, ...(definition.alternateLinuxRoots?.(context) ?? [])];
488506
const profiles = new Map<string, BrowserImportSourceProfile>();
489507
for (const directory of roots) {
490508
const found = yield* listSourceProfilesInDirectory(

‎apps/desktop/src/snapShot/DesktopSnapShot.test.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,15 @@ it.effect("matches Windows accessibility windows on a scaled display", () => {
10481048
);
10491049
});
10501050

1051-
it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
1052-
"persists %s text without inventing AT-SPI screen coordinates",
1053-
(backend) => {
1051+
it.effect.each([
1052+
{ backend: "gnome", screenshot: "PNG" },
1053+
{ backend: "niri", screenshot: "PNG" },
1054+
{ backend: "kde", screenshot: "PNG" },
1055+
{ backend: "hyprland", screenshot: "PNG" },
1056+
{ backend: "gnome", screenshot: "invalid" },
1057+
] as const)(
1058+
"persists $backend accessibility text with a $screenshot screenshot",
1059+
({ backend, screenshot }) => {
10541060
vi.stubEnv("XDG_SESSION_TYPE", "wayland");
10551061
flashWindows.length = 0;
10561062
const window = {
@@ -1067,7 +1073,16 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
10671073
...(backend === "niri" ? { accessibilityBoundsReliable: false } : {}),
10681074
...(backend === "kde" ? { clientBounds: { x: 479, y: 371, width: 700, height: 520 } } : {}),
10691075
};
1070-
linuxCaptureMock.mockResolvedValueOnce({ png: Buffer.from([1, 2, 3]), window });
1076+
// The captured pixels differ from the compositor's logical window bounds.
1077+
const imageSize = screenshot === "PNG" ? { width: 1400, height: 1040 } : window.bounds;
1078+
const png =
1079+
screenshot === "PNG"
1080+
? Buffer.from(
1081+
"iVBORw0KGgoAAAANSUhEUgAABXgAAAQQAQAAAABwoA4ZAAAAyElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgYyx4AAepc/c0AAAAASUVORK5CYII=",
1082+
"base64",
1083+
)
1084+
: Buffer.from([1, 2, 3]);
1085+
linuxCaptureMock.mockResolvedValueOnce({ png, window });
10711086
activeWindowMock.mockClear();
10721087
getSourcesMock.mockClear();
10731088
accessibilityByPidMock.mockReset().mockResolvedValue({
@@ -1107,7 +1122,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
11071122
assert.deepInclude(saved.source.accessibility, {
11081123
format: "element-tree",
11091124
coordinateSpace: "captured-image",
1110-
imageSize: { width: 700, height: window.bounds.height },
1125+
imageSize: { width: imageSize.width, height: imageSize.height },
11111126
truncated: false,
11121127
});
11131128
assert.deepInclude(
@@ -1117,7 +1132,7 @@ it.effect.each(["gnome", "niri", "kde", "hyprland"] as const)(
11171132
{
11181133
role: "window",
11191134
name: "Editor",
1120-
bounds: { x: 0, y: 0, width: 700, height: window.bounds.height },
1135+
bounds: { x: 0, y: 0, width: imageSize.width, height: imageSize.height },
11211136
state: { active: true },
11221137
},
11231138
);

‎apps/desktop/src/snapShot/DesktopSnapShot.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
snapShotShortcutSystemConflict,
9191
} from "./snapShot.ts";
9292
import * as HostProcess from "@t3tools/shared/HostProcess";
93+
import { readImageDimensions } from "@t3tools/shared/imageDimensions";
9394

9495
const MAX_CAPTURE_WIDTH = 2_560;
9596
const MAX_CAPTURE_HEIGHT = 1_600;
@@ -413,10 +414,10 @@ async function requestMacSnapShotPermissions(
413414
}
414415

415416
function snapShotImageSize(png: Buffer, fallback: Electron.Rectangle): Electron.Size {
416-
try {
417-
const size = Electron.nativeImage.createFromBuffer(png).getSize();
418-
if (size.width > 0 && size.height > 0) return size;
419-
} catch {}
417+
// Capture backends already validate or encode the PNG. Reading its header
418+
// avoids decoding every pixel again just to size accessibility coordinates.
419+
const size = readImageDimensions(png);
420+
if (size) return size;
420421
return {
421422
width: Math.max(1, Math.round(fallback.width)),
422423
height: Math.max(1, Math.round(fallback.height)),
-770 KB
Binary file not shown.
771 KB
Binary file not shown.

0 commit comments

Comments
 (0)