Skip to content

Commit

Permalink
Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Miiha authored and github-actions[bot] committed Sep 7, 2023
1 parent aeaa026 commit 5f14471
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.6.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.6.0")
],
targets: [
.target(
Expand Down
71 changes: 42 additions & 29 deletions Sources/ComposableUserNotifications/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,70 @@ public struct UserNotificationClient {
case openSettingsForNotification(_ notification: Notification?)
}

public var add: @Sendable (UNNotificationRequest) async throws -> Void =
unimplemented("\(Self.self).add")
public var add: @Sendable (UNNotificationRequest) async throws -> Void =
unimplemented("\(Self.self).add")

#if !os(tvOS)
public var deliveredNotifications: @Sendable () async -> [Notification] = unimplemented("\(Self.self).deliveredNotifications")
#endif
#if !os(tvOS)
public var deliveredNotifications: @Sendable () async -> [Notification] = unimplemented(
"\(Self.self).deliveredNotifications")
#endif

#if !os(tvOS)
public var notificationCategories: () async -> Set<UNNotificationCategory> = unimplemented("\(Self.self).deliveredNotifications")
#endif
#if !os(tvOS)
public var notificationCategories: () async -> Set<UNNotificationCategory> = unimplemented(
"\(Self.self).deliveredNotifications")
#endif

public var notificationSettings: () async -> Notification.Settings = unimplemented("\(Self.self).notificationSettings")
public var notificationSettings: () async -> Notification.Settings = unimplemented(
"\(Self.self).notificationSettings")

public var pendingNotificationRequests: () async -> [Notification.Request] = unimplemented("\(Self.self).pendingNotificationRequests")
public var pendingNotificationRequests: () async -> [Notification.Request] = unimplemented(
"\(Self.self).pendingNotificationRequests")

#if !os(tvOS)
public var removeAllDeliveredNotifications: () async -> Void = unimplemented("\(Self.self).removeAllDeliveredNotifications")
#endif
#if !os(tvOS)
public var removeAllDeliveredNotifications: () async -> Void = unimplemented(
"\(Self.self).removeAllDeliveredNotifications")
#endif

public var removeAllPendingNotificationRequests: () async -> Void = unimplemented("\(Self.self).removeAllPendingNotificationRequests")
public var removeAllPendingNotificationRequests: () async -> Void = unimplemented(
"\(Self.self).removeAllPendingNotificationRequests")

#if !os(tvOS)
public var removeDeliveredNotificationsWithIdentifiers: ([String]) async -> Void = unimplemented("\(Self.self).removeDeliveredNotificationsWithIdentifiers")
#endif
#if !os(tvOS)
public var removeDeliveredNotificationsWithIdentifiers: ([String]) async -> Void =
unimplemented("\(Self.self).removeDeliveredNotificationsWithIdentifiers")
#endif

public var removePendingNotificationRequestsWithIdentifiers: ([String]) async -> Void = unimplemented("\(Self.self).removePendingNotificationRequestsWithIdentifiers")
public var removePendingNotificationRequestsWithIdentifiers: ([String]) async -> Void =
unimplemented("\(Self.self).removePendingNotificationRequestsWithIdentifiers")

public var requestAuthorization: (UNAuthorizationOptions) async throws -> Bool =
unimplemented("\(Self.self).requestAuthorization")
unimplemented("\(Self.self).requestAuthorization")

#if !os(tvOS)
public var setNotificationCategories: (Set<UNNotificationCategory>) async -> Void = unimplemented("\(Self.self).setNotificationCategories")
#endif
#if !os(tvOS)
public var setNotificationCategories: (Set<UNNotificationCategory>) async -> Void =
unimplemented("\(Self.self).setNotificationCategories")
#endif

public var supportsContentExtensions: () -> Bool = unimplemented("\(Self.self).supportsContentExtensions")
public var supportsContentExtensions: () -> Bool = unimplemented(
"\(Self.self).supportsContentExtensions")

/// This Effect represents calls to the `UNUserNotificationCenterDelegate`.
/// Handling the completion handlers of the `UNUserNotificationCenterDelegate`s methods
/// by multiple observers might lead to unexpected behaviour.
public var delegate: @Sendable () -> AsyncStream<DelegateAction> = unimplemented("\(Self.self).delegate", placeholder: .finished)
public var delegate: @Sendable () -> AsyncStream<DelegateAction> = unimplemented(
"\(Self.self).delegate", placeholder: .finished)
}

extension UserNotificationClient.DelegateAction: Equatable {
public static func == (lhs: UserNotificationClient.DelegateAction, rhs: UserNotificationClient.DelegateAction) -> Bool {
public static func == (
lhs: UserNotificationClient.DelegateAction, rhs: UserNotificationClient.DelegateAction
) -> Bool {
switch (lhs, rhs) {
case let (.willPresentNotification(lhs, _), .willPresentNotification(rhs, _)):
return lhs == rhs
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
case let (.didReceiveResponse(lhs, _), .didReceiveResponse(rhs, _)):
return lhs == rhs
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
case let (.didReceiveResponse(lhs, _), .didReceiveResponse(rhs, _)):
return lhs == rhs
#endif
case let (.openSettingsForNotification(lhs), .openSettingsForNotification(rhs)):
return lhs == rhs
default:
Expand Down
108 changes: 54 additions & 54 deletions Sources/ComposableUserNotifications/LiveKey.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import Dependencies
import Foundation
import UserNotifications

extension UserNotificationClient: DependencyKey {
Expand All @@ -9,44 +9,44 @@ extension UserNotificationClient: DependencyKey {
var client = UserNotificationClient()
client.add = { try await UNUserNotificationCenter.current().add($0) }

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.deliveredNotifications = {
let notifications = await center.deliveredNotifications()
return notifications.map(Notification.init(rawValue:))
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.deliveredNotifications = {
let notifications = await center.deliveredNotifications()
return notifications.map(Notification.init(rawValue:))
}
#endif

client.notificationSettings = {
let settings = await center.notificationSettings()
return Notification.Settings(rawValue: settings)
}

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.notificationCategories = {
await center.notificationCategories()
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.notificationCategories = {
await center.notificationCategories()
}
#endif

client.pendingNotificationRequests = {
let requests = await center.pendingNotificationRequests()
return requests.map(Notification.Request.init(rawValue:))
}

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.removeAllDeliveredNotifications = {
center.removeAllDeliveredNotifications()
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.removeAllDeliveredNotifications = {
center.removeAllDeliveredNotifications()
}
#endif

client.removeAllPendingNotificationRequests = {
center.removeAllPendingNotificationRequests()
}

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.removeDeliveredNotificationsWithIdentifiers = {
center.removeDeliveredNotifications(withIdentifiers: $0)
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.removeDeliveredNotificationsWithIdentifiers = {
center.removeDeliveredNotifications(withIdentifiers: $0)
}
#endif

client.removePendingNotificationRequestsWithIdentifiers = {
center.removePendingNotificationRequests(withIdentifiers: $0)
Expand All @@ -56,11 +56,11 @@ extension UserNotificationClient: DependencyKey {
try await center.requestAuthorization(options: $0)
}

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.setNotificationCategories = {
center.setNotificationCategories($0)
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
client.setNotificationCategories = {
center.setNotificationCategories($0)
}
#endif

client.supportsContentExtensions = {
center.supportsContentExtensions
Expand All @@ -80,8 +80,8 @@ extension UserNotificationClient: DependencyKey {
}
}

private extension UserNotificationClient {
class Delegate: NSObject, UNUserNotificationCenterDelegate {
extension UserNotificationClient {
fileprivate class Delegate: NSObject, UNUserNotificationCenterDelegate {
let continuation: AsyncStream<UserNotificationClient.DelegateAction>.Continuation

init(continuation: AsyncStream<UserNotificationClient.DelegateAction>.Continuation) {
Expand All @@ -92,7 +92,7 @@ private extension UserNotificationClient {
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler:
@escaping (UNNotificationPresentationOptions) -> Void
@escaping (UNNotificationPresentationOptions) -> Void
) {
self.continuation.yield(
.willPresentNotification(
Expand All @@ -102,29 +102,29 @@ private extension UserNotificationClient {
)
}

#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
let wrappedResponse = Notification.Response(rawValue: response)
self.continuation.yield(
.didReceiveResponse(wrappedResponse) { completionHandler() }
)
}
#endif

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
func userNotificationCenter(
_ center: UNUserNotificationCenter,
openSettingsFor notification: UNNotification?
) {
let mappedNotification = notification.map(Notification.init)
self.continuation.yield(
.openSettingsForNotification(mappedNotification)
)
}
#endif
#if os(iOS) || os(macOS) || os(watchOS) || targetEnvironment(macCatalyst)
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
let wrappedResponse = Notification.Response(rawValue: response)
self.continuation.yield(
.didReceiveResponse(wrappedResponse) { completionHandler() }
)
}
#endif

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
func userNotificationCenter(
_ center: UNUserNotificationCenter,
openSettingsFor notification: UNNotification?
) {
let mappedNotification = notification.map(Notification.init)
self.continuation.yield(
.openSettingsForNotification(mappedNotification)
)
}
#endif
}
}
Loading

0 comments on commit 5f14471

Please sign in to comment.