Skip to content

Commit def26b4

Browse files
Add a legacy notification command for reloading widgets and move types to an enum
1 parent 9c5b944 commit def26b4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Sources/PushServer/SharedPush/Sources/NotificationParserLegacy.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public struct LegacyNotificationParserImpl: LegacyNotificationParser {
5959
}
6060

6161
let commandPayload: CommandPayload? = {
62-
switch input["message"] as? String {
63-
case "request_location_update", "request_location_updates":
62+
switch LegacyNotificationCommandType(rawValue: input["message"] as? String ?? "") {
63+
case .locationUpdate, .locationUpdates:
6464
return .init("request_location_update")
65-
case "clear_badge":
65+
case .clearBadge:
6666
return .init(isAlert: true, payload: ["aps": ["badge": 0]])
67-
case "clear_notification":
67+
case .clearNotification:
6868
var homeassistant = [String: Any]()
6969

7070
if let tag = data["tag"] {
@@ -76,8 +76,10 @@ public struct LegacyNotificationParserImpl: LegacyNotificationParser {
7676
}
7777

7878
return .init("clear_notification", homeassistant: homeassistant)
79-
case "update_complications":
79+
case .updateComplications:
8080
return .init("update_complications")
81+
case .updateWidgets:
82+
return .init("update_widgets")
8183
default: return nil
8284
}
8385
}()
@@ -246,6 +248,15 @@ public struct LegacyNotificationParserImpl: LegacyNotificationParser {
246248
}
247249
}
248250

251+
enum LegacyNotificationCommandType: String {
252+
case locationUpdate = "request_location_update"
253+
case locationUpdates = "request_location_updates"
254+
case clearBadge = "clear_badge"
255+
case clearNotification = "clear_notification"
256+
case updateComplications = "update_complications"
257+
case updateWidgets = "update_wigets"
258+
}
259+
249260
private extension Dictionary where Value == Any {
250261
mutating func mutate<SomeValue>(
251262
_ key: Key,

Sources/Shared/Notifications/NotificationCommands/NotificationsCommandManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class NotificationCommandManager {
2020
public init() {
2121
register(command: "request_location_update", handler: HandlerLocationUpdate())
2222
register(command: "clear_notification", handler: HandlerClearNotification())
23-
if #available(iOS 14, watchOS 9, macOS 11, *) {
23+
if #available(watchOS 9, *) {
2424
register(command: "reload_widgets", handler: HandlerReloadWidgets())
2525
}
2626

@@ -98,10 +98,10 @@ private struct HandlerClearNotification: NotificationCommandHandler {
9898
}
9999
}
100100

101-
@available(iOS 14, watchOS 9, macOS 11, *)
101+
@available(watchOS 9, *)
102102
private struct HandlerReloadWidgets: NotificationCommandHandler {
103103
func handle(_ payload: [String: Any]) -> Promise<Void> {
104-
Current.Log.verbose("reloading widgets")
104+
Current.Log.verbose("Reloading widgets triggered by notification command")
105105
return Promise<Void> { seal in
106106
DispatchQueue.main.async {
107107
WidgetCenter.shared.reloadTimelines(ofKind: "io.robbie.HomeAssistant.widget-gauge")

0 commit comments

Comments
 (0)