Refresh saved accounts before per-window account changes
1 file changed,
+9
−0
Sources/RastrilloApple/NativeConnection.swift+9 −0
CI failed — run details
CI log
=== test === swift test Fetching binary artifact https://github.com/sparkle-project/Sparkle/releases/download/2.9.6/Sparkle-for-Swift-Package-Manager.zip from cache error: failed validating archive from 'https://github.com/sparkle-project/Sparkle/releases/download/2.9.6/Sparkle-for-Swift-Package-Manager.zip' which is required by binary target 'Sparkle': could not find executable for 'unzip' error: fatalError make: *** [Makefile:4: test] Error 1 amadan: step test failed: exit status 2 amadan: job failed at step test — its output is above, not at the tail of this log
diff --git a/Sources/RastrilloApple/NativeConnection.swift b/Sources/RastrilloApple/NativeConnection.swift| index 95a87bf..dfc7ce0 100644 |
| --- a/Sources/RastrilloApple/NativeConnection.swift |
| +++ b/Sources/RastrilloApple/NativeConnection.swift |
| @@ -20,6 +20,11 @@ import Security |
| private let accountsKey = "native.accounts" |
| private let defaults: UserDefaults |
| + private func reloadAccounts() { |
| + if let data = defaults.data(forKey: accountsKey), |
| + let saved = try? JSONDecoder().decode([NativeAccount].self, from: data) { accounts = saved } |
| + } |
| + |
| private func persistAccounts() { |
| if let data = try? JSONEncoder().encode(accounts) { |
| defaults.set(data, forKey: accountsKey) |
| @@ -27,12 +32,14 @@ import Security |
| } |
| public func showAccounts() { |
| + reloadAccounts() |
| cancel() |
| client = nil |
| activeAccountID = nil |
| } |
| public func selectAccount(_ account: NativeAccount) { |
| + reloadAccounts() |
| cancel() |
| guard accounts.contains(account), (try? NativeHTTP.origin(account.origin.absoluteString)) == account.origin, |
| let credential = NativeCredentials.read(account.credentialKey) else { |
| @@ -57,6 +64,7 @@ import Security |
| let account = NativeAccount(id: UUID().uuidString, origin: origin, |
| name: label.isEmpty ? (origin.host ?? origin.absoluteString) : label) |
| try NativeCredentials.save(credential, origin: account.credentialKey) |
| + reloadAccounts() |
| accounts.insert(account, at: 0) |
| persistAccounts() |
| activeAccountID = account.id |
| @@ -165,6 +173,7 @@ import Security |
| } |
| public func cancel() { pendingID = nil; task?.cancel(); task = nil; browser.cancel(); signingIn = false; code = ""; browserURL = nil } |
| public func signOut() { |
| + reloadAccounts() |
| cancel() |
| if let client { |
| if let activeAccountID { |