diff --git a/.gitignore b/.gitignore index 65381e1023..a95e01289c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/Status /data noBackup/ .idea diff --git a/.gitmodules b/.gitmodules index 3e1d9b65f4..014e78b8d5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -97,3 +97,6 @@ [submodule "vendor/edn.nim"] path = vendor/edn.nim url = https://github.com/status-im/edn.nim.git +[submodule "vendor/nim-confutils"] + path = vendor/nim-confutils + url = https://github.com/status-im/nim-confutils.git diff --git a/Makefile b/Makefile index fee6ba0d78..ac195053de 100644 --- a/Makefile +++ b/Makefile @@ -151,12 +151,20 @@ else NIM_EXTRA_PARAMS := --passL:"-lsetupapi -lhid" endif -# TODO: control debug/release builds with a Make var -# We need `-d:debug` to get Nim's default stack traces. -NIM_PARAMS += --outdir:./bin -d:debug -# Enable debugging symbols in DOtherSide, in case we need GDB backtraces from it. -CFLAGS += -g -CXXFLAGS += -g +RELEASE ?= false +ifeq ($(RELEASE),false) + # We need `-d:debug` to get Nim's default stack traces + NIM_PARAMS += -d:debug + # Enable debugging symbols in DOtherSide, in case we need GDB backtraces + CFLAGS += -g + CXXFLAGS += -g +else + # Additional optimization flags for release builds are not included at present; + # adding them will involve refactoring config.nims in the root of this repo + NIM_PARAMS += -d:release +endif + +NIM_PARAMS += --outdir:./bin $(DOTHERSIDE): | deps echo -e $(BUILD_MSG) "DOtherSide" @@ -215,6 +223,9 @@ DEFAULT_TOKEN := 220a1abb4b6943a093c35d0ce4fb0732 INFURA_TOKEN ?= $(DEFAULT_TOKEN) NIM_PARAMS += -d:INFURA_TOKEN:"$(INFURA_TOKEN)" +RESOURCES_LAYOUT := -d:development + +nim_status_client: NIM_PARAMS += $(RESOURCES_LAYOUT) nim_status_client: | $(DOTHERSIDE) $(STATUSGO) $(QRCODEGEN) $(FLEETS) rcc deps echo -e $(BUILD_MSG) "$@" && \ $(ENV_SCRIPT) nim c $(NIM_PARAMS) --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" $(NIM_EXTRA_PARAMS) --passL:"$(QRCODEGEN)" --passL:"-lm" src/nim_status_client.nim && \ @@ -238,6 +249,7 @@ $(APPIMAGE_TOOL): STATUS_CLIENT_APPIMAGE ?= pkg/NimStatusClient-x86_64.AppImage +$(STATUS_CLIENT_APPIMAGE): override RESOURCES_LAYOUT := -d:production $(STATUS_CLIENT_APPIMAGE): nim_status_client $(APPIMAGE_TOOL) nim-status.desktop rm -rf pkg/*.AppImage rm -rf tmp/linux/dist @@ -279,6 +291,7 @@ MACOS_INNER_BUNDLE := $(MACOS_OUTER_BUNDLE)/Contents/Frameworks/QtWebEngineCore. STATUS_CLIENT_DMG ?= pkg/Status.dmg +$(STATUS_CLIENT_DMG): override RESOURCES_LAYOUT := -d:production $(STATUS_CLIENT_DMG): nim_status_client $(DMG_TOOL) rm -rf tmp/macos pkg/*.dmg mkdir -p $(MACOS_OUTER_BUNDLE)/Contents/MacOS @@ -349,6 +362,7 @@ endif STATUS_CLIENT_ZIP ?= pkg/Status.zip +$(STATUS_CLIENT_ZIP): override RESOURCES_LAYOUT := -d:production $(STATUS_CLIENT_ZIP): nim_status_client nim_windows_launcher $(NIM_WINDOWS_PREBUILT_DLLS) rm -rf pkg/*.zip rm -rf tmp/windows/dist @@ -426,30 +440,24 @@ $(ICON_TOOL): echo -e "\e[92mInstalling:\e[39m fileicon" npm i -NIM_STATUS_CLIENT_DEV ?= t -STATUS_PORT ?= 30306 +# Currently not in use: https://github.com/status-im/status-desktop/pull/1858 +# STATUS_PORT ?= 30306 set-status-macos-dev-icon: $(ICON_TOOL) npx fileicon set bin/nim_status_client status-dev.icns run-linux: echo -e "\e[92mRunning:\e[39m bin/nim_status_client" - NIM_STATUS_CLIENT_DEV="$(NIM_STATUS_CLIENT_DEV)" \ LD_LIBRARY_PATH="$(QT5_LIBDIR)":"$(STATUSGO_LIBDIR)" \ - STATUS_PORT="$(STATUS_PORT)" \ ./bin/nim_status_client run-macos: set-status-macos-dev-icon echo -e "\e[92mRunning:\e[39m bin/nim_status_client" - NIM_STATUS_CLIENT_DEV="$(NIM_STATUS_CLIENT_DEV)" \ - STATUS_PORT="$(STATUS_PORT)" \ ./bin/nim_status_client run-windows: $(NIM_WINDOWS_PREBUILT_DLLS) echo -e "\e[92mRunning:\e[39m bin/nim_status_client.exe" - NIM_STATUS_CLIENT_DEV="$(NIM_STATUS_CLIENT_DEV)" \ PATH="$(shell pwd)"/"$(shell dirname "$(DOTHERSIDE)")":"$(STATUSGO_LIBDIR)":"$(shell pwd)"/"$(shell dirname "$(NIM_WINDOWS_PREBUILT_DLLS)")":"$(PATH)" \ - STATUS_PORT="$(STATUS_PORT)" \ ./bin/nim_status_client.exe endif # "variables.mk" was not included diff --git a/src/app/utilsView/view.nim b/src/app/utilsView/view.nim index 255b692721..0f0447263f 100644 --- a/src/app/utilsView/view.nim +++ b/src/app/utilsView/view.nim @@ -30,9 +30,6 @@ QtObject: result.status = status result.setup - proc getDataDir*(self: UtilsView): string {.slot.} = - result = accountConstants.DATADIR - proc getOs*(self: UtilsView): string {.slot.} = if defined(windows): return "windows" diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 5d7304590f..8298f3ce9d 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -26,7 +26,7 @@ logScope: proc mainProc() = let fleets = - if defined(windows) and getEnv("NIM_STATUS_CLIENT_DEV").string == "": + if defined(windows) and defined(production): "/../resources/fleets.json" else: "/../fleets.json" @@ -46,7 +46,7 @@ proc mainProc() = let app = newQApplication("Status Desktop") let resources = - if defined(windows) and getEnv("NIM_STATUS_CLIENT_DEV").string == "": + if defined(windows) and defined(production): "/../resources/resources.rcc" else: "/../resources.rcc" @@ -55,9 +55,9 @@ proc mainProc() = let statusAppIcon = if defined(macosx): "" # not used in macOS - elif defined(windows) and getEnv("NIM_STATUS_CLIENT_DEV").string == "": + elif defined(windows) and defined(production): "/../resources/status.svg" - elif getEnv("NIM_STATUS_CLIENT_DEV").string != "": + elif defined(development): "/../status-dev.svg" else: "/../status.svg" @@ -65,7 +65,7 @@ proc mainProc() = app.icon(app.applicationDirPath & statusAppIcon) var i18nPath = "" - if (getEnv("NIM_STATUS_CLIENT_DEV").string != ""): + if defined(development): i18nPath = joinPath(getAppDir(), "../ui/i18n") elif (defined(windows)): i18nPath = joinPath(getAppDir(), "../resources/i18n") diff --git a/src/nim_windows_launcher.nim b/src/nim_windows_launcher.nim index f17642c08f..1930923ff4 100644 --- a/src/nim_windows_launcher.nim +++ b/src/nim_windows_launcher.nim @@ -1,9 +1,9 @@ -from os import getCurrentDir, joinPath +from os import getAppDir, joinPath from winlean import Handle, shellExecuteW const NULL: Handle = 0 -let cwd = getCurrentDir() -let workDir_str = joinPath(cwd, "bin") +let launcherDir = getAppDir() +let workDir_str = joinPath(launcherDir, "bin") let exePath_str = joinPath(workDir_str, "Status.exe") let open_str = "open" let params_str = "" diff --git a/src/status/libstatus/accounts.nim b/src/status/libstatus/accounts.nim index ad8b4ffed3..7f0e1aeedd 100644 --- a/src/status/libstatus/accounts.nim +++ b/src/status/libstatus/accounts.nim @@ -59,15 +59,9 @@ proc generateAlias*(publicKey: string): string = proc generateIdenticon*(publicKey: string): string = result = $status_go.identicon(publicKey) -proc ensureDir(dirname: string) = - if not existsDir(dirname): - # removeDir(dirname) - createDir(dirname) - proc initNode*() = - ensureDir(DATADIR) - ensureDir(KEYSTOREDIR) - + createDir(STATUSGODIR) + createDir(KEYSTOREDIR) discard $status_go.initKeystore(KEYSTOREDIR) proc parseIdentityImage*(images: JsonNode): IdentityImage = @@ -81,7 +75,7 @@ proc parseIdentityImage*(images: JsonNode): IdentityImage = result.large = image["uri"].getStr proc openAccounts*(): seq[NodeAccount] = - let strNodeAccounts = status_go.openAccounts(DATADIR).parseJson + let strNodeAccounts = status_go.openAccounts(STATUSGODIR).parseJson # FIXME fix serialization result = @[] if (strNodeAccounts.kind != JNull): diff --git a/src/status/libstatus/accounts/constants.nim b/src/status/libstatus/accounts/constants.nim index b06043643b..61797f8107 100644 --- a/src/status/libstatus/accounts/constants.nim +++ b/src/status/libstatus/accounts/constants.nim @@ -1,3 +1,4 @@ +import confutils import json import os @@ -170,36 +171,45 @@ var NODE_CONFIG* = %* { const DEFAULT_NETWORK_NAME* = "mainnet_rpc" -let sep = if defined(windows): "\\" else: "/" +const sep = when defined(windows): "\\" else: "/" -let homeDir = getHomeDir() - -let parentDir = - if getEnv("NIM_STATUS_CLIENT_DEV").string != "": - "." - elif homeDir == "": - "." - elif defined(macosx): - joinPath(homeDir, "Library", "Application Support") - elif defined(windows): - let targetDir = getEnv("LOCALAPPDATA").string - if targetDir == "": - joinPath(homeDir, "AppData", "Local") +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: - targetDir - else: - let targetDir = getEnv("XDG_CONFIG_HOME").string - if targetDir == "": - joinPath(homeDir, ".config") - else: - targetDir + let targetDir = getEnv("XDG_CONFIG_HOME").string + if targetDir == "": + joinPath(homeDir, ".config") + else: + targetDir + absolutePath(joinPath(parentDir, "Status")) -let clientDir = - if parentDir != ".": - joinPath(parentDir, "Status") - else: - parentDir +type StatusDesktopConfig = object + dataDir* {. + defaultValue: defaultDataDir() + desc: "Status Desktop data directory" + abbr: "d" .}: string -let DATADIR* = joinPath(clientDir, "data") & sep -let KEYSTOREDIR* = joinPath(clientDir, "data", "keystore") & sep -let TMPDIR* = joinPath(clientDir, "tmp") & sep +let desktopConfig = StatusDesktopConfig.load() + +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 + +createDir(DATADIR) +createDir(TMPDIR) diff --git a/src/status/tasks/marathon/mailserver/model.nim b/src/status/tasks/marathon/mailserver/model.nim index ac393e56e6..8be06bc2e7 100644 --- a/src/status/tasks/marathon/mailserver/model.nim +++ b/src/status/tasks/marathon/mailserver/model.nim @@ -62,7 +62,7 @@ proc newMailserverModel*(vptr: ByteAddress): MailserverModel = proc init*(self: MailserverModel) = trace "MailserverModel::init()" let fleets = - if defined(windows) and getEnv("NIM_STATUS_CLIENT_DEV").string == "": + if defined(windows) and defined(production): "/../resources/fleets.json" else: "/../fleets.json" diff --git a/vendor/nim-confutils b/vendor/nim-confutils new file mode 160000 index 0000000000..f091a70a5b --- /dev/null +++ b/vendor/nim-confutils @@ -0,0 +1 @@ +Subproject commit f091a70a5bf95ec772c8b4d9978e81b8ae89af0c