File size: 1,746 Bytes
4a940a5
 
 
 
 
 
 
 
 
 
504b471
4a940a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504b471
 
 
 
 
4a940a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * Centralized path management for CLI and Electron modes.
 *
 * CLI mode (default): all paths relative to process.cwd().
 * Electron mode: paths set by setPaths() before backend imports.
 */

import { resolve } from "path";

interface PathConfig {
  rootDir: string;
  configDir: string;
  dataDir: string;
  binDir: string;
  publicDir: string;
  desktopPublicDir?: string;
}

let _paths: PathConfig | null = null;

/**
 * Set custom paths (called by Electron main process before importing backend).
 * Must be called before any getXxxDir() calls.
 */
export function setPaths(config: PathConfig): void {
  _paths = config;
}

/** App root directory (where package.json lives). */
export function getRootDir(): string {
  return _paths?.rootDir ?? process.cwd();
}

/** Directory containing YAML config files. */
export function getConfigDir(): string {
  return _paths?.configDir ?? resolve(process.cwd(), "config");
}

/** Directory for runtime data (accounts.json, cookies.json, etc.). */
export function getDataDir(): string {
  return _paths?.dataDir ?? resolve(process.cwd(), "data");
}

/** Directory for curl-impersonate binaries. */
export function getBinDir(): string {
  return _paths?.binDir ?? resolve(process.cwd(), "bin");
}

/** Directory for static web assets (Vite build output). */
export function getPublicDir(): string {
  return _paths?.publicDir ?? resolve(process.cwd(), "public");
}

/** Directory for desktop-specific static assets (desktop Vite build output). */
export function getDesktopPublicDir(): string {
  return _paths?.desktopPublicDir ?? resolve(process.cwd(), "public-desktop");
}

/** Whether running in embedded mode (Electron). */
export function isEmbedded(): boolean {
  return _paths !== null;
}