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

Add DoubleBackground state #3710

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
@@ -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
}
}

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

}

struct DoubleBackground: AppState {

}

Unchanged files with check annotations Beta

allowedQueryReservedCharacters: allowedQueryReservedCharacters,
headers: headers)
let request = APIRequest(configuration: configuration, urlSession: .session(useMainThreadCallbackQueue: true))
request.fetch { _, error in

Check warning on line 275 in Core/Pixel.swift

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 275 in Core/Pixel.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 275 in Core/Pixel.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
Logger.general.debug("Pixel fired \(pixelName, privacy: .public) \(params, privacy: .public)")
onComplete(error)
}
let configuration = APIRequest.Configuration(url: .atb)
let request = APIRequest(configuration: configuration, urlSession: .session())
request.fetch { response, error in

Check warning on line 80 in Core/StatisticsLoader.swift

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 80 in Core/StatisticsLoader.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 80 in Core/StatisticsLoader.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
if let error = error {
Logger.general.error("Initial atb request failed with error: \(error.localizedDescription, privacy: .public)")
completion()
let configuration = APIRequest.Configuration(url: url)
let request = APIRequest(configuration: configuration, urlSession: .session())
request.fetch { _, error in

Check warning on line 102 in Core/StatisticsLoader.swift

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 102 in Core/StatisticsLoader.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
if let error = error {
Logger.general.error("Exit request failed with error: \(error.localizedDescription, privacy: .public)")
completion()
let configuration = APIRequest.Configuration(url: url)
let request = APIRequest(configuration: configuration, urlSession: .session())
request.fetch { response, error in

Check warning on line 148 in Core/StatisticsLoader.swift

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 148 in Core/StatisticsLoader.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
if let error = error {
Logger.general.error("Search atb request failed with error: \(error.localizedDescription, privacy: .public)")
completion()
let configuration = APIRequest.Configuration(url: url)
let request = APIRequest(configuration: configuration, urlSession: .session())
request.fetch { response, error in

Check warning on line 178 in Core/StatisticsLoader.swift

GitHub Actions / Unit Tests

'fetch(completion:)' is deprecated: Please use 'APIService' instead.

Check warning on line 178 in Core/StatisticsLoader.swift

GitHub Actions / Make Release Build

'fetch(completion:)' is deprecated: Please use 'APIService' instead.
if let error = error {
Logger.general.error("App atb request failed with error: \(error.localizedDescription, privacy: .public)")
completion()
Logger.sync.debug("Favicons Fetching is in progress. Starting background task to allow it to gracefully complete.")
var taskID: UIBackgroundTaskIdentifier!
taskID = application.beginBackgroundTask(withName: "Cancelled Favicons Fetching Completion Task") {

Check warning on line 199 in Core/SyncBookmarksAdapter.swift

GitHub Actions / Unit Tests

'taskID' mutated after capture by sendable closure

Check warning on line 199 in Core/SyncBookmarksAdapter.swift

GitHub Actions / Make Release Build

'taskID' mutated after capture by sendable closure
Logger.sync.debug("Forcing background task completion")
application.endBackgroundTask(taskID)
}
import Bookmarks
import Foundation
extension FavoritesDisplayMode: LosslessStringConvertible {

Check warning on line 23 in DuckDuckGo/FavoritesDisplayMode+UserDefaults.swift

GitHub Actions / Unit Tests

extension declares a conformance of imported type 'FavoritesDisplayMode' to imported protocol 'LosslessStringConvertible'; this will not behave correctly if the owners of 'Bookmarks' introduce this conformance in the future
static let `default` = FavoritesDisplayMode.displayNative(.mobile)
public init?(_ description: String) {