Skip to content

Commit e5b82d7

Browse files
feat(desktop): import cookies from Zen Browser
1 parent 680152e commit e5b82d7

4 files changed

Lines changed: 222 additions & 6 deletions

File tree

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

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,206 @@ describe("cookieDatabaseCandidatePaths", () => {
326326

327327
const firefox = BROWSER_IMPORT_SOURCES.find((source) => source.id === "firefox")!;
328328

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

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

Lines changed: 20 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;
@@ -171,6 +172,23 @@ export const BROWSER_IMPORT_SOURCES: ReadonlyArray<BrowserImportSourceDefinition
171172
}
172173
return context.path.join(context.home, ".mozilla", "firefox");
173174
},
175+
alternateLinuxRoots: (context) => [
176+
context.path.join(context.home, "snap", "firefox", "common", ".mozilla", "firefox"),
177+
],
178+
},
179+
{
180+
id: "zen",
181+
name: "Zen",
182+
engine: "firefox",
183+
platforms: ["darwin", "win32", "linux"],
184+
userDataDirectory: (context) => {
185+
if (context.platform === "darwin") return macApplicationSupport(context, "zen");
186+
if (context.platform === "win32") {
187+
return context.appData ? context.path.join(context.appData, "zen") : undefined;
188+
}
189+
return context.path.join(context.home, ".config", "zen");
190+
},
191+
alternateLinuxRoots: (context) => [context.path.join(context.home, ".zen")],
174192
},
175193
];
176194

@@ -491,7 +509,7 @@ const listSourceProfilesInDirectory = Effect.fnUntraced(function* (
491509
});
492510

493511
/**
494-
* Include Firefox's Snap home alongside its native home. Snap profiles use
512+
* Include alternate Linux homes alongside the native home. Alternate profiles use
495513
* absolute directories so cookie reads and lock checks keep pointing at the
496514
* installation they came from, even when both installs use the same name.
497515
*/
@@ -505,10 +523,7 @@ export const listSourceProfiles = Effect.fn("BrowserImportSources.listSourceProf
505523

506524
const root = definition.userDataDirectory(context);
507525
if (root === undefined) return [];
508-
const roots = [
509-
root,
510-
context.path.join(context.home, "snap", "firefox", "common", ".mozilla", "firefox"),
511-
];
526+
const roots = [root, ...(definition.alternateLinuxRoots?.(context) ?? [])];
512527
const profiles = new Map<string, BrowserImportSourceProfile>();
513528
for (const directory of roots) {
514529
const found = yield* listSourceProfilesInDirectory(

‎docs/user/browser-import.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ System Settings permission list, and turn access on. **Continue** becomes availa
1515
is detected. macOS may require you to quit and reopen T3 Code before the grant applies; reopen
1616
the import wizard afterward. You can revoke Full Disk Access once the import is done.
1717

18-
On Windows, import supports Firefox and Helium profiles that use standard profile encryption.
18+
On Windows, import supports Firefox, Zen, and Helium profiles that use standard profile encryption.
1919
Other Chromium-based browsers use app-bound encryption and cannot be imported. Partitioned cookies
2020
are skipped on all platforms.

‎packages/contracts/src/browserImport.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const BROWSER_IMPORT_SOURCE_IDS = [
1111
"arc",
1212
"helium",
1313
"firefox",
14+
"zen",
1415
"safari",
1516
] as const;
1617

0 commit comments

Comments
 (0)