| 1 | import * as Option from "effect/Option"; |
| 2 | |
| 3 | export type JoinPath = (first: string, ...segments: string[]) => string; |
| 4 | |
| 5 | function normalizeConfiguredBaseDir(t3Home: Option.Option<string>): Option.Option<string> { |
| 6 | if (Option.isNone(t3Home)) { |
| 7 | return Option.none(); |
| 8 | } |
| 9 | const trimmed = t3Home.value.trim(); |
| 10 | return trimmed.length > 0 ? Option.some(trimmed) : Option.none(); |
| 11 | } |
| 12 | |
| 13 | export function resolveDesktopBaseDir(input: { |
| 14 | readonly homeDirectory: string; |
| 15 | readonly joinPath: JoinPath; |
| 16 | readonly t3Home: Option.Option<string>; |
| 17 | }): string { |
| 18 | return Option.getOrElse(normalizeConfiguredBaseDir(input.t3Home), () => |
| 19 | input.joinPath(input.homeDirectory, ".t3"), |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | export function resolveDesktopStateDir(input: { |
| 24 | readonly baseDir: string; |
| 25 | readonly isDevelopment: boolean; |
| 26 | readonly joinPath: JoinPath; |
| 27 | readonly t3Home: Option.Option<string>; |
| 28 | }): string { |
| 29 | const useDevSubdir = |
| 30 | input.isDevelopment && Option.isNone(normalizeConfiguredBaseDir(input.t3Home)); |
| 31 | return input.joinPath(input.baseDir, useDevSubdir ? "dev" : "userdata"); |
| 32 | } |