Fix import/export subscriptions

Beta 6 has changed the way import and export works. It's changed from
a environment variable to view modifier now.
This commit is contained in:
Rizwan Mohamed Ibrahim
2020-08-28 23:01:58 +05:30
parent 76eb87c0f8
commit 7e9db1d218
2 changed files with 36 additions and 27 deletions

View File

@@ -9,6 +9,7 @@
import Foundation
import SwiftUI
import Account
import UniformTypeIdentifiers
enum FeedsSettingsError: LocalizedError, Equatable {
case none, noActiveAccount, exportFailed(reason: String?), importFailed
@@ -51,6 +52,11 @@ class FeedsSettingsModel: ObservableObject {
}
}
@Published var showError: Bool = false
@Published var isImporting: Bool = false
@Published var isExporting: Bool = false
@Published var selectedAccount: Account? = nil
let importingContentTypes: [UTType] = [UTType(filenameExtension: "opml"), UTType("public.xml")].compactMap { $0 }
func checkForActiveAccount() -> Bool {
if AccountManager.shared.activeAccounts.count == 0 {
@@ -60,7 +66,18 @@ class FeedsSettingsModel: ObservableObject {
return true
}
func generateExportURL(for account: Account) -> URL? {
func importOPML(account: Account?) {
selectedAccount = account
isImporting = true
}
func exportOPML(account: Account?) {
selectedAccount = account
isExporting = true
}
func generateExportURL() -> URL? {
guard let account = selectedAccount else { return nil }
let accountName = account.nameForDisplay.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: .whitespaces)
let filename = "Subscriptions-\(accountName).opml"
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent(filename)
@@ -75,9 +92,9 @@ class FeedsSettingsModel: ObservableObject {
return tempFile
}
func processImportedFiles(_ urls: [URL],_ account: Account?) {
func processImportedFiles(_ urls: [URL]) {
urls.forEach{
account?.importOPML($0, completion: { [weak self] result in
selectedAccount?.importOPML($0, completion: { [weak self] result in
switch result {
case .success:
break