Init commit

This commit is contained in:
世界
2023-07-15 15:03:45 +08:00
commit f441b89efb
122 changed files with 7355 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
import Foundation
extension Bundle {
var version: String {
infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"
}
var versionNumber: String {
infoDictionary?["CFBundleVersion"] as? String ?? "unknown"
}
}
+34
View File
@@ -0,0 +1,34 @@
import Foundation
public enum FilePath {
public static let packageName = "io.nekohasekai.sfa"
#if os(iOS)
public static let httpClientName = "SFI"
#elseif os(macOS)
public static let httpClientName = "SFM"
#endif
}
public extension FilePath {
static let groupName = "group.\(packageName)"
static let sharedDirectory: URL! = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)
static let cacheDirectory = sharedDirectory
.appendingPathComponent("Library", isDirectory: true)
.appendingPathComponent("Caches", isDirectory: true)
static let workingDirectory = cacheDirectory.appendingPathComponent("Working", isDirectory: true)
static let iCloudDirectory = FileManager.default.url(forUbiquityContainerIdentifier: nil)!.appendingPathComponent("Documents", isDirectory: true)
}
public extension URL {
var fileName: String {
var path = relativePath
if let index = path.lastIndex(of: "/") {
path = String(path[path.index(index, offsetBy: 1)...])
}
return path
}
}
+46
View File
@@ -0,0 +1,46 @@
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 {
NSLog("userNotificationCenter")
if let listener = ServiceNotification.listener {
listener(notification.request.content)
return []
} else {
return [.alert]
}
}
}
}