import Foundation extension ConfigStore { public static let defaultFileContents = """ #:schema \(ConfigJSONSchema.publishedURL) version = 1 [general] shortcuts-enabled = true collect-activity = true when-display-full = "swap" [motion] highlight = "active" highlight-width = 2.0 [appearance] stack-controls = "on-demand" palette = "system" mode = "system" border-opacity = 1.0 [focus-modes] no-peek-level = 0.25 no-peek-blur = true clean-space-color = "graphite" [mouse] focus-follows-mouse = false focus-delay = 0.35 typing-cooldown = 1 edge-snapping = true drop-to-ratio = true """ public func createDefaultFileIfMissing() throws { switch ConfigFileContents.read(from: fileURL) { case .bytes: return case .failure(let diagnostic): throw diagnostic case .missing: break } try FileManager.default.createDirectory( at: fileURL.deletingLastPathComponent(), withIntermediateDirectories: true ) do { try Data(Self.defaultFileContents.utf8).write(to: fileURL, options: .withoutOverwriting) } catch let error as CocoaError where error.code == .fileWriteFileExists { // An editor or another startup may have created the file after our read. switch ConfigFileContents.read(from: fileURL) { case .bytes: return case .failure(let diagnostic): throw diagnostic case .missing: throw error } } } }