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:
parent
9ac0c159fe
commit
c43b665db3
|
@ -1,5 +1,6 @@
|
|||
import NimQml
|
||||
|
||||
import ../../constants as main_constants
|
||||
import local_account_settings
|
||||
|
||||
QtObject:
|
||||
|
@ -51,7 +52,7 @@ QtObject:
|
|||
read = getIsKeycardUser
|
||||
|
||||
proc getUsingBiometricLogin*(self: UserProfile): bool {.slot.} =
|
||||
if(not defined(macosx)):
|
||||
if(not main_constants.IS_MACOS):
|
||||
return false
|
||||
return self.localAccountSettings.getStoreToKeychainValue() == LS_VALUE_STORE
|
||||
QtProperty[bool] usingBiometricLogin:
|
||||
|
|
|
@ -2,6 +2,7 @@ import Tables, chronicles, strutils, os
|
|||
import uuids
|
||||
import io_interface
|
||||
|
||||
import ../../../constants as main_constants
|
||||
import ../../global/global_singleton
|
||||
import ../../core/signals/types
|
||||
import ../../core/eventemitter
|
||||
|
@ -400,7 +401,7 @@ proc isSelectedAccountAKeycardAccount*(self: Controller): bool =
|
|||
|
||||
proc tryToObtainDataFromKeychain*(self: Controller) =
|
||||
# Dealing with Keychain is the MacOS only feature
|
||||
if(not defined(macosx)):
|
||||
if not main_constants.IS_MACOS:
|
||||
return
|
||||
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
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
|
||||
# through the onboarding or login view.
|
||||
# This is MacOS only feature
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
return
|
||||
|
||||
let value = singletonInstance.localAccountSettings.getStoreToKeychainValue()
|
||||
|
|
|
@ -55,7 +55,7 @@ method resolveKeycardNextState*(self: KeycardEnterPinState, keycardFlowType: str
|
|||
return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult:
|
||||
controller.setKeycardEvent(keycardEvent)
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
controller.setupKeycardAccount(false)
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self)
|
|
@ -33,6 +33,14 @@ method resolveKeycardNextState*(self: KeycardEnterPukState, keycardFlowType: str
|
|||
if keycardEvent.pukRetries > 0:
|
||||
return createState(StateType.KeycardWrongPuk, 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 keycardFlowType == ResponseTypeValueEnterNewPIN and
|
||||
keycardEvent.error.len > 0 and
|
||||
|
|
|
@ -19,7 +19,7 @@ method getNextPrimaryState*(self: KeycardPinSetState, controller: Controller): S
|
|||
return createState(StateType.UserProfileCreate, self.flowType, self.getBackState)
|
||||
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
|
||||
if controller.getValidPuk():
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
return nil
|
||||
return createState(StateType.Biometrics, 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 createState(StateType.KeycardWrongPuk, self.flowType, self.getBackState)
|
||||
if self.flowType == FlowType.LostKeycardReplacement:
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self.getBackState)
|
||||
|
||||
method executePrimaryCommand*(self: KeycardPinSetState, controller: Controller) =
|
||||
if defined(macosx):
|
||||
return
|
||||
# if controller.getValidPuk():
|
||||
# controller.setupKeycardAccount(false)
|
||||
# return
|
||||
if self.flowType == FlowType.FirstRunOldUserKeycardImport:
|
||||
if main_constants.IS_MACOS:
|
||||
return
|
||||
if controller.getValidPuk():
|
||||
controller.setupKeycardAccount(false)
|
||||
if self.flowType == FlowType.AppLogin:
|
||||
if controller.getRecoverUsingSeedPhraseWhileLogin():
|
||||
controller.startLoginFlowAutomatically(controller.getPin())
|
||||
return
|
||||
if controller.getValidPuk():
|
||||
controller.setupKeycardAccount(false)
|
||||
if self.flowType == FlowType.LostKeycardReplacement:
|
||||
if main_constants.IS_MACOS:
|
||||
return
|
||||
controller.startLoginFlowAutomatically(controller.getPin())
|
||||
|
||||
method resolveKeycardNextState*(self: KeycardPinSetState, keycardFlowType: string, keycardEvent: KeycardEvent,
|
||||
|
|
|
@ -47,7 +47,7 @@ method resolveKeycardNextState*(self: KeycardWrongPinState, keycardFlowType: str
|
|||
return createState(StateType.KeycardMaxPairingSlotsReached, self.flowType, self.getBackState)
|
||||
if keycardFlowType == ResponseTypeValueKeycardFlowResult:
|
||||
controller.setKeycardEvent(keycardEvent)
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
controller.setupKeycardAccount(false)
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self)
|
|
@ -38,7 +38,7 @@ method resolveKeycardNextState*(self: KeycardWrongPukState, keycardFlowType: str
|
|||
if keycardFlowType == ResponseTypeValueKeycardFlowResult:
|
||||
controller.setKeycardEvent(keycardEvent)
|
||||
controller.setPukValid(true)
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
controller.setupKeycardAccount(false)
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self.getBackState)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import chronicles
|
||||
import ../../../../constants as main_constants
|
||||
import ../../../../app_service/service/keycard/constants
|
||||
import ../controller
|
||||
from ../../../../app_service/service/keycard/service import KCSFlowType
|
||||
|
|
|
@ -9,7 +9,7 @@ proc delete*(self: UserProfileChatKeyState) =
|
|||
self.State.delete
|
||||
|
||||
method executePrimaryCommand*(self: UserProfileChatKeyState, controller: Controller) =
|
||||
if defined(macosx):
|
||||
if main_constants.IS_MACOS:
|
||||
return
|
||||
let storeToKeychain = false # false, cause we don't have keychain support for other than mac os
|
||||
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys:
|
||||
|
@ -26,6 +26,6 @@ method getNextPrimaryState*(self: UserProfileChatKeyState, controller: Controlle
|
|||
if self.flowType == FlowType.FirstRunNewUserNewKeycardKeys or
|
||||
self.flowType == FlowType.FirstRunNewUserImportSeedPhraseIntoKeycard or
|
||||
self.flowType == FlowType.FirstRunOldUserKeycardImport:
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self)
|
||||
|
|
|
@ -9,12 +9,12 @@ proc delete*(self: UserProfileConfirmPasswordState) =
|
|||
self.State.delete
|
||||
|
||||
method getNextPrimaryState*(self: UserProfileConfirmPasswordState, controller: Controller): State =
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
return nil
|
||||
return createState(StateType.Biometrics, self.flowType, self)
|
||||
|
||||
method executePrimaryCommand*(self: UserProfileConfirmPasswordState, controller: Controller) =
|
||||
if defined(macosx):
|
||||
if main_constants.IS_MACOS:
|
||||
return
|
||||
let storeToKeychain = false # false, cause we don't have keychain support for other than mac os
|
||||
if self.flowType == FlowType.FirstRunNewUserNewKeys:
|
||||
|
|
|
@ -6,6 +6,7 @@ import internal/[state, state_factory]
|
|||
import models/generated_account_item as gen_acc_item
|
||||
import models/login_account_item as login_acc_item
|
||||
import models/fetching_data_model as fetch_model
|
||||
import ../../../constants as main_constants
|
||||
import ../../global/global_singleton
|
||||
import ../../global/app_translatable_constants as atc
|
||||
import ../../core/eventemitter
|
||||
|
@ -89,7 +90,7 @@ method load*[T](self: Module[T]) =
|
|||
self.view.setGeneratedAccountList(accounts)
|
||||
|
||||
if(self.controller.shouldStartWithOnboardingScreen()):
|
||||
if defined(macosx):
|
||||
if main_constants.IS_MACOS:
|
||||
self.view.setCurrentStartupState(newNotificationState(FlowType.General, nil))
|
||||
else:
|
||||
self.view.setCurrentStartupState(newWelcomeState(FlowType.General, nil))
|
||||
|
|
|
@ -2,6 +2,8 @@ import json, random, times, strutils, sugar, os, re, chronicles
|
|||
import nimcrypto
|
||||
import signing_phrases
|
||||
|
||||
import ../../constants as main_constants
|
||||
|
||||
const STATUS_DOMAIN* = ".stateofus.eth"
|
||||
const ETH_DOMAIN* = ".eth"
|
||||
|
||||
|
@ -39,7 +41,7 @@ proc defaultDataDir(): string =
|
|||
parentDir(getAppDir())
|
||||
elif homeDir == "":
|
||||
getCurrentDir()
|
||||
elif defined(macosx):
|
||||
elif main_constants.IS_MACOS:
|
||||
joinPath(homeDir, "Library", "Application Support")
|
||||
elif defined(windows):
|
||||
let targetDir = getEnv("LOCALAPPDATA").string
|
||||
|
|
|
@ -340,7 +340,7 @@ QtObject:
|
|||
result["KeyStoreDir"] = newJString(self.keyStoreDir.replace(main_constants.STATUSGODIR, ""))
|
||||
|
||||
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)
|
||||
|
||||
proc addKeycardDetails(self: Service, settingsJson: var JsonNode, accountData: var JsonNode) =
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import NimQml
|
||||
import json_serialization, chronicles, os, strformat, re
|
||||
|
||||
import ../../../constants as main_constants
|
||||
import ../../../app/global/global_singleton
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/signals/types
|
||||
|
@ -47,7 +49,7 @@ proc init*(self: Service) =
|
|||
self.i18nPath = joinPath(getAppDir(), "i18n")
|
||||
elif (defined(windows)):
|
||||
self.i18nPath = joinPath(getAppDir(), "../resources/i18n")
|
||||
elif (defined(macosx)):
|
||||
elif (main_constants.IS_MACOS):
|
||||
self.i18nPath = joinPath(getAppDir(), "../i18n")
|
||||
elif (defined(linux)):
|
||||
self.i18nPath = joinPath(getAppDir(), "../i18n")
|
||||
|
|
|
@ -3,6 +3,10 @@ import os, sequtils, strutils
|
|||
import # vendor libs
|
||||
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: "/"
|
||||
|
||||
proc defaultDataDir*(): string =
|
||||
|
@ -12,7 +16,7 @@ proc defaultDataDir*(): string =
|
|||
parentDir(getAppDir())
|
||||
elif homeDir == "":
|
||||
getCurrentDir()
|
||||
elif defined(macosx):
|
||||
elif IS_MACOS:
|
||||
joinPath(homeDir, "Library", "Application Support")
|
||||
elif defined(windows):
|
||||
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
|
||||
|
||||
var cliParams = commandLineParams()
|
||||
if defined(macosx):
|
||||
if IS_MACOS:
|
||||
cliParams.keepIf(proc(p: string): bool = not p.startsWith("-psn_"))
|
||||
|
||||
let desktopConfig = StatusDesktopConfig.load(cliParams)
|
||||
|
|
|
@ -3,7 +3,7 @@ import NimQml, chronicles, os, strformat, strutils, times, md5, json
|
|||
import status_go
|
||||
import keycard_go
|
||||
import app/core/main
|
||||
import constants
|
||||
import constants as main_constants
|
||||
|
||||
import app/global/global_singleton
|
||||
import app/boot/app_controller
|
||||
|
@ -29,14 +29,14 @@ proc determineOpenUri(): string =
|
|||
|
||||
proc determineStatusAppIconPath(): string =
|
||||
if defined(production):
|
||||
if defined(macosx):
|
||||
if main_constants.IS_MACOS:
|
||||
return "" # not used in macOS
|
||||
elif defined(windows):
|
||||
elif main_constants.IS_MACOS:
|
||||
return "/../resources/status.svg"
|
||||
else:
|
||||
return "/../status.svg"
|
||||
else:
|
||||
if defined(macosx):
|
||||
if main_constants.IS_MACOS:
|
||||
return "" # not used in macOS
|
||||
else:
|
||||
return "/../status-dev.svg"
|
||||
|
@ -78,7 +78,7 @@ proc setupRemoteSignalsHandling() =
|
|||
keycard_go.setSignalEventCallback(callbackKeycardGo)
|
||||
|
||||
proc mainProc() =
|
||||
if defined(macosx) and defined(production):
|
||||
if main_constants.IS_MACOS and defined(production):
|
||||
setCurrentDir(getAppDir())
|
||||
|
||||
ensureDirectories(DATADIR, TMPDIR, LOGDIR)
|
||||
|
@ -121,7 +121,7 @@ proc mainProc() =
|
|||
let dockShowAppEvent = newStatusDockShowAppEventObject(singletonInstance.engine)
|
||||
let osThemeEvent = newStatusOSThemeEventObject(singletonInstance.engine)
|
||||
|
||||
if not defined(macosx):
|
||||
if not main_constants.IS_MACOS:
|
||||
app.icon(app.applicationDirPath & statusAppIconPath)
|
||||
|
||||
prepareLogging()
|
||||
|
|
Loading…
Reference in New Issue