Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Add DoubleBackground state #3710

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 33 additions & 2 deletions DuckDuckGo/AppLifecycle/AppStateTransitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

}
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/AppLifecycle/AppStates/Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ struct Background: AppState {
}

}

struct DoubleBackground: AppState {

}
Loading