refactor: Fix macOS standalone application

This commit is contained in:
世界
2026-01-05 01:21:24 +08:00
parent ef1c924c64
commit 59317f3c79
66 changed files with 2799 additions and 585 deletions
+1
View File
@@ -10,6 +10,7 @@ public extension Date {
var relativeFormat: String {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
formatter.dateTimeStyle = .named
return formatter.localizedString(for: self, relativeTo: Date())
}
}
+46 -45
View File
@@ -119,61 +119,62 @@ public extension UTType {
}
#if !os(tvOS)
// MARK: - FileDocument for Export
public struct ProfileExportDocument: FileDocument {
public static var readableContentTypes: [UTType] { [.profile] }
// MARK: - FileDocument for Export
public let data: Data
public let filename: String
public struct ProfileExportDocument: FileDocument {
public static var readableContentTypes: [UTType] { [.profile] }
public init(content: LibboxProfileContent) throws {
guard let encoded = content.encode() else {
throw NSError(domain: "ProfileExportDocument", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to encode profile"])
public let data: Data
public let filename: String
public init(content: LibboxProfileContent) throws {
guard let encoded = content.encode() else {
throw NSError(domain: "ProfileExportDocument", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to encode profile"])
}
data = encoded
filename = "\(content.name).bpf"
}
data = encoded
filename = "\(content.name).bpf"
}
public init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents else {
throw CocoaError(.fileReadCorruptFile)
public init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents else {
throw CocoaError(.fileReadCorruptFile)
}
self.data = data
filename = "profile.bpf"
}
self.data = data
filename = "profile.bpf"
}
public func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
FileWrapper(regularFileWithContents: data)
}
}
public struct ProfileJSONExportDocument: FileDocument {
public static var readableContentTypes: [UTType] { [.json] }
public let content: String
public let filename: String
public init(jsonContent: String, name: String) {
content = jsonContent
filename = "\(name).json"
}
public init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let content = String(data: data, encoding: .utf8)
else {
throw CocoaError(.fileReadCorruptFile)
public func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
FileWrapper(regularFileWithContents: data)
}
self.content = content
filename = "profile.json"
}
public func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
guard let data = content.data(using: .utf8) else {
throw CocoaError(.fileWriteInapplicableStringEncoding)
public struct ProfileJSONExportDocument: FileDocument {
public static var readableContentTypes: [UTType] { [.json] }
public let content: String
public let filename: String
public init(jsonContent: String, name: String) {
content = jsonContent
filename = "\(name).json"
}
public init(configuration: ReadConfiguration) throws {
guard let data = configuration.file.regularFileContents,
let content = String(data: data, encoding: .utf8)
else {
throw CocoaError(.fileReadCorruptFile)
}
self.content = content
filename = "profile.json"
}
public func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
guard let data = content.data(using: .utf8) else {
throw CocoaError(.fileWriteInapplicableStringEncoding)
}
return FileWrapper(regularFileWithContents: data)
}
return FileWrapper(regularFileWithContents: data)
}
}
#endif
+1 -1
View File
@@ -29,7 +29,7 @@ public extension Profile {
if await SharedPreferences.selectedProfileID.get() == id {
if let profile = try? await ExtensionProfile.load() {
if await profile.status == .connected {
try LibboxNewStandaloneCommandClient()!.serviceReload()
try await profile.reloadService()
}
}
}
@@ -1,6 +1,9 @@
import BinaryCodable
import Foundation
import GRDB
import os
private let logger = Logger(category: "SharedPreferences")
extension SharedPreferences {
public class Preference<T: Codable> {
@@ -16,7 +19,7 @@ extension SharedPreferences {
do {
return try await SharedPreferences.read(name) ?? defaultValue
} catch {
NSLog("read preferences error: \(error)")
logger.error("read preferences error: \(error)")
return defaultValue
}
}
@@ -31,7 +34,7 @@ extension SharedPreferences {
do {
try await SharedPreferences.write(name, newValue)
} catch {
NSLog("write preferences error: \(error)")
logger.error("write preferences error: \(error)")
}
}
}