From b175f510068727f79dbdcadda10d5bb373d82617 Mon Sep 17 00:00:00 2001 From: aeoliux Date: Sun, 14 Apr 2024 11:30:36 +0200 Subject: [PATCH] Added search functionality --- LibrePass.xcodeproj/project.pbxproj | 4 ++-- LibrePass/API/LibrePassCipher.swift | 23 +++++++--------------- LibrePass/App/LibrePassManagerWindow.swift | 5 ++++- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/LibrePass.xcodeproj/project.pbxproj b/LibrePass.xcodeproj/project.pbxproj index 7c40153..9e27a5d 100644 --- a/LibrePass.xcodeproj/project.pbxproj +++ b/LibrePass.xcodeproj/project.pbxproj @@ -459,7 +459,7 @@ SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -494,7 +494,7 @@ SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/LibrePass/API/LibrePassCipher.swift b/LibrePass/API/LibrePassCipher.swift index 7780ca6..fbc636d 100644 --- a/LibrePass/API/LibrePassCipher.swift +++ b/LibrePass/API/LibrePassCipher.swift @@ -71,6 +71,13 @@ class LibrePassCipher: Codable { } } + func contains(query: String) -> Bool { + return self.id == query || + (self.type == .Login) ? self.loginData!.name.contains(query) || self.loginData!.username?.contains(query) ?? false || self.loginData!.uris?.filter({ $0.contains(query) }).count ?? 0 > 0 || self.loginData!.notes?.contains(query) ?? false: + (self.type == .SecureNote) ? self.secureNoteData!.title.contains(query) || self.secureNoteData!.note.contains(query) : + self.cardData!.name.contains(query) || self.cardData!.cardholderName.contains(query) || self.cardData!.notes?.contains(query) ?? false + } + enum CipherType: Int, Codable { case Login = 0 case SecureNote @@ -121,19 +128,3 @@ class LibrePassCipher: Codable { var lastUsed: Int } } - -extension [LibrePassEncryptedCipher] { - mutating func addOrReplace(cipher: LibrePassEncryptedCipher) { - if let index = self.firstIndex(where: { cipher.id == $0.id }) { - self[index] = cipher - } else { - self.append(cipher) - } - } - - mutating func delete(id: String) { - if let index = self.firstIndex(where: { id == $0.id }) { - self.remove(at: index) - } - } -} diff --git a/LibrePass/App/LibrePassManagerWindow.swift b/LibrePass/App/LibrePassManagerWindow.swift index e1fbbcf..4361028 100644 --- a/LibrePass/App/LibrePassManagerWindow.swift +++ b/LibrePass/App/LibrePassManagerWindow.swift @@ -27,6 +27,8 @@ struct LibrePassManagerWindow: View { @Query var syncQueue: [SyncQueueItem] @Query var lastStorageItem: [LastSyncStorage] + @State var searchQuery: String = "" + var body: some View { NavigationView { List { @@ -34,7 +36,7 @@ struct LibrePassManagerWindow: View { ForEach(vault, id: \.self.id) { encCipher in let cipher = try? LibrePassCipher(encCipher: encCipher.encryptedCipher, key: self.context.lClient!.sharedKey!) - if let cipher = cipher { + if let cipher = cipher, self.searchQuery == "" || (self.searchQuery != "" && cipher.contains(query: self.searchQuery)) { NavigationLink(destination: CipherView(cipher: cipher, sync: self.syncVault)) { HStack { CipherButton(cipher: cipher) @@ -52,6 +54,7 @@ struct LibrePassManagerWindow: View { } .navigationTitle("Vault") + .searchable(text: self.$searchQuery) .toolbar { HStack { SpinningWheel(isPresented: self.$deletionIndicator, task: self.deleteCiphers)