2023-01-31 15:52:57 +00:00
|
|
|
import os, sequtils, strutils, strformat
|
2021-09-09 19:09:17 +00:00
|
|
|
|
|
|
|
import # vendor libs
|
|
|
|
confutils
|
|
|
|
|
2023-03-15 13:35:03 +00:00
|
|
|
const DEFAULT_WALLET_ENABLED = true
|
|
|
|
let WALLET_ENABLED* = if (existsEnv("ENABLE_WALLET")):
|
|
|
|
parseInt($getEnv("ENABLE_WALLET")) != 0
|
|
|
|
else:
|
|
|
|
DEFAULT_WALLET_ENABLED
|
|
|
|
|
2023-01-20 08:31:11 +00:00
|
|
|
## Added a constant here cause it's easier to check the app how it behaves
|
|
|
|
## on other platform if we just change the value here
|
|
|
|
const IS_MACOS* = defined(macosx)
|
|
|
|
|
2023-05-11 13:12:30 +00:00
|
|
|
# For future supporting fingerprints on other platforms
|
|
|
|
const SUPPORTS_FINGERPRINT* = IS_MACOS
|
|
|
|
|
2022-04-07 09:08:44 +00:00
|
|
|
const sep* = when defined(windows): "\\" else: "/"
|
2021-09-09 19:09:17 +00:00
|
|
|
|
2022-04-08 10:44:50 +00:00
|
|
|
proc defaultDataDir*(): string =
|
2021-09-09 19:09:17 +00:00
|
|
|
let homeDir = getHomeDir()
|
|
|
|
let parentDir =
|
|
|
|
if defined(development):
|
|
|
|
parentDir(getAppDir())
|
|
|
|
elif homeDir == "":
|
|
|
|
getCurrentDir()
|
2023-01-20 08:31:11 +00:00
|
|
|
elif IS_MACOS:
|
2021-09-09 19:09:17 +00:00
|
|
|
joinPath(homeDir, "Library", "Application Support")
|
|
|
|
elif defined(windows):
|
|
|
|
let targetDir = getEnv("LOCALAPPDATA").string
|
|
|
|
if targetDir == "":
|
|
|
|
joinPath(homeDir, "AppData", "Local")
|
|
|
|
else:
|
|
|
|
targetDir
|
|
|
|
else:
|
|
|
|
let targetDir = getEnv("XDG_CONFIG_HOME").string
|
|
|
|
if targetDir == "":
|
|
|
|
joinPath(homeDir, ".config")
|
|
|
|
else:
|
|
|
|
targetDir
|
|
|
|
absolutePath(joinPath(parentDir, "Status"))
|
|
|
|
|
|
|
|
type StatusDesktopConfig = object
|
|
|
|
dataDir* {.
|
|
|
|
defaultValue: defaultDataDir()
|
|
|
|
desc: "Status Desktop data directory"
|
|
|
|
abbr: "d" .}: string
|
2021-09-09 21:31:56 +00:00
|
|
|
uri* {.
|
|
|
|
defaultValue: ""
|
|
|
|
desc: "status-im:// URI to open a chat or other"
|
|
|
|
name: "uri" .}: string
|
|
|
|
|
|
|
|
|
2021-09-09 19:09:17 +00:00
|
|
|
# On macOS the first time when a user gets the "App downloaded from the
|
|
|
|
# internet" warning, and clicks the Open button, the OS passes a unique process
|
|
|
|
# serial number (PSN) as -psn_... command-line argument, which we remove before
|
|
|
|
# processing the arguments with nim-confutils.
|
|
|
|
# Credit: https://github.com/bitcoin/bitcoin/blame/b6e34afe9735faf97d6be7a90fafd33ec18c0cbb/src/util/system.cpp#L383-L389
|
|
|
|
|
|
|
|
var cliParams = commandLineParams()
|
2023-01-20 08:31:11 +00:00
|
|
|
if IS_MACOS:
|
2021-09-09 19:09:17 +00:00
|
|
|
cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_"))
|
|
|
|
|
|
|
|
let desktopConfig = StatusDesktopConfig.load(cliParams)
|
|
|
|
|
|
|
|
let
|
|
|
|
baseDir = absolutePath(expandTilde(desktopConfig.dataDir))
|
2021-09-09 21:31:56 +00:00
|
|
|
OPENURI* = desktopConfig.uri
|
2021-09-09 19:09:17 +00:00
|
|
|
DATADIR* = baseDir & sep
|
|
|
|
STATUSGODIR* = joinPath(baseDir, "data") & sep
|
2022-05-05 13:43:29 +00:00
|
|
|
ROOTKEYSTOREDIR* = joinPath(baseDir, "data", "keystore")
|
2021-09-09 19:09:17 +00:00
|
|
|
TMPDIR* = joinPath(baseDir, "tmp") & sep
|
|
|
|
LOGDIR* = joinPath(baseDir, "logs") & sep
|
2022-07-21 11:29:18 +00:00
|
|
|
KEYCARDPAIRINGDATAFILE* = joinPath(baseDir, "data", "keycard/pairings.json")
|
2021-09-09 19:09:17 +00:00
|
|
|
|
|
|
|
proc ensureDirectories*(dataDir, tmpDir, logDir: string) =
|
|
|
|
createDir(dataDir)
|
|
|
|
createDir(tmpDir)
|
2022-02-09 09:43:23 +00:00
|
|
|
createDir(logDir)
|
2022-03-24 11:51:24 +00:00
|
|
|
|
|
|
|
# This is changed during compilation by reading the VERSION file
|
2023-01-31 15:52:57 +00:00
|
|
|
const DESKTOP_VERSION {.strdefine.} = "0.0.0"
|
2022-03-24 11:51:24 +00:00
|
|
|
# This is changed during compilation by executing git command
|
|
|
|
const GIT_COMMIT* {.strdefine.} = ""
|
2023-01-26 17:14:10 +00:00
|
|
|
|
2023-01-31 15:52:57 +00:00
|
|
|
const APP_VERSION* = if defined(production): DESKTOP_VERSION else: fmt("git master {GIT_COMMIT}")
|
|
|
|
|
2023-01-26 17:14:10 +00:00
|
|
|
# Name of the test environment var to check for
|
2023-01-31 15:52:57 +00:00
|
|
|
const TEST_ENVIRONMENT_VAR* = "TEST_ENVIRONMENT"
|