diff options
| author | Fuwn <[email protected]> | 2025-03-03 03:08:52 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-03-03 03:08:52 -0800 |
| commit | 2646279dc1378d0c63e91372486baa85d83590bd (patch) | |
| tree | 740abe2babf8e4ca9d9c4b86f64f2e4301533a98 /Sora/Data | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-2646279dc1378d0c63e91372486baa85d83590bd.tar.xz sora-testing-2646279dc1378d0c63e91372486baa85d83590bd.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Data')
| -rw-r--r-- | Sora/Data/JSONFileDocument.swift | 26 | ||||
| -rw-r--r-- | Sora/Data/Settings/SettingsManager.swift | 4 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Sora/Data/JSONFileDocument.swift b/Sora/Data/JSONFileDocument.swift new file mode 100644 index 0000000..bc41616 --- /dev/null +++ b/Sora/Data/JSONFileDocument.swift @@ -0,0 +1,26 @@ +import SwiftUI +import UniformTypeIdentifiers + +struct JSONFileDocument: FileDocument { + static var readableContentTypes: [UTType] { [.json] } + + var data: Data + + init(_ data: Data) throws { + self.data = data + } + + init(configuration: ReadConfiguration) throws { + guard let data = configuration.file.regularFileContents else { + throw CocoaError(.fileReadCorruptFile) + } + + self.data = data + } + + func fileWrapper( + configuration: WriteConfiguration // swiftlint:disable:this unused_parameter + ) throws -> FileWrapper { + FileWrapper(regularFileWithContents: data) + } +} diff --git a/Sora/Data/Settings/SettingsManager.swift b/Sora/Data/Settings/SettingsManager.swift index c9590be..7d38d0f 100644 --- a/Sora/Data/Settings/SettingsManager.swift +++ b/Sora/Data/Settings/SettingsManager.swift @@ -125,6 +125,10 @@ class SettingsManager: ObservableObject { bookmarks.removeAll { $0.id == id } } + func exportBookmarks() throws -> Data { + try JSONEncoder().encode(bookmarks) + } + // MARK: - Search History Management func removeSearchHistoryEntry(at offsets: IndexSet) { searchHistory.remove(atOffsets: offsets) |