chore(@desktop/general): map `defined(macosx)` to custom constant

A custom `IS_MACOS` constant introduced which represents os defined
macosx, cause for devs working on macos is easier to change a single constant
in a single place to simulate some how the app would behave in some cases on
other platforms.

For example if the dev is working on macos, it's not possible to simulate linux only or
win only features that way, but it's definitely possible to check if mac only features are
not visible on other platforms.
This commit is contained in:
Sale Djenic 2023-01-20 09:31:11 +01:00 committed by saledjenic
parent 9ac0c159fe
commit c43b665db3
16 changed files with 54 additions and 29 deletions

View File

@ -1,5 +1,6 @@
import NimQml import NimQml
import ../../constants as main_constants
import local_account_settings import local_account_settings
QtObject: QtObject:
@ -51,7 +52,7 @@ QtObject:
read = getIsKeycardUser read = getIsKeycardUser
proc getUsingBiometricLogin*(self: UserProfile): bool {.slot.} = proc getUsingBiometricLogin*(self: UserProfile): bool {.slot.} =
if(not defined(macosx)): if(not main_constants.IS_MACOS):
return false return false
return self.localAccountSettings.getStoreToKeychainValue() == LS_VALUE_STORE return self.localAccountSettings.getStoreToKeychainValue() == LS_VALUE_STORE
QtProperty[bool] usingBiometricLogin: QtProperty[bool] usingBiometricLogin:

View File

@ -2,6 +2,7 @@ import Tables, chronicles, strutils, os
import uuids import uuids
import io_interface import io_interface
import ../../../constants as main_constants
import ../../global/global_singleton import ../../global/global_singleton
import ../../core/signals/types import ../../core/signals/types
import ../../core/eventemitter import ../../core/eventemitter
@ -400,7 +401,7 @@ proc isSelectedAccountAKeycardAccount*(self: Controller): bool =
proc tryToObtainDataFromKeychain*(self: Controller) = proc tryToObtainDataFromKeychain*(self: Controller) =
# Dealing with Keychain is the MacOS only feature # Dealing with Keychain is the MacOS only feature
if(not defined(macosx)): if not main_constants.IS_MACOS:
return return
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue() let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
if (value != LS_VALUE_STORE): if (value != LS_VALUE_STORE):
@ -504,7 +505,7 @@ proc checkForStoringPasswordToKeychain*(self: Controller) =
# This proc is called once user is logged in irrespective he is logged in # This proc is called once user is logged in irrespective he is logged in
# through the onboarding or login view. # through the onboarding or login view.
# This is MacOS only feature # This is MacOS only feature
if not defined(macosx): if not main_constants.IS_MACOS:
return return
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue() let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()

View File

@ -55,7 +55,7 @@ method resolveKeycardNextState*(self: KeycardEnterPinState, keycardFlowType: str
return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState) return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState)
if keycardFlowType == ResponseTypeValueKeycardFlowResult: if keycardFlowType == ResponseTypeValueKeycardFlowResult:
controller.setKeycardEvent(keycardEvent) controller.setKeycardEvent(keycardEvent)
if not defined(macosx): if not main_constants.IS_MACOS:
controller.setupKeycardAccount(false) controller.setupKeycardAccount(false)
return nil return nil
return createState(StateType.Biometrics, self.flowType, self) return createState(StateType.Biometrics, self.flowType, self)

View File

@ -33,6 +33,14 @@ method resolveKeycardNextState*(self: KeycardEnterPukState, keycardFlowType: str
if keycardEvent.pukRetries > 0: if keycardEvent.pukRetries > 0:
return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState) return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState)
return createState(StateType.KeycardMaxPukRetriesReached, self.flowType, self.getBackState) return createState(StateType.KeycardMaxPukRetriesReached, self.flowType, self.getBackState)
if keycardFlowType == ResponseTypeValueKeycardFlowResult:
controller.setKeycardEvent(keycardEvent)
controller.setPukValid(true)
if not main_constants.IS_MACOS:
controller.setupKeycardAccount(false)
return nil
let backState = findBackStateWithTargetedStateType(self, StateType.RecoverOldUser)
return createState(StateType.Biometrics, self.flowType, backState)
if self.flowType == FlowType.AppLogin: if self.flowType == FlowType.AppLogin:
if keycardFlowType == ResponseTypeValueEnterNewPIN and if keycardFlowType == ResponseTypeValueEnterNewPIN and
keycardEvent.error.len > 0 and keycardEvent.error.len > 0 and

View File

