57 lines
1.7 KiB
Swift
57 lines
1.7 KiB
Swift
//
|
|
// PushManager.swift
|
|
// PushNotifications
|
|
//
|
|
// Created by Shadowfacts on 4/7/24.
|
|
//
|
|
|
|
import Foundation
|
|
import OSLog
|
|
#if canImport(Sentry)
|
|
import Sentry
|
|
#endif
|
|
import Pachyderm
|
|
import UserAccounts
|
|
|
|
public struct PushManager {
|
|
@MainActor
|
|
public static let shared = createPushManager()
|
|
|
|
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "PushManager")
|
|
|
|
private init() {}
|
|
|
|
@MainActor
|
|
private static func createPushManager() -> any _PushManager {
|
|
guard let info = Bundle.main.object(forInfoDictionaryKey: "TuskerInfo") as? [String: Any],
|
|
let scheme = info["PushProxyScheme"] as? String,
|
|
let host = info["PushProxyHost"] as? String,
|
|
!scheme.isEmpty,
|
|
!host.isEmpty else {
|
|
logger.debug("Missing proxy info, push disabled")
|
|
return DisabledPushManager()
|
|
}
|
|
var endpoint = URLComponents()
|
|
endpoint.scheme = scheme
|
|
endpoint.host = host
|
|
let url = endpoint.url!
|
|
logger.debug("Push notifications enabled with proxy \(url.absoluteString, privacy: .public)")
|
|
return PushManagerImpl(endpoint: url)
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
public protocol _PushManager {
|
|
var enabled: Bool { get }
|
|
var pushProxyRegistration: PushProxyRegistration? { get }
|
|
|
|
func pushSubscription(account: UserAccountInfo) -> PushSubscription?
|
|
|
|
func register(transactionID: UInt64) async throws -> PushProxyRegistration
|
|
func unregister() async throws
|
|
func updateIfNecessary() async
|
|
|
|
func didRegisterForRemoteNotifications(deviceToken: Data)
|
|
func didFailToRegisterForRemoteNotifications(error: any Error)
|
|
}
|