fix(@desktop/profile): Fix loading the correct settings

Since #e0c53b7012354023e367c33093598f7523063aa6 settings where loaded
according to the username while they should be loaded after the public
key

As the public key is only available once the login happened, it needs
to be set when the profile is being initialized
This commit is contained in:
Anthony Laibe 2021-09-21 13:55:25 +02:00 committed by Iuri Matias
parent 3acabfd2a8
commit a44822d7f6
6 changed files with 23 additions and 43 deletions

View File

@ -62,7 +62,6 @@ QtObject:
keyUid: currNodeAcct.keyUid,
identityImage: currNodeAcct.identityImage
))
self.status.events.emit("currentAccountUpdated", AccountArgs(account: currNodeAcct))
QtProperty[QVariant] currentAccount:
read = getCurrentAccount

View File

@ -100,10 +100,7 @@ QtObject:
result = self.status.wallet.validateMnemonic(mnemonic.strip())
proc storeDerivedAndLogin(self: OnboardingView, password: string): string {.slot.} =
# In this moment we're sure that new account will be logged in, and emit signal.
let genAcc = self.currentAccount.account
let acc = Account(name: genAcc.name, keyUid: genAcc.keyUid, identicon: genAcc.identicon, identityImage: genAcc.identityImage)
self.status.events.emit("currentAccountUpdated", status_account_type.AccountArgs(account: acc))
try:
result = self.status.accounts.storeDerivedAndLogin(self.status.fleet.config, genAcc, password).toJson

View File

@ -35,9 +35,6 @@ proc delete*(self: ProfileController) =
delete self.variant
delete self.view
proc setSettingsFile*(self: ProfileController, username: string) =
self.view.setSettingsFile(username)
proc init*(self: ProfileController, account: Account) =
let profile = account.toProfileModel()
@ -62,6 +59,7 @@ proc init*(self: ProfileController, account: Account) =
self.view.devices.addDevices(status_devices.getAllDevices())
self.view.devices.setDeviceSetup(status_devices.isDeviceSetup())
self.view.setNewProfile(profile)
self.view.setSettingsFile(profile.id)
self.view.network.setNetwork(network)
self.view.ens.init()
self.view.initialized()

View File

@ -184,23 +184,6 @@ QtObject:
QtProperty[QVariant] picture:
read = getProfilePicture
proc settingsFileChanged*(self: ProfileView) {.signal.}
proc getSettingsFile*(self: ProfileView): string {.slot.} =
self.appService.localSettingsService.getSettingsFilePath
proc setSettingsFile*(self: ProfileView, username: string) =
if(username.len == 0 or
self.appService.localSettingsService.getSettingsFilePath.endsWith(username)):
return
self.appService.localSettingsService.updateSettingsFilePath(username)
self.settingsFileChanged()
QtProperty[string] settingsFile:
read = getSettingsFile
notify = settingsFileChanged
proc getGlobalSettingsFile*(self: ProfileView): string {.slot.} =
self.appService.localSettingsService.getGlobalSettingsFilePath
@ -213,6 +196,19 @@ QtObject:
QtProperty[QVariant] mutedChats:
read = getMutedChats
proc settingsFileChanged*(self: ProfileView) {.signal.}
proc getSettingsFile*(self: ProfileView): string {.slot.} =
self.appService.localSettingsService.getSettingsFilePath
proc setSettingsFile*(self: ProfileView, pubKey: string) =
self.appService.localSettingsService.updateSettingsFilePath(pubKey)
self.settingsFileChanged()
QtProperty[string] settingsFile:
read = getSettingsFile
notify = settingsFileChanged
proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} =
if (sendUserStatus == self.profile.sendUserStatus):
return

View File

@ -40,17 +40,16 @@ QtObject:
proc getSettingsFilePath*(self: LocalSettingsService): string =
return self.settingsFilePath
proc updateSettingsFilePath*(self: LocalSettingsService, username: string) =
if (username.len > 0):
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
warn "Failed to remove unused settings file", file=unknownSettingsPath
proc updateSettingsFilePath*(self: LocalSettingsService, pubKey: string) =
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
warn "Failed to remove unused settings file", file=unknownSettingsPath
self.settings.delete
self.settingsFilePath = os.joinPath(DATADIR, "qt", username)
self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat)
self.settings.delete
self.settingsFilePath = os.joinPath(DATADIR, "qt", pubKey)
self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat)
proc setValue*(self: LocalSettingsService, key: string, value: QVariant) =
self.settings.setValue(key, value)

View File

@ -194,7 +194,6 @@ proc mainProc() =
status.events.once("login") do(a: Args):
var args = AccountArgs(a)
appService.onLoggedIn()
# Reset login and onboarding to remove any mnemonic that would have been saved in the accounts list
@ -205,17 +204,9 @@ proc mainProc() =
onboarding.moveToAppState()
status.events.emit("loginCompleted", args)
proc updateProfileSettings(account: Account) =
profile.setSettingsFile(account.name)
status.events.on("currentAccountUpdated") do(a: Args):
var args = AccountArgs(a)
updateProfileSettings(args.account)
status.events.once("loginCompleted") do(a: Args):
var args = AccountArgs(a)
updateProfileSettings(args.account)
status.startMessenger()
profile.init(args.account)
wallet.init()