Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627import Foundation
struct AppRelaunchFailureNotice: Codable { private let version: Int
private static func url(configURL: URL) -> URL { configURL.deletingLastPathComponent().appendingPathComponent("restart-failure.json") }
static func record(configURL: URL) throws { let destination = url(configURL: configURL) try FileManager.default.createDirectory( at: destination.deletingLastPathComponent(), withIntermediateDirectories: true) try JSONEncoder().encode(Self(version: 1)).write(to: destination, options: .atomic) }
static func consume(configURL: URL) throws -> Bool { let source = url(configURL: configURL) let data: Data do { data = try Data(contentsOf: source) } catch CocoaError.fileReadNoSuchFile { return false } let notice = try JSONDecoder().decode(Self.self, from: data) guard notice.version == 1 else { throw CocoaError(.fileReadCorruptFile) } try FileManager.default.removeItem(at: source) return true }}