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, keyUid: currNodeAcct.keyUid,
identityImage: currNodeAcct.identityImage identityImage: currNodeAcct.identityImage
)) ))
self.status.events.emit("currentAccountUpdated", AccountArgs(account: currNodeAcct))
QtProperty[QVariant] currentAccount: QtProperty[QVariant] currentAccount:
read = getCurrentAccount read = getCurrentAccount

View File

@ -100,10 +100,7 @@ QtObject:
result = self.status.wallet.validateMnemonic(mnemonic.strip()) result = self.status.wallet.validateMnemonic(mnemonic.strip())
proc storeDerivedAndLogin(self: OnboardingView, password: string): string {.slot.} = 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 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: try:
result = self.status.accounts.storeDerivedAndLogin(self.status.fleet.config, genAcc, password).toJson 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.variant
delete self.view delete self.view
proc setSettingsFile*(self: ProfileController, username: string) =
self.view.setSettingsFile(username)
proc init*(self: ProfileController, account: Account) = proc init*(self: ProfileController, account: Account) =
let profile = account.toProfileModel() let profile = account.toProfileModel()
@ -62,6 +59,7 @@ proc init*(self: ProfileController, account: Account) =
self.view.devices.addDevices(status_devices.getAllDevices()) self.view.devices.addDevices(status_devices.getAllDevices())
self.view.devices.setDeviceSetup(status_devices.isDeviceSetup()) self.view.devices.setDeviceSetup(status_devices.isDeviceSetup())
self.view.setNewProfile(profile) self.view.setNewProfile(profile)
self.view.setSettingsFile(profile.id)
self.view.network.setNetwork(network) self.view.network.setNetwork(network)
self.view.ens.init() self.view.ens.init()
self.view.initialized() self.view.initialized()

View File

@ -184,23 +184,6 @@ QtObject:
QtProperty[QVariant] picture: QtProperty[QVariant] picture:
read = getProfilePicture 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.} = proc getGlobalSettingsFile*(self: ProfileView): string {.slot.} =
self.appService.localSettingsService.getGlobalSettingsFilePath self.appService.localSettingsService.getGlobalSettingsFilePath
@ -213,6 +196,19 @@ QtObject:
QtProperty[QVariant] mutedChats: QtProperty[QVariant] mutedChats:
read = getMutedChats 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.} = proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} =
if (sendUserStatus == self.profile.sendUserStatus): if (sendUserStatus == self.profile.sendUserStatus):
return return

View File

@ -40,17 +40,16 @@ QtObject:
proc getSettingsFilePath*(self: LocalSettingsService): string = proc getSettingsFilePath*(self: LocalSettingsService): string =
return self.settingsFilePath return self.settingsFilePath
proc updateSettingsFilePath*(self: LocalSettingsService, username: string) = proc updateSettingsFilePath*(self: LocalSettingsService, pubKey: string) =
if (username.len > 0): let unknownSettingsPath = os.joinPath(DATADIR, "qt", UNKNOWN_ACCOUNT)
let unknownSettingsPath = os.joinPath(DATADIR, "qt", UNKNOWN_ACCOUNT) if (not unknownSettingsPath.tryRemoveFile):
if (not unknownSettingsPath.tryRemoveFile): # Only fails if the file exists and an there was an error removing it
# 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
# More info: https://nim-lang.org/docs/os.html#tryRemoveFile%2Cstring warn "Failed to remove unused settings file", file=unknownSettingsPath
warn "Failed to remove unused settings file", file=unknownSettingsPath
self.settings.delete self.settings.delete
self.settingsFilePath = os.joinPath(DATADIR, "qt", username) self.settingsFilePath = os.joinPath(DATADIR, "qt", pubKey)
self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat) self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat)
proc setValue*(self: LocalSettingsService, key: string, value: QVariant) = proc setValue*(self: LocalSettingsService, key: string, value: QVariant) =
self.settings.setValue(key, value) self.settings.setValue(key, value)

View File

@ -194,7 +194,6 @@ proc mainProc() =
status.events.once("login") do(a: Args): status.events.once("login") do(a: Args):
var args = AccountArgs(a) var args = AccountArgs(a)
appService.onLoggedIn() appService.onLoggedIn()
# Reset login and onboarding to remove any mnemonic that would have been saved in the accounts list # 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() onboarding.moveToAppState()
status.events.emit("loginCompleted", args) 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): status.events.once("loginCompleted") do(a: Args):
var args = AccountArgs(a) var args = AccountArgs(a)
updateProfileSettings(args.account)
status.startMessenger() status.startMessenger()
profile.init(args.account) profile.init(args.account)
wallet.init() wallet.init()