Skip to content

Commit

Permalink
Add DoubleBackground state (#3710)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208930420896743/f

**Description**:
Add DoubleBackground state to discover what events are called after we
end up in this weird state.
  • Loading branch information
jaceklyp authored Dec 10, 2024
1 parent d43e29d commit 5a5104b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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 {

}

0 comments on commit 5a5104b

Please sign in to comment.