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