From c2cd6481fd4e343cbed032f33f187c4064105936 Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Wed, 1 May 2019 18:28:22 +0200 Subject: [PATCH] Utilize default settings values --- pass.xcodeproj/project.pbxproj | 6 +++--- pass/AppDelegate.swift | 4 ---- pass/Controllers/PasswordsViewController.swift | 4 ++-- passKit/Helpers/DefaultsKeys.swift | 4 ++-- {pass => passKit}/Helpers/SearchBarScope.swift | 6 ++++-- passKit/Models/PasswordStore.swift | 4 ++-- 6 files changed, 13 insertions(+), 15 deletions(-) rename {pass => passKit}/Helpers/SearchBarScope.swift (70%) diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index 8eeec14..0f8195e 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 301F6463216162550071A4CE /* AdditionField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301F6462216162550071A4CE /* AdditionField.swift */; }; 301F6468216165290071A4CE /* ConstantsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301F6467216165290071A4CE /* ConstantsTest.swift */; }; 301F646D216166AA0071A4CE /* AdditionFieldTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301F646C216166AA0071A4CE /* AdditionFieldTest.swift */; }; - 302202EF222F14E400555236 /* SearchBarScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302202EE222F14E400555236 /* SearchBarScope.swift */; }; 302E85612125ECC70031BA64 /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302E85602125ECC70031BA64 /* Parser.swift */; }; 302E85632125EE550031BA64 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302E85622125EE550031BA64 /* Constants.swift */; }; 30697C2A21F63C5A0064FCAC /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30697C2321F63C580064FCAC /* NotificationNames.swift */; }; @@ -42,6 +41,7 @@ 30697C5421F63E0B0064FCAC /* CredentialProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30697C5221F63E0B0064FCAC /* CredentialProviderViewController.swift */; }; 30697C5F21F674800064FCAC /* String+UtilitiesTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30697C5E21F674800064FCAC /* String+UtilitiesTest.swift */; }; 307BF39921BC2298003A082D /* TestBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307BF39821BC2297003A082D /* TestBase.swift */; }; + 308C273A2279F9CB0016D0E2 /* SearchBarScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 302202EE222F14E400555236 /* SearchBarScope.swift */; }; 30A1D29C21AF451E00E2D1F7 /* PasswordGeneratorFlavourTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A1D29B21AF451E00E2D1F7 /* PasswordGeneratorFlavourTest.swift */; }; 30A1D2A221B2BC6F00E2D1F7 /* TokenBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A1D2A121B2BC6F00E2D1F7 /* TokenBuilder.swift */; }; 30A1D2A621B2D46100E2D1F7 /* OtpType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30A1D2A521B2D46100E2D1F7 /* OtpType.swift */; }; @@ -602,6 +602,7 @@ 30697C2421F63C590064FCAC /* Globals.swift */, 30697C2321F63C580064FCAC /* NotificationNames.swift */, 30697C2621F63C590064FCAC /* PasswordGeneratorFlavour.swift */, + 302202EE222F14E400555236 /* SearchBarScope.swift */, 30697C2721F63C590064FCAC /* Utils.swift */, ); path = Helpers; @@ -665,7 +666,6 @@ isa = PBXGroup; children = ( A2BC54C71EEE5669001FAFBD /* Objective-CBridgingHeader.h */, - 302202EE222F14E400555236 /* SearchBarScope.swift */, A20691F31F2A3D0E0096483D /* SecurePasteboard.swift */, A2A61C1F1EEFABAD00CFE063 /* UtilsExtension.swift */, ); @@ -1233,6 +1233,7 @@ 30697C4821F63CAB0064FCAC /* PasswordStore.swift in Sources */, A26075AD1EEC7125005DB03E /* pass.xcdatamodeld in Sources */, 30697C2D21F63C5A0064FCAC /* PasswordGeneratorFlavour.swift in Sources */, + 308C273A2279F9CB0016D0E2 /* SearchBarScope.swift in Sources */, 30697C2F21F63C5A0064FCAC /* DefaultsKeys.swift in Sources */, 30A1D2A821B2D53200E2D1F7 /* PasswordChange.swift in Sources */, 30697C3E21F63C990064FCAC /* String+Utilities.swift in Sources */, @@ -1300,7 +1301,6 @@ DCFB77AB1E503729008DE471 /* ContentTableViewCell.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */, DC4914961E434301007FF592 /* LabelTableViewCell.swift in Sources */, - 302202EF222F14E400555236 /* SearchBarScope.swift in Sources */, DC5F385B1E56AADB00C69ACA /* PGPKeyArmorSettingTableViewController.swift in Sources */, DCAAF7451E2FA66800AB94BC /* SettingsTableViewController.swift in Sources */, DCFB77A71E502DF9008DE471 /* EditPasswordTableViewController.swift in Sources */, diff --git a/pass/AppDelegate.swift b/pass/AppDelegate.swift index 5febb0a..1658566 100644 --- a/pass/AppDelegate.swift +++ b/pass/AppDelegate.swift @@ -34,10 +34,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { self.perform(#selector(postSearchNotification), with: nil, afterDelay: 0.4) } } - - // Assign default values to global settings. - SharedDefaults.register(defaults: [DefaultsKeys.gitBranchName._key: "master"]) - return true } diff --git a/pass/Controllers/PasswordsViewController.swift b/pass/Controllers/PasswordsViewController.swift index ff68252..d032f58 100644 --- a/pass/Controllers/PasswordsViewController.swift +++ b/pass/Controllers/PasswordsViewController.swift @@ -585,14 +585,14 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { // update the default search scope - SharedDefaults[.isSearchDefaultAll] = SearchBarScope(rawValue: selectedScope) == .all + SharedDefaults[.searchDefault] = SearchBarScope(rawValue: selectedScope) ?? .all updateSearchResults(for: searchController) } func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool { // set the default search scope to "all" - if SharedDefaults[.isShowFolderOn] && SharedDefaults[.isSearchDefaultAll] { + if SharedDefaults[.isShowFolderOn] && SharedDefaults[.searchDefault] == .all { searchController.searchBar.selectedScopeButtonIndex = SearchBarScope.all.rawValue } else { searchController.searchBar.selectedScopeButtonIndex = SearchBarScope.current.rawValue diff --git a/passKit/Helpers/DefaultsKeys.swift b/passKit/Helpers/DefaultsKeys.swift index d099137..016d0cf 100644 --- a/passKit/Helpers/DefaultsKeys.swift +++ b/passKit/Helpers/DefaultsKeys.swift @@ -22,7 +22,7 @@ public extension DefaultsKeys { static let gitURL = DefaultsKey("gitURL") static let gitAuthenticationMethod = DefaultsKey("gitAuthenticationMethod") static let gitUsername = DefaultsKey("gitUsername") - static let gitBranchName = DefaultsKey("gitBranchName") + static let gitBranchName = DefaultsKey("gitBranchName", defaultValue: "master") static let gitSSHPrivateKeyURL = DefaultsKey("gitSSHPrivateKeyURL") static let gitSSHKeySource = DefaultsKey("gitSSHKeySource") static let gitSSHPrivateKeyArmor = DefaultsKey("gitSSHPrivateKeyArmor") @@ -40,7 +40,7 @@ public extension DefaultsKeys { static let isRememberGitCredentialPassphraseOn = DefaultsKey("isRememberGitCredentialPassphraseOn", defaultValue: false) static let isShowFolderOn = DefaultsKey("isShowFolderOn", defaultValue: true) static let isHidePasswordImagesOn = DefaultsKey("isHidePasswordImagesOn", defaultValue: false) - static let isSearchDefaultAll = DefaultsKey("isSearchDefaultAll", defaultValue: true) + static let searchDefault = DefaultsKey("searchDefault", defaultValue: .all) static let passwordGeneratorFlavor = DefaultsKey("passwordGeneratorFlavor", defaultValue: "Apple") static let encryptInArmored = DefaultsKey("encryptInArmored", defaultValue: false) diff --git a/pass/Helpers/SearchBarScope.swift b/passKit/Helpers/SearchBarScope.swift similarity index 70% rename from pass/Helpers/SearchBarScope.swift rename to passKit/Helpers/SearchBarScope.swift index ab5c16f..57ba4d6 100644 --- a/pass/Helpers/SearchBarScope.swift +++ b/passKit/Helpers/SearchBarScope.swift @@ -6,11 +6,13 @@ // Copyright © 2019 Bob Sun. All rights reserved. // -enum SearchBarScope: Int, CaseIterable { +import SwiftyUserDefaults + +public enum SearchBarScope: Int, CaseIterable, DefaultsSerializable { case current case all - var localizedName: String { + public var localizedName: String { switch self { case .current: return "Current".localize() diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index 164c2ac..eae2872 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -582,7 +582,7 @@ public class PasswordStore { do { let credentialProvider = try credential.credentialProvider(requestGitPassword: requestGitPassword) let options = [GTRepositoryRemoteOptionsCredentialProvider: credentialProvider] - if let branch = try getLocalBranch(withName: SharedDefaults[.gitBranchName]!) { + if let branch = try getLocalBranch(withName: SharedDefaults[.gitBranchName]) { let remote = try GTRemote(name: "origin", in: storeRepository) try storeRepository.push(branch, to: remote, withOptions: options, progress: transferProgressBlock) } @@ -805,7 +805,7 @@ public class PasswordStore { throw AppError.RepositoryNotSet } // get the remote branch - let remoteBranchName = SharedDefaults[.gitBranchName]! + let remoteBranchName = SharedDefaults[.gitBranchName] guard let remoteBranch = try storeRepository.remoteBranches().first(where: { $0.shortName == remoteBranchName }) else { throw AppError.RepositoryRemoteBranchNotFound(remoteBranchName) }