Assorted changes

This commit is contained in:
Shadowfacts 2023-09-22 20:12:56 -04:00
parent 94c39fb5c5
commit d636f23ef3
6 changed files with 34 additions and 5 deletions

View File

@ -7,12 +7,12 @@
<key>OTP.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>OTPKit.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>

View File

@ -43,6 +43,15 @@ struct KeyData: Codable {
}
}
mutating func addOrUpdateFolders(_ folders: [Folder]) {
for f in folders {
guard !self.folders.contains(where: { $0.id == f.id }) else {
continue
}
self.folders.append(f)
}
}
mutating func updateKey(entryID id: UUID, newKey: TOTPKey) {
guard let index = entries.firstIndex(where: { $0.id == id }) else {
return

View File

@ -51,6 +51,7 @@ class KeyStore: ObservableObject {
data = newStore
} else {
data.addOrUpdateEntries(newStore.entries)
data.addOrUpdateFolders(newStore.folders)
}
}

View File

@ -84,6 +84,8 @@ extension AddQRView {
return "Scanner: Bad Input"
case .scanner(.badOutput):
return "Scanner: Bad Output"
case .scanner(.initError(let e)):
return ("Scanner: Initialization: \(e)")
}
}
}

View File

@ -6,6 +6,7 @@
//
import SwiftUI
import UniformTypeIdentifiers
struct FoldersSection: View {
@ObservedObject private var store: KeyStore = .shared
@ -15,6 +16,20 @@ struct FoldersSection: View {
Section {
ForEach(store.sortedFolders) { (folder) in
FolderRow(store: store, folder: folder)
.onDrop(of: [.text], isTargeted: nil) { providers in
guard let provider = providers.first,
provider.canLoadObject(ofClass: NSString.self) else {
return false
}
provider.loadObject(ofClass: NSString.self) { object, _ in
guard let str = object as? NSString,
let id = UUID(uuidString: str as String) else {
return
}
store.moveEntryToFolder(entryID: id, folderID: folder.id)
}
return true
}
}
.onDelete { (indices) in
let folderIDs = indices.map { store.sortedFolders[$0].id }

View File

@ -35,9 +35,11 @@ struct KeysSection: View {
ForEach(filteredEntries) { (entry) in
KeyView(key: entry.key, currentCode: entry.code)
// disabled because dropping onto list rows does not work :/
// .onDrag {
// NSItemProvider(object: entry.id.uuidString as NSString)
// }
.onDrag {
let provider = NSItemProvider()
provider.registerObject(entry.id.uuidString as NSString, visibility: .ownProcess)
return provider
}
.contextMenu {
self.keyMenu(entry: entry)
}