Add support for tvOS
This commit is contained in:
@@ -7,25 +7,42 @@ public enum FilePath {
|
||||
public extension FilePath {
|
||||
static let groupName = "group.\(packageName)"
|
||||
|
||||
static var sharedDirectory = defaultSharedDirectory
|
||||
private static let defaultSharedDirectory: URL! = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: FilePath.groupName)
|
||||
|
||||
private static var defaultSharedDirectory: URL {
|
||||
FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: FilePath.groupName)!
|
||||
}
|
||||
|
||||
static var cacheDirectory: URL {
|
||||
sharedDirectory
|
||||
#if os(iOS)
|
||||
static let sharedDirectory = defaultSharedDirectory!
|
||||
#elseif os(tvOS)
|
||||
static let sharedDirectory = defaultSharedDirectory
|
||||
.appendingPathComponent("Library", isDirectory: true)
|
||||
.appendingPathComponent("Caches", isDirectory: true)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
static var sharedDirectory: URL! = defaultSharedDirectory
|
||||
#endif
|
||||
|
||||
static var workingDirectory: URL {
|
||||
cacheDirectory.appendingPathComponent("Working", isDirectory: true)
|
||||
}
|
||||
#if os(iOS)
|
||||
static let cacheDirectory = sharedDirectory
|
||||
.appendingPathComponent("Library", isDirectory: true)
|
||||
.appendingPathComponent("Caches", isDirectory: true)
|
||||
#elseif os(tvOS)
|
||||
static let cacheDirectory = sharedDirectory
|
||||
#elseif os(macOS)
|
||||
static var cacheDirectory: URL {
|
||||
sharedDirectory
|
||||
.appendingPathComponent("Library", isDirectory: true)
|
||||
.appendingPathComponent("Caches", isDirectory: true)
|
||||
}
|
||||
#endif
|
||||
|
||||
static var iCloudDirectory: URL {
|
||||
FileManager.default.url(forUbiquityContainerIdentifier: nil)!.appendingPathComponent("Documents", isDirectory: true)
|
||||
}
|
||||
#if os(macOS)
|
||||
static var workingDirectory: URL {
|
||||
cacheDirectory.appendingPathComponent("Working", isDirectory: true)
|
||||
}
|
||||
#else
|
||||
static let workingDirectory = cacheDirectory.appendingPathComponent("Working", isDirectory: true)
|
||||
|
||||
#endif
|
||||
|
||||
static var iCloudDirectory: URL! = FileManager.default.url(forUbiquityContainerIdentifier: nil)!.appendingPathComponent("Documents", isDirectory: true)
|
||||
}
|
||||
|
||||
public extension URL {
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import Foundation
|
||||
import UserNotifications
|
||||
|
||||
public enum ServiceNotification {
|
||||
private static let delegate = Delegate()
|
||||
|
||||
public static func register() {
|
||||
UNUserNotificationCenter.current().delegate = delegate
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) {
|
||||
_, _ in
|
||||
}
|
||||
}
|
||||
|
||||
private static var listener: ((UNNotificationContent) -> Void)?
|
||||
|
||||
public static func setServiceNotificationListener(listener: @escaping (UNNotificationContent) -> Void) {
|
||||
ServiceNotification.listener = listener
|
||||
}
|
||||
|
||||
public static func removeServiceNotificationListener() {
|
||||
ServiceNotification.listener = nil
|
||||
}
|
||||
|
||||
public static func postServiceNotification(content: UNNotificationContent) {
|
||||
UNUserNotificationCenter.current().add(UNNotificationRequest(identifier: "service-notification", content: content, trigger: nil))
|
||||
}
|
||||
|
||||
public static func postServiceNotification(title: String, message: String) {
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = title
|
||||
content.body = message
|
||||
postServiceNotification(content: content)
|
||||
}
|
||||
|
||||
private class Delegate: NSObject, UNUserNotificationCenterDelegate {
|
||||
func userNotificationCenter(_: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
|
||||
if let listener = ServiceNotification.listener {
|
||||
listener(notification.request.content)
|
||||
return []
|
||||
} else {
|
||||
return [.alert]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,7 @@ public enum Variant {
|
||||
public static let applicationName = "SFI"
|
||||
#elseif os(macOS)
|
||||
public static let applicationName = "SFM"
|
||||
#elseif os(tvOS)
|
||||
public static let applicationName = "SFT"
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user