29 lines
1.1 KiB
Swift
29 lines
1.1 KiB
Swift
|
|
import Foundation
|
||
|
|
|
||
|
|
/// Plain-text record of what the app saw, because a release build's NSLog lines are hard to read
|
||
|
|
/// back. Lives beside the socket so one folder holds everything the app owns.
|
||
|
|
enum StatusFile {
|
||
|
|
static var path: String {
|
||
|
|
(NotifySocketPathHelper.directory as NSString).appendingPathComponent("status.txt")
|
||
|
|
}
|
||
|
|
|
||
|
|
private static var lines: [String: String] = [:]
|
||
|
|
private static let lock = NSLock()
|
||
|
|
|
||
|
|
static func set(_ key: String, _ value: String) {
|
||
|
|
lock.lock()
|
||
|
|
lines[key] = value
|
||
|
|
let text = lines.sorted { $0.key < $1.key }.map { "\($0.key): \($0.value)" }.joined(separator: "\n") + "\n"
|
||
|
|
lock.unlock()
|
||
|
|
do { try text.write(toFile: path, atomically: true, encoding: .utf8) }
|
||
|
|
catch { NSLog("LuxeNotifier: cannot write status file \(path): \(error)") }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
enum NotifySocketPathHelper {
|
||
|
|
static var directory: String {
|
||
|
|
let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
|
||
|
|
return base.appendingPathComponent("LuxeNotifier").path
|
||
|
|
}
|
||
|
|
}
|