mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Fixes ArticleTheme Import on SwiftUI
Adds startAccessingSecurityScopedResource and stopAccessingSecurityScopedResource to `.fileImporter`s.
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
public struct NNWThemeDocument: FileDocument {
|
||||
@@ -21,7 +20,10 @@ public struct NNWThemeDocument: FileDocument {
|
||||
}
|
||||
|
||||
public init(configuration: ReadConfiguration) throws {
|
||||
|
||||
guard let _ = configuration.file.regularFileContents else {
|
||||
throw CocoaError(.fileReadCorruptFile)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
public func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
|
||||
|
||||
@@ -44,8 +44,12 @@ struct ArticleThemeManagerView: View {
|
||||
switch result {
|
||||
case .success(let success):
|
||||
do {
|
||||
let theme = try ArticleTheme(path: success.path, isAppTheme: false)
|
||||
showImportConfirmationAlert = (theme, true)
|
||||
let url = URL(fileURLWithPath: success.path)
|
||||
if url.startAccessingSecurityScopedResource() {
|
||||
let theme = try ArticleTheme(path: success.path, isAppTheme: false)
|
||||
showImportConfirmationAlert = (theme, true)
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
} catch {
|
||||
showImportErrorAlert = (error, true)
|
||||
}
|
||||
|
||||
@@ -117,13 +117,17 @@ struct SettingsView: View {
|
||||
.fileImporter(isPresented: $viewModel.showImportView, allowedContentTypes: OPMLDocument.readableContentTypes) { result in
|
||||
switch result {
|
||||
case .success(let url):
|
||||
viewModel.importAccount!.importOPML(url) { importResult in
|
||||
switch importResult {
|
||||
case .success(_):
|
||||
viewModel.showImportSuccess = true
|
||||
case .failure(let error):
|
||||
viewModel.importExportError = error
|
||||
viewModel.showImportExportError = true
|
||||
if url.startAccessingSecurityScopedResource() {
|
||||
viewModel.importAccount!.importOPML(url) { importResult in
|
||||
switch importResult {
|
||||
case .success(_):
|
||||
viewModel.showImportSuccess = true
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
case .failure(let error):
|
||||
viewModel.importExportError = error
|
||||
viewModel.showImportExportError = true
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
|
||||
Reference in New Issue
Block a user