Open History to see the last commit
1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as FileSystem from "effect/FileSystem";
4import * as Layer from "effect/Layer";
5
6import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
7
8export const LinuxBrowserSecretPath = Context.Reference<string | undefined>(
9 "@t3tools/desktop/preview/BrowserImport/LinuxBrowserSecretPath",
10 { defaultValue: () => undefined },
11);
12
13export const layer = Layer.effect(
14 LinuxBrowserSecretPath,
15 Effect.gen(function* () {
16 const environment = yield* DesktopEnvironment.DesktopEnvironment;
17 if (environment.platform !== "linux") return undefined;
18 const fileSystem = yield* FileSystem.FileSystem;
19 const relative = environment.path.join("browser-secret", "t3-browser-secret");
20 const candidates = environment.isPackaged
21 ? [environment.path.join(environment.resourcesPath, relative)]
22 : [
23 environment.path.join(
24 environment.rootDir,
25 "native",
26 "browser-secret",
27 "build",
28 environment.processArch,
29 "t3-browser-secret",
30 ),
31 ...environment.resolveResourcePathCandidates(relative),
32 ];
33 for (const candidate of candidates) {
34 if (yield* fileSystem.exists(candidate).pipe(Effect.orElseSucceed(() => false)))
35 return candidate;
36 }
37 return undefined;
38 }),
39);