diff --git a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift index a7c2a11f90..e7a5df5fbd 100644 --- a/DuckDuckGo/AppLifecycle/AppStateTransitions.swift +++ b/DuckDuckGo/AppLifecycle/AppStateTransitions.swift @@ -90,17 +90,48 @@ extension Background { return Active(application: application) case .openURL: return self - case .launching, .suspending, .backgrounding: + case .backgrounding: + return DoubleBackground() + case .launching, .suspending: return handleUnexpectedEvent(event) } } } +extension DoubleBackground { + + func apply(event: AppEvent) -> any AppState { + // report event so we know what events can be called at this moment, but do not let SM be stuck in this state just not to be flooded with these events + _ = handleUnexpectedEvent(event) + + switch event { + case .activating(let application): + return Active(application: application) + case .suspending(let application): + return Inactive(application: application) + case .launching, .backgrounding, .openURL: + return self + } + + } + +} + extension InactiveBackground { func apply(event: AppEvent) -> any AppState { - handleUnexpectedEvent(event) + // report event so we know what events can be called at this moment, but do not let SM be stuck in this state just not to be flooded with these events + _ = handleUnexpectedEvent(event) + + switch event { + case .activating(let application): + return Active(application: application) + case .suspending(let application): + return Inactive(application: application) + case .launching, .backgrounding, .openURL: + return self + } } } diff --git a/DuckDuckGo/AppLifecycle/AppStates/Background.swift b/DuckDuckGo/AppLifecycle/AppStates/Background.swift index 9332e41b6b..71b0ab4c1a 100644 --- a/DuckDuckGo/AppLifecycle/AppStates/Background.swift +++ b/DuckDuckGo/AppLifecycle/AppStates/Background.swift @@ -26,3 +26,7 @@ struct Background: AppState { } } + +struct DoubleBackground: AppState { + +}