Skip to content

Commit c9b9625

Browse files
committed
Improve unauthenticated flow and avoid scene activation when not needed
1 parent 14259d4 commit c9b9625

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Sources/App/Scenes/SceneManager.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,15 @@ final class SceneManager {
120120
) -> Guarantee<DelegateType> {
121121
if let active = existingScenes(for: query.activity).first,
122122
let delegate = active.delegate as? DelegateType {
123+
Current.Log.verbose("Ready to activate scene \(active.session.persistentIdentifier)")
124+
123125
let options = UIScene.ActivationRequestOptions()
124126
options.requestingScene = active
125127

126128
// Only activate scene if not activated already
127-
guard UIApplication.shared.connectedScenes.contains(where: { $0 != active }) else {
129+
guard active.activationState != .foregroundActive else {
130+
Current.Log
131+
.verbose("Did not activate scene \(active.session.persistentIdentifier), it was already active")
128132
return .value(delegate)
129133
}
130134

@@ -155,6 +159,8 @@ final class SceneManager {
155159
pendingResolvers[token] = PendingResolver(resolver: resolver)
156160

157161
if supportsMultipleScenes {
162+
Current.Log.verbose("Ready to request new scene activation for \(query.activity)")
163+
158164
let activity = query.activity.activity
159165
activity.userInfo = [
160166
Self.activityUserInfoKeyResolver: token,

Sources/App/WebView/WebViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg
964964
view.titleLabel?.numberOfLines = 0
965965
view.bodyLabel?.numberOfLines = 0
966966

967+
// Avoid retrying from Home Assistant UI since this is a dead end
968+
webView.load(URLRequest(url: URL(string: "about:blank")!))
967969
SwiftMessages.show(config: config, view: view)
968970
}
969971
}

Sources/Shared/API/Authentication/TokenManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public class TokenManager {
163163
)
164164
Current.clientEventStore.addEvent(event)
165165
Current.modelManager.unsubscribe()
166+
Current.api(for: server)?.connection.disconnect()
166167
Current.onboardingObservation.needed(.unauthenticated(
167168
server.identifier.rawValue,
168169
underlying.asAFError?.responseCode ?? -1

0 commit comments

Comments
 (0)