Skip to content

Commit

Permalink
Have settings coordinator use import service
Browse files Browse the repository at this point in the history
  • Loading branch information
KatherineInCode committed Apr 23, 2024
1 parent 4b72148 commit f149283
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions AuthenticatorShared/UI/Platform/Settings/SettingsCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import OSLog
import SwiftUI

// MARK: - SettingsCoordinator
Expand All @@ -14,6 +13,7 @@ final class SettingsCoordinator: NSObject, Coordinator, HasStackNavigator {
typealias Services = HasAuthenticatorItemRepository
& HasErrorReporter
& HasExportItemsService
& HasImportItemsService
& HasPasteboardService
& HasStateService
& HasTimeProvider
Expand Down Expand Up @@ -85,11 +85,9 @@ final class SettingsCoordinator: NSObject, Coordinator, HasStackNavigator {
private func showExportedItemsUrl(_ fileUrl: URL) {
let activityVC = UIActivityViewController(activityItems: [fileUrl], applicationActivities: nil)
activityVC.completionWithItemsHandler = { activityType, completed, returnedItems, activityError in

Check warning on line 87 in AuthenticatorShared/UI/Platform/Settings/SettingsCoordinator.swift

View workflow job for this annotation

GitHub Actions / Test

Unused Closure Parameter Violation: Unused parameter in a closure should be replaced with _ (unused_closure_parameter)
Logger.application.log("Donedone \(completed) \(activityError)")
}
stackNavigator?.present(activityVC) {
Logger.application.log("Done")
// TODO: Toast!

Check warning on line 88 in AuthenticatorShared/UI/Platform/Settings/SettingsCoordinator.swift

View workflow job for this annotation

GitHub Actions / Test

TODO without JIRA Violation: All TODOs must be followed by a JIRA reference, for example: "TODO: BIT-123" (todo_without_jira)
}
stackNavigator?.present(activityVC)
}

/// Shows the export vault screen.
Expand Down Expand Up @@ -153,27 +151,13 @@ final class SettingsCoordinator: NSObject, Coordinator, HasStackNavigator {

extension SettingsCoordinator: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else { return }
Task {
do {
let importData = try Data(contentsOf: urls.first!)
let decoder = JSONDecoder()
let vaultLike = try decoder.decode(VaultLike.self, from: importData)
let items = vaultLike.items
try await items.asyncForEach { cipherLike in
let item = AuthenticatorItemView(
id: cipherLike.id,
name: cipherLike.name,
totpKey: cipherLike.login?.totp
)
try await services.authenticatorItemRepository.addAuthenticatorItem(item)
}
try await services.importItemsService.importItems(url: url, format: .json)
} catch {
Logger.application.log("\(error)")
services.errorReporter.log(error: error)
}
}
}

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
Logger.application.log("Cancelled! (???)")
}
}

0 comments on commit f149283

Please sign in to comment.