Avoid race conditions between the home screen's crash alert and Sentry's onLastRunStatusDetermined

By converting the `lastCrashEventID` to a publisher that the VM can just listen to instead of relying on start to match a pre-set event
This commit is contained in:
Stefan Ceriu
2026-08-13 09:25:27 +03:00
parent 9f648803f9
commit d4d74dd8f8
14 changed files with 33 additions and 32 deletions
@@ -39,8 +39,6 @@ enum HomeScreenCoordinatorAction {
final class HomeScreenCoordinator: CoordinatorProtocol {
private var viewModel: HomeScreenViewModelProtocol
// periphery:ignore - only used in release builds
private let bugReportService: BugReportServiceProtocol
private let actionsSubject: PassthroughSubject<HomeScreenCoordinatorAction, Never> = .init()
private var cancellables = Set<AnyCancellable>()
@@ -54,9 +52,9 @@ final class HomeScreenCoordinator: CoordinatorProtocol {
selectedRoomPublisher: parameters.selectedRoomPublisher,
appSettings: parameters.appSettings,
analyticsService: parameters.analyticsService,
bugReportService: parameters.bugReportService,
notificationManager: parameters.notificationManager,
userIndicatorController: parameters.userIndicatorController)
bugReportService = parameters.bugReportService
viewModel.actions
.sink { [weak self] action in
@@ -100,16 +98,6 @@ final class HomeScreenCoordinator: CoordinatorProtocol {
// MARK: - Public
func start() {
#if !DEBUG
// Note: bugReportService.isEnabled doesn't determine if a user has opted in to Analytics/Sentry.
// Therefore we use lastCrashEventID as this will only be set if we have crash ID from Sentry.
if bugReportService.crashedLastRun, bugReportService.lastCrashEventID != nil {
viewModel.presentCrashedLastRunAlert()
}
#endif
}
func toPresentable() -> AnyView {
AnyView(HomeScreen(context: viewModel.context))
}
@@ -17,6 +17,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
private let userSession: UserSessionProtocol
private let spaceFilterSubject: CurrentValueSubject<SpaceServiceFilter?, Never>
private let analyticsService: AnalyticsServiceProtocol
private let bugReportService: BugReportServiceProtocol
private let appSettings: AppSettings
private let notificationManager: NotificationManagerProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
@@ -33,10 +34,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
selectedRoomPublisher: CurrentValuePublisher<String?, Never>,
appSettings: AppSettings,
analyticsService: AnalyticsServiceProtocol,
bugReportService: BugReportServiceProtocol,
notificationManager: NotificationManagerProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.userSession = userSession
self.analyticsService = analyticsService
self.bugReportService = bugReportService
self.appSettings = appSettings
self.notificationManager = notificationManager
self.userIndicatorController = userIndicatorController
@@ -141,6 +144,15 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
.weakAssign(to: \.state.selectedSpaceFilter, on: self)
.store(in: &cancellables)
bugReportService.lastCrashEventIDSubject
.compactMap { $0 }
.first()
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
self?.presentCrashedLastRunAlert()
}
.store(in: &cancellables)
Task {
state.reportRoomEnabled = await userSession.clientProxy.isReportRoomSupported
}
@@ -220,6 +220,7 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: .volatile(),
analyticsService: AnalyticsServiceMock(.init()),
bugReportService: BugReportServiceMock(.init()),
notificationManager: NotificationManagerMock(),
userIndicatorController: UserIndicatorControllerMock())
}
@@ -147,6 +147,7 @@ struct HomeScreenEmptyStateView_Previews: PreviewProvider, TestablePreview {
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: .volatile(),
analyticsService: AnalyticsServiceMock(.init()),
bugReportService: BugReportServiceMock(.init()),
notificationManager: NotificationManagerMock(),
userIndicatorController: UserIndicatorControllerMock())
}()
@@ -203,6 +203,7 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview {
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: .volatile(),
analyticsService: AnalyticsServiceMock(.init()),
bugReportService: BugReportServiceMock(.init()),
notificationManager: NotificationManagerMock(),
userIndicatorController: UserIndicatorControllerMock())
}
@@ -135,6 +135,7 @@ struct HomeScreenKnockedCell_Previews: PreviewProvider, TestablePreview {
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: .volatile(),
analyticsService: AnalyticsServiceMock(.init()),
bugReportService: BugReportServiceMock(.init()),
notificationManager: NotificationManagerMock(),
userIndicatorController: UserIndicatorControllerMock())
}
@@ -124,6 +124,7 @@ struct HomeScreenRecoveryKeyConfirmationBanner_Previews: PreviewProvider, Testab
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: .volatile(),
analyticsService: AnalyticsServiceMock(.init()),
bugReportService: BugReportServiceMock(.init()),
notificationManager: NotificationManagerMock(),
userIndicatorController: UserIndicatorControllerMock())
}