Skip to content

Commit

Permalink
Merge branch 'release/2.0.0-beta5'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Aug 19, 2021
2 parents 52a1cc7 + e4be8ee commit 964af43
Show file tree
Hide file tree
Showing 38 changed files with 488 additions and 182 deletions.
7 changes: 5 additions & 2 deletions Cryptomator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@
74267A1C26A5799F004C61BC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Localizable.strings; sourceTree = "<group>"; };
74267A1D26A579A4004C61BC /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
7469AD99266E26B0000DCD45 /* URL+Zip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Zip.swift"; sourceTree = "<group>"; };
74BDA62B26CE8AE1007FBD72 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
74D365B9268B5DB0005ECD69 /* FilesAppUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilesAppUtil.swift; sourceTree = "<group>"; };
74FC576025ADED030003ED27 /* VaultCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -1004,11 +1005,11 @@
4A66F58125C487C9001BE15E /* PasswordFieldCell.swift */,
4A4B7E4726B2BAFB009BFDB1 /* SwitchCell.swift */,
4A4B7E4526B2B6A0009BFDB1 /* SwitchCellViewModel.swift */,
4A4B7E4B26B2FF41009BFDB1 /* TableViewCell.swift */,
4A4B7E4326B2B1A5009BFDB1 /* TableViewCellViewModel.swift */,
4A66F57825C47BB2001BE15E /* TextFieldCell.swift */,
4AA22C15261CA8D800A17486 /* URLFieldCell.swift */,
4AA22C1D261CA94700A17486 /* UsernameFieldCell.swift */,
4A4B7E4B26B2FF41009BFDB1 /* TableViewCell.swift */,
);
path = Cells;
sourceTree = "<group>";
Expand All @@ -1021,12 +1022,12 @@
4AE7D79325826A0900C5E1D8 /* FileProviderValidationServiceSource.h */,
4AE7D79425826A0900C5E1D8 /* FileProviderValidationServiceSource.m */,
4AA621DE249A6A8400A0BCBD /* Info.plist */,
4AFD8C102693204900F77BA6 /* ErrorWrapper.swift */,
4AD0F61B24AF203F0026B765 /* FileProvider+Actions.swift */,
4AA621DC249A6A8400A0BCBD /* FileProviderEnumerator.swift */,
4AA621D8249A6A8400A0BCBD /* FileProviderExtension.swift */,
4A24001926AE9F3A009DBC2E /* VaultLockingServiceSource.swift */,
4A9BED63268F1DB000721BAA /* VaultUnlockingServiceSource.swift */,
4AFD8C102693204900F77BA6 /* ErrorWrapper.swift */,
);
path = FileProviderExtension;
sourceTree = "<group>";
Expand Down Expand Up @@ -1433,6 +1434,7 @@
en,
Base,
de,
cs,
el,
es,
fr,
Expand Down Expand Up @@ -1929,6 +1931,7 @@
children = (
742679FA26A56B33004C61BC /* en */,
742679FE26A578E2004C61BC /* de */,
74BDA62B26CE8AE1007FBD72 /* cs */,
74267A0326A5793E004C61BC /* el */,
74267A0426A57944004C61BC /* es */,
74267A0526A57947004C61BC /* fr */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,8 @@ class LocalFileSystemAuthenticationViewModel: LocalFileSystemAuthenticationViewM
}

private func validate(credential: LocalFileSystemCredential) -> Promise<Void> {
let provider = LocalFileSystemProvider(rootURL: credential.rootURL)
return provider.fetchItemListExhaustively(forFolderAt: CloudPath("/")).recover { error -> CloudItemList in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: CloudPath("/"))
} else {
throw error
}
}.then { itemList in
let provider = LocalizedCloudProviderDecorator(delegate: LocalFileSystemProvider(rootURL: credential.rootURL))
return provider.fetchItemListExhaustively(forFolderAt: CloudPath("/")).then { itemList in
try self.validationLogic.validate(items: itemList.items)
}
}
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/ActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit

