GeezerVison is showing github.com — Improved service layer (#1) · feather-framework/feather-push@a88b1e1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Package.resolved +2-2Lines changed: 2 additions & 2 deletions Collapse file Copy file name to clipboardExpand all lines: Package.swift +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,14 +4,19 @@ import PackageDescription | 4 | 4 | let package = Package( | 5 | 5 | name: "feather-push", | 6 | 6 | platforms: [ | 7 | | - .macOS(.v10_15) | | 7 | + .macOS(.v13), | | 8 | + .iOS(.v16), | | 9 | + .tvOS(.v16), | | 10 | + .watchOS(.v9), | 8 | 11 | ], | 9 | 12 | products: [ | 10 | 13 | .library(name: "FeatherPush", targets: ["FeatherPush"]), | 11 | 14 | .library(name: "XCTFeatherPush", targets: ["XCTFeatherPush"]), | 12 | 15 | ], | 13 | 16 | dependencies: [ | 14 | | - .package(url: "https://github.com/feather-framework/feather-service.git", .upToNextMinor(from: "0.1.0")), | | 17 | + .package(url: "https://github.com/feather-framework/feather-service.git", | | 18 | + .upToNextMinor(from: "0.2.0") | | 19 | + ), | 15 | 20 | ], | 16 | 21 | targets: [ | 17 | 22 | .target( | |
Collapse file Copy file name to clipboardExpand all lines: README.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Feather Push | 2 | 2 |
| 3 | | -An abstract push service for Feather CMS. | | 3 | +An abstract push notification service for Feather CMS. | 4 | 4 |
| 5 | 5 | ## Getting started | 6 | 6 |
| |
Collapse file Copy file name to clipboardExpand all lines: Sources/FeatherPush/Push.swift +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | // Created by Tibor Bodecs on 2023. 01. 16.. | 6 | 6 | // | 7 | 7 |
| 8 | | -public enum Delivery: String { | | 8 | +public enum Delivery: String, Sendable { | 9 | 9 | case normal | 10 | 10 | case silent | 11 | 11 | } | 12 | 12 |
| 13 | 13 | public enum Platform: Sendable { | 14 | | - case ios | | 14 | + case iOS | | 15 | + case macOS | | 16 | + case tvOS | | 17 | + case watchOS | | 18 | + case visionOS | | 19 | + case safari | 15 | 20 | case android | 16 | 21 | case web | 17 | 22 | case custom(String) | 18 | 23 | } | 19 | 24 |
| 20 | | -public struct Recipient { | | 25 | +public struct Recipient: Sendable { | 21 | 26 | public let token: String | 22 | 27 | public let platform: Platform | 23 | 28 |
| @@ -30,7 +35,7 @@ public struct Recipient { | 30 | 35 | } | 31 | 36 | } | 32 | 37 |
| 33 | | -public struct Notification { | | 38 | +public struct Notification: Sendable { | 34 | 39 | public let title: String | 35 | 40 | public let body: String | 36 | 41 | public let userInfo: [String: String] | |
Collapse file Copy file name to clipboard +49Lines changed: 49 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// | | 2 | +// Service+Push.swift | | 3 | +// FeatherPush | | 4 | +// | | 5 | +// Created by Tibor Bodecs on 20/11/2023. | | 6 | +// | | 7 | + | | 8 | +import FeatherService | | 9 | +import Logging | | 10 | + | | 11 | +public enum PushServiceID: ServiceID { | | 12 | + | | 13 | + /// default push service identifier | | 14 | + case `default` | | 15 | + | | 16 | + /// custom push service identifier | | 17 | + case custom(String) | | 18 | + | | 19 | + public var rawId: String { | | 20 | + switch self { | | 21 | + case .default: | | 22 | + return "push-id" | | 23 | + case .custom(let value): | | 24 | + return "\(value)-push-id" | | 25 | + } | | 26 | + } | | 27 | +} | | 28 | + | | 29 | +public extension ServiceRegistry { | | 30 | + | | 31 | + /// add a new push service using a context | | 32 | + func add( | | 33 | + _ contextFactoryBuilder: @autoclosure @escaping () -> ServiceContext, | | 34 | + id: PushServiceID = .default | | 35 | + ) async throws { | | 36 | + try await add(.init { contextFactoryBuilder() }, id: id) | | 37 | + } | | 38 | + | | 39 | + /// returns a push service by a given id | | 40 | + func push( | | 41 | + _ id: PushServiceID = .default, | | 42 | + logger: Logger? = nil | | 43 | + ) throws -> PushService { | | 44 | + guard let push = try get(id, logger: logger) as? PushService else { | | 45 | + fatalError("Push service not found, use `add` to register.") | | 46 | + } | | 47 | + return push | | 48 | + } | | 49 | +} |
|