Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-14836: Fix vault state on app re-entry from background #1149

Merged
merged 6 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ public class ServiceContainer: Services { // swiftlint:disable:this type_body_le

let twoStepLoginService = DefaultTwoStepLoginService(environmentService: environmentService)


let pasteboardService = DefaultPasteboardService(
errorReporter: errorReporter,
stateService: stateService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
startEventTimer()
await checkIfExtensionSwitchedAccounts()
await checkAccountsForTimeout()
await coordinator?.handleEvent(.didStart)
matt-livefront marked this conversation as resolved.
Show resolved Hide resolved
await completeAutofillAccountSetupIfEnabled()
#if DEBUG
debugWillEnterForeground?()
Expand Down Expand Up @@ -493,7 +494,7 @@
///
/// - Parameter loginRequest: The login request.
///
func showLoginRequest(_ loginRequest: LoginRequest) {

Check warning on line 497 in BitwardenShared/UI/Platform/Application/AppProcessor.swift

View workflow job for this annotation

GitHub Actions / Test

main actor-isolated instance method 'showLoginRequest' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode
coordinator?.navigate(to: .loginRequest(loginRequest))
}

Expand All @@ -504,7 +505,7 @@
/// - loginRequest: The login request to show.
/// - showAlert: Whether to show the alert or simply switch the account.
///
func switchAccounts(to account: Account, for loginRequest: LoginRequest, showAlert: Bool) {

Check warning on line 508 in BitwardenShared/UI/Platform/Application/AppProcessor.swift

View workflow job for this annotation

GitHub Actions / Test

main actor-isolated instance method 'switchAccounts(to:for:showAlert:)' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode
DispatchQueue.main.async {
if showAlert {
self.coordinator?.showAlert(.confirmation(
Expand Down
19 changes: 13 additions & 6 deletions BitwardenShared/UI/Platform/Application/AppProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
notificationCenterService.willEnterForegroundSubject.send()
try await waitForAsync { self.willEnterForegroundCalled == 2 }

XCTAssertTrue(coordinator.events.isEmpty)
XCTAssertEqual(coordinator.events.last, .didStart)
XCTAssertEqual(errorReporter.errors as? [BitwardenTestError], [.example])
}

Expand All @@ -277,7 +277,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
notificationCenterService.willEnterForegroundSubject.send()
try await waitForAsync { self.willEnterForegroundCalled == 2 }

XCTAssertTrue(coordinator.events.isEmpty)
XCTAssertEqual(coordinator.events.last, .didStart)
}

/// `init()` subscribes to will enter foreground events and handles switching accounts if the
Expand All @@ -294,7 +294,14 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
notificationCenterService.willEnterForegroundSubject.send()
try await waitForAsync { self.willEnterForegroundCalled == 2 }

XCTAssertEqual(coordinator.events, [.switchAccounts(userId: "2", isAutomatic: false)])
XCTAssertEqual(
coordinator.events,
[
.didStart,
.switchAccounts(userId: "2", isAutomatic: false),
.didStart,
]
)
}

/// `init()` subscribes to will enter foreground events and doesn't check for an account switch
Expand Down Expand Up @@ -323,7 +330,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
notificationCenterService.willEnterForegroundSubject.send()
try await waitForAsync { willEnterForegroundCalled == 2 }

XCTAssertTrue(coordinator.events.isEmpty)
XCTAssertEqual(coordinator.events.last, .didStart)
}

/// `init()` subscribes to will enter foreground events and restarts the app is there's no
Expand All @@ -339,7 +346,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
notificationCenterService.willEnterForegroundSubject.send()
try await waitForAsync { self.willEnterForegroundCalled == 2 }

XCTAssertEqual(coordinator.events, [.didStart])
XCTAssertEqual(coordinator.events, [.didStart, .didStart, .didStart])
}

/// `init()` sets the `AppProcessor` as the delegate of any necessary services.
Expand Down Expand Up @@ -915,7 +922,7 @@ class AppProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body
waitFor(!coordinator.events.isEmpty)

XCTAssertTrue(appModule.appCoordinator.isStarted)
XCTAssertEqual(appModule.appCoordinator.events, [.didStart])
XCTAssertEqual(appModule.appCoordinator.events, [.didStart, .didStart])
XCTAssertEqual(migrationService.didPerformMigrations, true)
}

Expand Down
Loading