class ActionButton: UIButton {
var primaryAction: ((UIButton) -> Void)?

Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Bindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import Foundation

class Bindable<Value> {
@Published var value: Value

Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Cells/SwitchCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import UIKit

class SwitchCell: TableViewCell {
var switchControl = UISwitch(frame: .zero)

Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Cells/TableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import UIKit

class TableViewCell: UITableViewCell {
lazy var subscribers = Set<AnyCancellable>()
private var viewModel: TableViewCellViewModel?
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Cells/TableViewCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit

protocol TableViewCellViewModel: AnyObject {
var type: TableViewCell.Type { get }
var title: Bindable<String?> { get }
Expand Down
10 changes: 2 additions & 8 deletions Cryptomator/Common/ChooseFolder/ChooseFolderViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChooseFolderViewModel: ChooseFolderViewModelProtocol {
init(canCreateFolder: Bool, cloudPath: CloudPath, provider: CloudProvider) {
self.canCreateFolder = canCreateFolder
self.cloudPath = cloudPath
self.provider = provider
self.provider = LocalizedCloudProviderDecorator(delegate: provider)
}

func startListenForChanges(onError: @escaping (Error) -> Void, onChange: @escaping () -> Void, onVaultDetection: @escaping (VaultDetailItem) -> Void) {
Expand All @@ -49,13 +49,7 @@ class ChooseFolderViewModel: ChooseFolderViewModelProtocol {
}

func refreshItems() {
provider.fetchItemListExhaustively(forFolderAt: cloudPath).recover { error -> CloudItemList in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: self.cloudPath)
} else {
throw error
}
}.then { itemList in
provider.fetchItemListExhaustively(forFolderAt: cloudPath).then { itemList in
if let vaultItem = VaultDetector.getVaultItem(items: itemList.items, parentCloudPath: self.cloudPath) {
self.foundMasterkey = true
self.vaultListener?(vaultItem)
Expand Down
10 changes: 2 additions & 8 deletions Cryptomator/Common/ChooseFolder/CreateNewFolderViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ class CreateNewFolderViewModel: CreateNewFolderViewModelProtocol {

init(parentPath: CloudPath, provider: CloudProvider) {
self.parentPath = parentPath
self.provider = provider
self.provider = LocalizedCloudProviderDecorator(delegate: provider)
}

func createFolder() -> Promise<CloudPath> {
guard let folderName = folderName, !folderName.isEmpty else {
return Promise(CreateNewFolderViewModelError.emptyFolderName)
}
let folderPath = parentPath.appendingPathComponent(folderName)
return provider.createFolder(at: folderPath).recover { error -> Void in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: folderPath)
} else {
throw error
}
}.then {
return provider.createFolder(at: folderPath).then {
folderPath
}
}
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Combine/Publisher+OptionalAssign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import Foundation

extension Publisher where Failure == Never {
func assign<Root: AnyObject>(to keyPath: ReferenceWritableKeyPath<Root, Output>, on root: Root?) -> AnyCancellable {
sink { [weak root] in
Expand Down
8 changes: 6 additions & 2 deletions Cryptomator/Common/Combine/UIControl+Publisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

import Combine
import UIKit
// Taken from: https://www.avanderlee.com/swift/custom-combine-publisher/
/// A custom subscription to capture UIControl target events.

/**
A custom subscription to capture `UIControl` target events.

Taken from: <https://www.avanderlee.com/swift/custom-combine-publisher/>
*/
final class UIControlSubscription<SubscriberType: Subscriber, Control: UIControl>: Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let control: Control
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/Combine/UISwitch+Publisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import UIKit

extension UISwitch {
func publisher(for events: UIControl.Event) -> AnyPublisher<Bool, UIControlPublisher<UISwitch>.Failure> {
return publisher(for: events).map { $0.isOn }.eraseToAnyPublisher()
Expand Down
2 changes: 2 additions & 0 deletions Cryptomator/Common/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Skymatic GmbH. All rights reserved.
//

import CocoaLumberjackSwift
import CryptomatorCommonCore
import UIKit

Expand All @@ -18,6 +19,7 @@ protocol Coordinator: AnyObject {

extension Coordinator {
func handleError(_ error: Error, for viewController: UIViewController) {
DDLogError("Error: \(error)")
let alertController = UIAlertController(title: LocalizedString.getValue("common.alert.error.title"), message: error.localizedDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: LocalizedString.getValue("common.button.ok"), style: .default))
viewController.present(alertController, animated: true)
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/Common/HeaderFooter/BaseHeaderFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Combine
import UIKit

class BaseHeaderFooterView: UITableViewHeaderFooterView, HeaderFooterViewModelConfiguring {
weak var tableView: UITableView?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit

protocol HeaderFooterViewModel {
var viewType: HeaderFooterViewModelConfiguring.Type { get }
var title: Bindable<String?> { get }
Expand Down
1 change: 1 addition & 0 deletions Cryptomator/VaultDetail/VaultPasswordVerifying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation

protocol VaultPasswordVerifying {
func verifiedVaultPassword()
func cancel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// LocalizedCloudProviderDecorator.swift
// CryptomatorCommonCore
//
// Created by Tobias Hagemann on 19.08.21.
// Copyright © 2020 Skymatic GmbH. All rights reserved.
//

import CryptomatorCloudAccessCore
import Foundation
import Promises

public class LocalizedCloudProviderDecorator: CloudProvider {
// swiftlint:disable:next weak_delegate
public let delegate: CloudProvider

public init(delegate: CloudProvider) {
self.delegate = delegate
}

public func fetchItemMetadata(at cloudPath: CloudPath) -> Promise<CloudItemMetadata> {
return delegate.fetchItemMetadata(at: cloudPath).recover { error -> CloudItemMetadata in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
} else {
throw error
}
}
}

public func fetchItemList(forFolderAt cloudPath: CloudPath, withPageToken pageToken: String?) -> Promise<CloudItemList> {
return delegate.fetchItemList(forFolderAt: cloudPath, withPageToken: pageToken).recover { error -> CloudItemList in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
} else {
throw error
}
}
}

public func downloadFile(from cloudPath: CloudPath, to localURL: URL) -> Promise<Void> {
return delegate.downloadFile(from: cloudPath, to: localURL).recover { error -> Void in
if let error = error as? CloudProviderError {
switch error {
case .itemAlreadyExists:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: CloudPath(localURL.path))
default:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
}
} else {
throw error
}
}
}

public func uploadFile(from localURL: URL, to cloudPath: CloudPath, replaceExisting: Bool) -> Promise<CloudItemMetadata> {
return delegate.uploadFile(from: localURL, to: cloudPath, replaceExisting: replaceExisting).recover { error -> CloudItemMetadata in
if let error = error as? CloudProviderError {
switch error {
case .itemNotFound, .itemTypeMismatch:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: CloudPath(localURL.path))
default:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
}
} else {
throw error
}
}
}

public func createFolder(at cloudPath: CloudPath) -> Promise<Void> {
return delegate.createFolder(at: cloudPath).recover { error -> Void in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
} else {
throw error
}
}
}

public func deleteFile(at cloudPath: CloudPath) -> Promise<Void> {
return delegate.deleteFile(at: cloudPath).recover { error -> Void in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
} else {
throw error
}
}
}

public func deleteFolder(at cloudPath: CloudPath) -> Promise<Void> {
return delegate.deleteFolder(at: cloudPath).recover { error -> Void in
if let error = error as? CloudProviderError {
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: cloudPath)
} else {
throw error
}
}
}

public func moveFile(from sourceCloudPath: CloudPath, to targetCloudPath: CloudPath) -> Promise<Void> {
return delegate.moveFile(from: sourceCloudPath, to: targetCloudPath).recover { error -> Void in
if let error = error as? CloudProviderError {
switch error {
case .itemAlreadyExists, .parentFolderDoesNotExist:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: targetCloudPath)
default:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: sourceCloudPath)
}
} else {
throw error
}
}
}

public func moveFolder(from sourceCloudPath: CloudPath, to targetCloudPath: CloudPath) -> Promise<Void> {
return delegate.moveFolder(from: sourceCloudPath, to: targetCloudPath).recover { error -> Void in
if let error = error as? CloudProviderError {
switch error {
case .itemAlreadyExists, .parentFolderDoesNotExist:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: targetCloudPath)
default:
throw LocalizedCloudProviderError.convertToLocalized(error, cloudPath: sourceCloudPath)
}
} else {
throw error
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import CryptomatorCloudAccessCore
import Foundation

public protocol CloudProviderManager {
func getProvider(with accountUID: String) throws -> CloudProvider
static func providerShouldUpdate(with accountUID: String)
Expand Down
Loading

0 comments on commit 964af43

Please sign in to comment.