Skip to content

Commit

Permalink
feat: make sure we call applicationState from the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jul 4, 2023
1 parent 06cf460 commit 3b81ca7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MailCore/Utils/ApplicationStatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import UIKit

/// Something that reads the application state if available
public protocol ApplicationStatable {
var applicationState: UIApplication.State? { get }
@MainActor var applicationState: UIApplication.State? { get }
}
28 changes: 15 additions & 13 deletions MailCore/Utils/MessagePresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,22 @@ public final class MessagePresenter: MessagePresentable {
// MARK: - private

private func showInContext(message: String, action: MessageAction?) {
// check not in extension mode
guard !Bundle.main.isExtension else {
presentInLocalNotification(message: message, action: action)
return
Task { @MainActor in
// check not in extension mode
guard !Bundle.main.isExtension else {
presentInLocalNotification(message: message, action: action)
return
}

// if app not in foreground, we use the local notifications
guard applicationState.applicationState == .active else {
presentInLocalNotification(message: message, action: action)
return
}

// Present the message as we are in foreground app context
presentInSnackbar(message: message, action: action)
}

// if app not in foreground, we use the local notifications
guard applicationState.applicationState == .active else {
presentInLocalNotification(message: message, action: action)
return
}

// Present the message as we are in foreground app context
presentInSnackbar(message: message, action: action)
}

// MARK: Private
Expand Down

0 comments on commit 3b81ca7

Please sign in to comment.