feat: added buttons for import/export application settings (#1837)

This commit is contained in:
Serhiy Mytrovtsiy
2024-03-28 21:13:44 +01:00
parent 6507322371
commit edca2a0e6d
2 changed files with 54 additions and 1 deletions

View File

@@ -62,4 +62,19 @@ public class Store {
self.defaults.removeObject(forKey: key)
}
}
public func export(to url: URL) {
guard let id = Bundle.main.bundleIdentifier,
let dicitionary = self.defaults.persistentDomain(forName: id) else { return }
NSDictionary(dictionary: dicitionary).write(to: url, atomically: true)
}
public func `import`(from url: URL) {
guard let id = Bundle.main.bundleIdentifier, let dict = NSDictionary(contentsOf: url) as? [String: Any] else { return }
self.defaults.setPersistentDomain(dict, forName: id)
if let path = Bundle.main.resourceURL?.deletingLastPathComponent().deletingLastPathComponent().absoluteString {
asyncShell("/usr/bin/open \(path)")
NSApp.terminate(self)
}
}
}