refactor: extract app constants from status-lib to desktop
This commit is contained in:
parent
2599903ca4
commit
a13a0e0d3a
|
@ -1,6 +1,5 @@
|
|||
import NimQml, Tables, json, sequtils, chronicles, strutils, os, strformat
|
||||
import status/[status]
|
||||
import status/constants
|
||||
import status/utils as status_utils
|
||||
import status/chat as status_chat
|
||||
import status/messages as status_messages
|
||||
|
@ -18,7 +17,7 @@ import ../utils/image_utils
|
|||
import web3/[conversions, ethtypes]
|
||||
import views/message_search/[view_controller]
|
||||
import views/[channels_list, message_list, chat_item, reactions, stickers, groups, transactions, communities, community_list, community_item, format_input, ens, activity_notification_list, channel, messages, message_item, gif]
|
||||
|
||||
import ../../constants
|
||||
|
||||
# TODO: remove me
|
||||
import status/libstatus/chat as libstatus_chat
|
||||
|
|
|
@ -3,6 +3,7 @@ import status/[signals, status]
|
|||
import status/types/[account, rpc_response]
|
||||
import view
|
||||
import eventemitter
|
||||
import ../../constants
|
||||
|
||||
type LoginController* = ref object
|
||||
status*: Status
|
||||
|
@ -33,7 +34,7 @@ proc handleNodeLogin(self: LoginController, response: NodeSignal) =
|
|||
self.status.events.emit("login", AccountArgs(account: self.view.currentAccount.account.toAccount))
|
||||
|
||||
proc init*(self: LoginController) =
|
||||
let nodeAccounts = self.status.accounts.openAccounts()
|
||||
let nodeAccounts = self.status.accounts.openAccounts(STATUSGODIR)
|
||||
self.status.accounts.nodeAccounts = nodeAccounts
|
||||
for nodeAccount in nodeAccounts:
|
||||
self.view.addAccountToList(nodeAccount)
|
||||
|
|
|
@ -2,7 +2,7 @@ import NimQml, os
|
|||
import chronicles
|
||||
import profile_info
|
||||
import status/status
|
||||
import status/constants as accountConstants
|
||||
import ../../../constants
|
||||
|
||||
logScope:
|
||||
topics = "profile-settings-view"
|
||||
|
@ -35,14 +35,14 @@ QtObject:
|
|||
else:
|
||||
self.profile.pubKey
|
||||
|
||||
return os.joinPath(accountConstants.DATADIR, "qt", pubkey)
|
||||
return os.joinPath(DATADIR, "qt", pubkey)
|
||||
|
||||
QtProperty[string] settingsFile:
|
||||
read = getSettingsFile
|
||||
notify = settingsFileChanged
|
||||
|
||||
proc getGlobalSettingsFile(self: ProfileSettingsView): string {.slot.} =
|
||||
return os.joinPath(accountConstants.DATADIR, "qt", "global")
|
||||
return os.joinPath(DATADIR, "qt", "global")
|
||||
|
||||
proc globalSettingsFileChanged*(self: ProfileSettingsView) {.signal.}
|
||||
|
||||
|
@ -53,7 +53,7 @@ QtObject:
|
|||
proc removeUnknownAccountSettings*(self: ProfileSettingsView) =
|
||||
# Remove old 'unknownAccount' settings file if it was created
|
||||
self.settingsFileChanged()
|
||||
let unknownSettingsPath = os.joinPath(accountConstants.DATADIR, "qt", UNKNOWN_ACCOUNT)
|
||||
let unknownSettingsPath = os.joinPath(DATADIR, "qt", UNKNOWN_ACCOUNT)
|
||||
if (not unknownSettingsPath.tryRemoveFile):
|
||||
# Only fails if the file exists and an there was an error removing it
|
||||
# More info: https://nim-lang.org/docs/os.html#tryRemoveFile%2Cstring
|
||||
|
|
|
@ -4,7 +4,7 @@ import
|
|||
status/[status, settings],
|
||||
status/wallet as status_wallet,
|
||||
status/types/[rpc_response]
|
||||
|
||||
import ../../../../constants
|
||||
import account_list, account_item
|
||||
|
||||
logScope:
|
||||
|
@ -40,13 +40,13 @@ QtObject:
|
|||
|
||||
proc addAccountsFromSeed*(self: AccountsView, seed: string, password: string, accountName: string, color: string): string {.slot.} =
|
||||
try:
|
||||
self.status.wallet.addAccountsFromSeed(seed.strip(), password, accountName, color)
|
||||
self.status.wallet.addAccountsFromSeed(seed.strip(), password, accountName, color, KEYSTOREDIR)
|
||||
except StatusGoException as e:
|
||||
result = StatusGoError(error: e.msg).toJson
|
||||
|
||||
proc addAccountsFromPrivateKey*(self: AccountsView, privateKey: string, password: string, accountName: string, color: string): string {.slot.} =
|
||||
try:
|
||||
self.status.wallet.addAccountsFromPrivateKey(privateKey, password, accountName, color)
|
||||
self.status.wallet.addAccountsFromPrivateKey(privateKey, password, accountName, color, KEYSTOREDIR)
|
||||
except StatusGoException as e:
|
||||
result = StatusGoError(error: e.msg).toJson
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import
|
|||
status/[status, settings],
|
||||
status/wallet2 as status_wallet,
|
||||
status/types/[rpc_response]
|
||||
|
||||
import ../../../../constants
|
||||
import account_list, account_item
|
||||
|
||||
logScope:
|
||||
|
@ -40,13 +40,13 @@ QtObject:
|
|||
|
||||
proc addAccountsFromSeed*(self: AccountsView, seed: string, password: string, accountName: string, color: string): string {.slot.} =
|
||||
try:
|
||||
self.status.wallet2.addAccountsFromSeed(seed.strip(), password, accountName, color)
|
||||
self.status.wallet2.addAccountsFromSeed(seed.strip(), password, accountName, color, KEYSTOREDIR)
|
||||
except StatusGoException as e:
|
||||
result = StatusGoError(error: e.msg).toJson
|
||||
|
||||
proc addAccountsFromPrivateKey*(self: AccountsView, privateKey: string, password: string, accountName: string, color: string): string {.slot.} =
|
||||
try:
|
||||
self.status.wallet2.addAccountsFromPrivateKey(privateKey, password, accountName, color)
|
||||
self.status.wallet2.addAccountsFromPrivateKey(privateKey, password, accountName, color, KEYSTOREDIR)
|
||||
except StatusGoException as e:
|
||||
result = StatusGoError(error: e.msg).toJson
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
import os, sequtils, strutils
|
||||
|
||||
import # vendor libs
|
||||
confutils
|
||||
|
||||
const sep = when defined(windows): "\\" else: "/"
|
||||
|
||||
proc defaultDataDir(): string =
|
||||
let homeDir = getHomeDir()
|
||||
let parentDir =
|
||||
if defined(development):
|
||||
parentDir(getAppDir())
|
||||
elif homeDir == "":
|
||||
getCurrentDir()
|
||||
elif defined(macosx):
|
||||
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
|
||||
|
||||
# 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()
|
||||
if defined(macosx):
|
||||
cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_"))
|
||||
|
||||
let desktopConfig = StatusDesktopConfig.load(cliParams)
|
||||
|
||||
let
|
||||
baseDir = absolutePath(expandTilde(desktopConfig.dataDir))
|
||||
DATADIR* = baseDir & sep
|
||||
STATUSGODIR* = joinPath(baseDir, "data") & sep
|
||||
KEYSTOREDIR* = joinPath(baseDir, "data", "keystore") & sep
|
||||
TMPDIR* = joinPath(baseDir, "tmp") & sep
|
||||
LOGDIR* = joinPath(baseDir, "logs") & sep
|
||||
|
||||
proc ensureDirectories*(dataDir, tmpDir, logDir: string) =
|
||||
createDir(dataDir)
|
||||
createDir(tmpDir)
|
||||
createDir(logDir)
|
|
@ -11,13 +11,13 @@ import app/onboarding/core as onboarding
|
|||
import app/login/core as login
|
||||
import app/provider/core as provider
|
||||
import status/types/[account]
|
||||
import status/constants
|
||||
import status_go
|
||||
import status/status as statuslib
|
||||
import eventemitter
|
||||
import app_service/tasks/marathon/mailserver/controller as mailserver_controller
|
||||
import app_service/tasks/marathon/mailserver/worker as mailserver_worker
|
||||
import app_service/main
|
||||
import constants
|
||||
|
||||
var signalsQObjPointer: pointer
|
||||
|
||||
|
@ -28,6 +28,8 @@ proc mainProc() =
|
|||
if defined(macosx) and defined(production):
|
||||
setCurrentDir(getAppDir())
|
||||
|
||||
ensureDirectories(DATADIR, TMPDIR, LOGDIR)
|
||||
|
||||
let logFile = fmt"app_{getTime().toUnix}.log"
|
||||
discard defaultChroniclesStream.output.open(LOGDIR & logFile, fmAppend)
|
||||
|
||||
|
@ -48,7 +50,7 @@ proc mainProc() =
|
|||
let appService = newAppService(status, mailserverWorker)
|
||||
defer: appService.delete()
|
||||
|
||||
status.initNode()
|
||||
status.initNode(STATUSGODIR, KEYSTOREDIR)
|
||||
|
||||
let uiScaleFilePath = joinPath(DATADIR, "ui-scale")
|
||||
enableHDPI(uiScaleFilePath)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7058328bb3da96a01477f6f2f476aa8277bfafe9
|
||||
Subproject commit efe2790db6cf5e3f01d4b3265d2a671fed70e2d1
|
Loading…
Reference in New Issue