@ -19,7 +19,7 @@ method getNextPrimaryState*(self: KeycardPinSetState, controller: Controller): S
return createState(StateType.UserProfileCreate, self.flowType, self.getBackState) return createState(StateType.UserProfileCreate, self.flowType, self.getBackState)
if self.flowType == FlowType.FirstRunOldUserKeycardImport: if self.flowType == FlowType.FirstRunOldUserKeycardImport:
if controller.getValidPuk(): if controller.getValidPuk():
if not defined(macosx): if not main_constants.IS_MACOS:
return nil return nil
return createState(StateType.Biometrics, self.flowType, self.getBackState) return createState(StateType.Biometrics, self.flowType, self.getBackState)
return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState) return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState)
@ -31,20 +31,25 @@ method getNextPrimaryState*(self: KeycardPinSetState, controller: Controller): S
return nil return nil
return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState) return createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState)
if self.flowType == FlowType.LostKeycardReplacement: if self.flowType == FlowType.LostKeycardReplacement:
if not defined(macosx): if not main_constants.IS_MACOS:
return nil return nil
return createState(StateType.Biometrics, self.flowType, self.getBackState) return createState(StateType.Biometrics, self.flowType, self.getBackState)
method executePrimaryCommand*(self: KeycardPinSetState, controller: Controller) = method executePrimaryCommand*(self: KeycardPinSetState, controller: Controller) =
if defined(macosx): if self.flowType == FlowType.FirstRunOldUserKeycardImport:
if main_constants.IS_MACOS:
return return
# if controller.getValidPuk(): if controller.getValidPuk():
# controller.setupKeycardAccount(false) controller.setupKeycardAccount(false)
# return
if self.flowType == FlowType.AppLogin: if self.flowType == FlowType.AppLogin:
if controller.getRecoverUsingSeedPhraseWhileLogin(): if controller.getRecoverUsingSeedPhraseWhileLogin():
controller.startLoginFlowAutomatically(controller.getPin()) controller.startLoginFlowAutomatically(controller.getPin())
return
if controller.getValidPuk():
controller.setupKeycardAccount(false)
if self.flowType == FlowType.LostKeycardReplacement: if self.flowType == FlowType.LostKeycardReplacement:
if main_constants.IS_MACOS:
return
controller.startLoginFlowAutomatically(controller.getPin()) controller.startLoginFlowAutomatically(controller.getPin())
method resolveKeycardNextState*(self: KeycardPinSetState, keycardFlowType: string, keycardEvent: KeycardEvent, method resolveKeycardNextState*(self: KeycardPinSetState, keycardFlowType: string, keycardEvent: KeycardEvent,

View File

@ -47,7 +47,7 @@ method resolveKeycardNextState*(self: KeycardWrongPinState, keycardFlowType: str
return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState) return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState)
if keycardFlowType == ResponseTypeValueKeycardFlowResult: if keycardFlowType == ResponseTypeValueKeycardFlowResult:
controller.setKeycardEvent(keycardEvent) controller.setKeycardEvent(keycardEvent)
if not defined(macosx): if not main_constants.IS_MACOS:
controller.setupKeycardAccount(false) controller.setupKeycardAccount(false)
return nil return nil
return createState(StateType.Biometrics, self.flowType, self) return createState(StateType.Biometrics, self.flowType, self)

View File

@ -38,7 +38,7 @@ method resolveKeycardNextState*(self: KeycardWrongPukState, keycardFlowType: str
if keycardFlowType == ResponseTypeValueKeycardFlowResult: if keycardFlowType == ResponseTypeValueKeycardFlowResult:
controller.setKeycardEvent(keycardEvent) controller.setKeycardEvent(keycardEvent)
controller.setPukValid(true) controller.setPukValid(true)
if not defined(macosx): if not main_constants.IS_MACOS:
controller.setupKeycardAccount(false) controller.setupKeycardAccount(false)
return nil return nil
return createState(StateType.Biometrics, self.flowType, self.getBackState) return createState(StateType.Biometrics, self.flowType, self.getBackState)

View File

@ -1,4 +1,5 @@
import chronicles import chronicles
import ../../../../constants as main_constants
import ../../../../app_service/service/keycard/constants import ../../../../app_service/service/keycard/constants
import ../controller import ../controller
from ../../../../app_service/service/keycard/service import KCSFlowType from ../../../../app_service/service/keycard/service import KCSFlowType

View File

@ -9,7 +9,7 @@ proc delete*(self: UserProfileChatKeyState) =
self.State.delete self.State.delete
method executePrimaryCommand*(self: UserProfileChatKeyState, controller: Controller) = method executePrimaryCommand*(self: UserProfileChatKeyState, controller: Controller) =
if defined(macosx): if main_constants.IS_MACOS:
return return
let storeToKeychain = false # false, cause we don't have keychain support for other than mac os let storeToKeychain = false # false, cause we don't have keychain support for other than mac os
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys: if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys:
@ -26,6 +26,6 @@ method getNextPrimaryState*(self: UserProfileChatKeyState, controller: Controlle
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys or if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys or
self.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard or self.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard or
self.flowType == FlowType.FirstRunOldUserKeycardImport: self.flowType == FlowType.FirstRunOldUserKeycardImport:
if not defined(macosx): if not main_constants.IS_MACOS:
return nil return nil
return createState(StateType.Biometrics, self.flowType, self) return createState(StateType.Biometrics, self.flowType, self)

View File

@ -9,12 +9,12 @@ proc delete*(self: UserProfileConfirmPasswordState) =
self.State.delete self.State.delete
method getNextPrimaryState*(self: UserProfileConfirmPasswordState, controller: Controller): State = method getNextPrimaryState*(self: UserProfileConfirmPasswordState, controller: Controller): State =
if not defined(macosx): if not main_constants.IS_MACOS:
return nil return nil
return createState(StateType.Biometrics, self.flowType, self) return createState(StateType.Biometrics, self.flowType, self)
method executePrimaryCommand*(self: UserProfileConfirmPasswordState, controller: Controller) = method executePrimaryCommand*(self: UserProfileConfirmPasswordState, controller: Controller) =
if defined(macosx): if main_constants.IS_MACOS:
return return
let storeToKeychain = false # false, cause we don't have keychain support for other than mac os let storeToKeychain = false # false, cause we don't have keychain support for other than mac os
if self.flowType == FlowType.FirstRunNewUserNewKeys: if self.flowType == FlowType.FirstRunNewUserNewKeys:

View File

@ -6,6 +6,7 @@ import internal/[state, state_factory]
import models/generated_account_item as gen_acc_item import models/generated_account_item as gen_acc_item
import models/login_account_item as login_acc_item import models/login_account_item as login_acc_item
import models/fetching_data_model as fetch_model import models/fetching_data_model as fetch_model
import ../../../constants as main_constants
import ../../global/global_singleton import ../../global/global_singleton
import ../../global/app_translatable_constants as atc import ../../global/app_translatable_constants as atc
import ../../core/eventemitter import ../../core/eventemitter
@ -89,7 +90,7 @@ method load*[T](self: Module[T]) =
self.view.setGeneratedAccountList(accounts) self.view.setGeneratedAccountList(accounts)
if(self.controller.shouldStartWithOnboardingScreen()): if(self.controller.shouldStartWithOnboardingScreen()):
if defined(macosx): if main_constants.IS_MACOS:
self.view.setCurrentStartupState(newNotificationState(FlowType.General, nil)) self.view.setCurrentStartupState(newNotificationState(FlowType.General, nil))
else: else:
self.view.setCurrentStartupState(newWelcomeState(FlowType.General, nil)) self.view.setCurrentStartupState(newWelcomeState(FlowType.General, nil))

View File

@ -2,6 +2,8 @@ import json, random, times, strutils, sugar, os, re, chronicles
import nimcrypto import nimcrypto
import signing_phrases import signing_phrases
import ../../constants as main_constants
const STATUS_DOMAIN* = ".stateofus.eth" const STATUS_DOMAIN* = ".stateofus.eth"
const ETH_DOMAIN* = ".eth" const ETH_DOMAIN* = ".eth"
@ -39,7 +41,7 @@ proc defaultDataDir(): string =
parentDir(getAppDir()) parentDir(getAppDir())
elif homeDir == "": elif homeDir == "":
getCurrentDir() getCurrentDir()
elif defined(macosx): elif main_constants.IS_MACOS:
joinPath(homeDir, "Library", "Application Support") joinPath(homeDir, "Library", "Application Support")
elif defined(windows): elif defined(windows):
let targetDir = getEnv("LOCALAPPDATA").string let targetDir = getEnv("LOCALAPPDATA").string

View File

@ -340,7 +340,7 @@ QtObject:
result["KeyStoreDir"] = newJString(self.keyStoreDir.replace(main_constants.STATUSGODIR, "")) result["KeyStoreDir"] = newJString(self.keyStoreDir.replace(main_constants.STATUSGODIR, ""))
proc setLocalAccountSettingsFile(self: Service) = proc setLocalAccountSettingsFile(self: Service) =
if(defined(macosx) and self.getLoggedInAccount.isValid()): if(main_constants.IS_MACOS and self.getLoggedInAccount.isValid()):
singletonInstance.localAccountSettings.setFileName(self.getLoggedInAccount.name) singletonInstance.localAccountSettings.setFileName(self.getLoggedInAccount.name)
proc addKeycardDetails(self: Service, settingsJson: var JsonNode, accountData: var JsonNode) = proc addKeycardDetails(self: Service, settingsJson: var JsonNode, accountData: var JsonNode) =

View File

@ -1,5 +1,7 @@
import NimQml import NimQml
import json_serialization, chronicles, os, strformat, re import json_serialization, chronicles, os, strformat, re
import ../../../constants as main_constants
import ../../../app/global/global_singleton import ../../../app/global/global_singleton
import ../../../app/core/eventemitter import ../../../app/core/eventemitter
import ../../../app/core/signals/types import ../../../app/core/signals/types
@ -47,7 +49,7 @@ proc init*(self: Service) =
self.i18nPath = joinPath(getAppDir(), "i18n") self.i18nPath = joinPath(getAppDir(), "i18n")
elif (defined(windows)): elif (defined(windows)):
self.i18nPath = joinPath(getAppDir(), "../resources/i18n") self.i18nPath = joinPath(getAppDir(), "../resources/i18n")
elif (defined(macosx)): elif (main_constants.IS_MACOS):
self.i18nPath = joinPath(getAppDir(), "../i18n") self.i18nPath = joinPath(getAppDir(), "../i18n")
elif (defined(linux)): elif (defined(linux)):
self.i18nPath = joinPath(getAppDir(), "../i18n") self.i18nPath = joinPath(getAppDir(), "../i18n")

View File

@ -3,6 +3,10 @@ import os, sequtils, strutils
import # vendor libs import # vendor libs
confutils confutils
## 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)
const sep* = when defined(windows): "\\" else: "/" const sep* = when defined(windows): "\\" else: "/"
proc defaultDataDir*(): string = proc defaultDataDir*(): string =
@ -12,7 +16,7 @@ proc defaultDataDir*(): string =
parentDir(getAppDir()) parentDir(getAppDir())
elif homeDir == "": elif homeDir == "":
getCurrentDir() getCurrentDir()
elif defined(macosx): elif IS_MACOS:
joinPath(homeDir, "Library", "Application Support") joinPath(homeDir, "Library", "Application Support")
elif defined(windows): elif defined(windows):
let targetDir = getEnv("LOCALAPPDATA").string let targetDir = getEnv("LOCALAPPDATA").string
@ -46,7 +50,7 @@ type StatusDesktopConfig = object
# Credit: https://github.com/bitcoin/bitcoin/blame/b6e34afe9735faf97d6be7a90fafd33ec18c0cbb/src/util/system.cpp#L383-L389 # Credit: https://github.com/bitcoin/bitcoin/blame/b6e34afe9735faf97d6be7a90fafd33ec18c0cbb/src/util/system.cpp#L383-L389
var cliParams = commandLineParams() var cliParams = commandLineParams()
if defined(macosx): if IS_MACOS:
cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_")) cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_"))
let desktopConfig = StatusDesktopConfig.load(cliParams) let desktopConfig = StatusDesktopConfig.load(cliParams)

View File

@ -3,7 +3,7 @@ import NimQml, chronicles, os, strformat, strutils, times, md5, json
import status_go import status_go
import keycard_go import keycard_go
import app/core/main import app/core/main
import constants import constants as main_constants
import app/global/global_singleton import app/global/global_singleton
import app/boot/app_controller import app/boot/app_controller
@ -29,14 +29,14 @@ proc determineOpenUri(): string =
proc determineStatusAppIconPath(): string = proc determineStatusAppIconPath(): string =
if defined(production): if defined(production):
if defined(macosx): if main_constants.IS_MACOS:
return "" # not used in macOS return "" # not used in macOS
elif defined(windows): elif main_constants.IS_MACOS:
return "/../resources/status.svg" return "/../resources/status.svg"
else: else:
return "/../status.svg" return "/../status.svg"
else: else:
if defined(macosx): if main_constants.IS_MACOS:
return "" # not used in macOS return "" # not used in macOS
else: else:
return "/../status-dev.svg" return "/../status-dev.svg"
@ -78,7 +78,7 @@ proc setupRemoteSignalsHandling() =
keycard_go.setSignalEventCallback(callbackKeycardGo) keycard_go.setSignalEventCallback(callbackKeycardGo)
proc mainProc() = proc mainProc() =
if defined(macosx) and defined(production): if main_constants.IS_MACOS and defined(production):
setCurrentDir(getAppDir()) setCurrentDir(getAppDir())
ensureDirectories(DATADIR, TMPDIR, LOGDIR) ensureDirectories(DATADIR, TMPDIR, LOGDIR)
@ -121,7 +121,7 @@ proc mainProc() =
let dockShowAppEvent = newStatusDockShowAppEventObject(singletonInstance.engine) let dockShowAppEvent = newStatusDockShowAppEventObject(singletonInstance.engine)
let osThemeEvent = newStatusOSThemeEventObject(singletonInstance.engine) let osThemeEvent = newStatusOSThemeEventObject(singletonInstance.engine)
if not defined(macosx): if not main_constants.IS_MACOS:
app.icon(app.applicationDirPath & statusAppIconPath) app.icon(app.applicationDirPath & statusAppIconPath)
prepareLogging() prepareLogging()