-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathUIKitDatabaseActionsInterface.swift
336 lines (275 loc) · 11.1 KB
/
UIKitDatabaseActionsInterface.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
//
// UIKitDatabaseActionsInterface.swift
// Strongbox
//
// Created by Strongbox on 27/07/2024.
// Copyright © 2024 Mark McGuill. All rights reserved.
//
import Foundation
import SwiftUI
import UIKit
class UIKitDatabaseActionsInterface: DatabaseActionsInterface {
let viewModel: Model
var browseActionsHelper: BrowseActionsHelper!
weak var navController: UINavigationController! {
didSet {
browseActionsHelper = BrowseActionsHelper(model: viewModel, viewController: navController, updateDatabaseAction: { [weak self] clearSelectedDetailItem, completion in
Task { [weak self] in
guard let self else {
return
}
let savedLocal = await saveAndNotifyAfterChanges(clearSelectedDetailItem: clearSelectedDetailItem)
completion?(savedLocal)
}
})
}
}
init(viewModel: Model) {
self.viewModel = viewModel
}
@MainActor
var splitViewController: MainSplitViewController {
navController.splitViewController as! MainSplitViewController
}
@MainActor
var tabBarController: BrowseTabViewController {
navController.tabBarController as! BrowseTabViewController
}
@MainActor
func close() {
splitViewController.closeAndCleanup()
}
@MainActor
func navigateTo(destination: DatabaseNavigationDestination, homeModel: DatabaseHomeViewModel) {
switch destination {
case let .entryDetail(uuid):
let vc = ItemDetailsViewController.fromStoryboard(viewModel, nodeUuid: uuid)
splitViewController.showDetailViewController(vc, sender: nil)
case .allEntries:
let browse = BrowseSafeView.fromStoryboard(.list, model: viewModel)
navController.pushViewController(browse, animated: true)
case .groups:
let browse = BrowseSafeView.fromStoryboard(.hierarchy, model: viewModel)
navController.pushViewController(browse, animated: true)
case .totps:
let browse = BrowseSafeView.fromStoryboard(.totpList, model: viewModel)
navController.pushViewController(browse, animated: true)
case .favourites:
let browse = BrowseSafeView.fromStoryboard(.favourites, model: viewModel)
navController.pushViewController(browse, animated: true)
case let .tags(tag):
let browse = BrowseSafeView.fromStoryboard(.tags, model: viewModel)
browse.currentTag = tag
navController.pushViewController(browse, animated: true)
case .recycleBin:
guard let recycleBinUuid = viewModel.database.recycleBinNodeUuid else {
swlog("🔴 Recycle Bin Navigation requested but no recycle bin exists! ")
return
}
let browse = BrowseSafeView.fromStoryboard(.hierarchy, model: viewModel)
browse.currentGroupId = recycleBinUuid
navController.pushViewController(browse, animated: true)
case .sshKeys:
let browse = BrowseSafeView.fromStoryboard(.sshKeys, model: viewModel)
navController.pushViewController(browse, animated: true)
case .passkeys:
let browse = BrowseSafeView.fromStoryboard(.passkeys, model: viewModel)
navController.pushViewController(browse, animated: true)
case .attachments:
let browse = BrowseSafeView.fromStoryboard(.attachments, model: viewModel)
navController.pushViewController(browse, animated: true)
case .expiredAndExpiring:
let browse = BrowseSafeView.fromStoryboard(.expiredAndExpiring, model: viewModel)
navController.pushViewController(browse, animated: true)
case .auditIssues:
let auditNavView = UIHostingController(rootView: AuditNavigationView(model: homeModel, showCloseButton: false))
navController.pushViewController(auditNavView, animated: true)
case .watchEntries:
let browse = BrowseSafeView.fromStoryboard(.watchEntries, model: viewModel)
navController.pushViewController(browse, animated: true)
}
}
@MainActor
func interactiveSyncAppleWatch(_ withInteractiveGuide: Bool = false, allowUserToOptOut: Bool = false) {
splitViewController.syncAppleWatchNow(interactiveGuide: withInteractiveGuide, allowUserToOptOut: false)
}
func onPulldownToRefresh() async {
await splitViewController.onManualPullDownRefresh {}
}
func showPassword(entry: any SwiftEntryModelInterface) {
browseActionsHelper.showPassword(entry.uuid)
}
func showAuditDrillDown(entry: any SwiftEntryModelInterface) {
browseActionsHelper.showAuditDrillDown(entry.uuid)
}
func presentHardwareKeySettings() {
browseActionsHelper.showHardwareKeySettings()
}
func updateAndQueueSync() async -> Bool {
await splitViewController.updateAndQueueSync()
}
func copyPassword(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyPassword(entry.uuid)
}
func copyAllFields(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyAllFields(entry.uuid)
}
func copyUsername(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyUsername(entry.uuid)
}
func copyTotp(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyTotp(entry.uuid)
}
func copyUrl(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyUrl(entry.uuid)
}
func copyEmail(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyEmail(entry.uuid)
}
func copyNotes(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyNotes(entry.uuid)
}
func copyAndLaunch(entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyAndLaunch(entry.uuid)
}
func copyCustomField(key: String, entry: any SwiftEntryModelInterface) {
browseActionsHelper.copyCustomField(key, uuid: entry.uuid)
}
func deleteItem(item: any SwiftItemModelInterface) async -> Bool {
await browseActionsHelper.deleteSingleItem(item.uuid)
}
func emptyRecycleBin() async {
await browseActionsHelper.emptyRecycleBin()
}
@MainActor
var tabBarControllerIsHidden: Bool {
guard let tabBarController = navController.tabBarController else {
swlog("🔴 Couldn't get tab bar controller?!")
return true
}
return tabBarController.tabBar.isHidden
}
var biometricsIsFaceId: Bool {
BiometricsManager.sharedInstance().isFaceId()
}
var watchIsPairedAndInstalled: Bool {
WatchAppManager.shared.watchIsPairedAndInstalled
}
@MainActor
func presentConfigureTabsView() {
let vc = ConfigureTabsViewController.fromStoryboard(model: viewModel)
navController.present(vc, animated: true)
}
@MainActor
func presentCustomizeView() {
let vc = BrowsePreferencesTableViewController.fromStoryboard()
vc.model = viewModel
let embedInNav = UINavigationController(rootViewController: vc)
embedInNav.modalPresentationStyle = .formSheet
navController.present(embedInNav, animated: true)
}
@MainActor
func presentConvenienceUnlockPreferences() {
let vc = ConvenienceUnlockPreferences.fromStoryboard(with: viewModel)
navController.present(vc, animated: true)
}
@MainActor
func presentAutoFillSettings() {
let vc = AutoFillPreferencesViewController.fromStoryboard(with: viewModel)
navController.present(vc, animated: true)
}
@MainActor
func presentAuditSettings() {
let vc = AuditConfigurationVcTableViewController.fromStoryboard()
vc.model = viewModel
vc.updateDatabase = { [weak self] in
Task { [weak self] in
await self?.saveAndNotifyAfterChanges()
}
}
let embedInNav = UINavigationController(rootViewController: vc)
embedInNav.modalPresentationStyle = .formSheet
navController.present(embedInNav, animated: true)
}
@MainActor
func presentAutoLockSettings() {
let vc = AutomaticLockingPreferences.fromStoryboard(with: viewModel)
let embedInNav = UINavigationController(rootViewController: vc)
embedInNav.modalPresentationStyle = .formSheet
navController.present(embedInNav, animated: true)
}
@MainActor
func presentAdvancedSettings() {
let vc = AdvancedDatabaseSettings.fromStoryboard()
vc.viewModel = viewModel
vc.onDatabaseBulkIconUpdate = { [weak self] selectedFavIcons in
self?.browseActionsHelper.onDatabaseBulkIconUpdate(selectedFavIcons)
}
let embedInNav = UINavigationController(rootViewController: vc)
embedInNav.modalPresentationStyle = .formSheet
navController.present(embedInNav, animated: true)
}
@MainActor
func presentEncryptionSettings() {
let embedInNav = EncryptionPreferencesViewController.fromStoryboard()
let vc = embedInNav.topViewController as! EncryptionPreferencesViewController
vc.model = viewModel
vc.onChangedDatabaseEncryptionSettings = { [weak self] in
Task { [weak self] in
await self?.saveAndNotifyAfterChanges()
}
}
embedInNav.modalPresentationStyle = .formSheet
navController.present(embedInNav, animated: true)
}
@MainActor
func presentSetMasterCredentials() {
browseActionsHelper.presentSetCredentials()
}
@MainActor
func onAddEntry() {
let vc = ItemDetailsViewController.fromStoryboard(viewModel, nodeUuid: nil)
splitViewController.showDetailViewController(vc, sender: nil)
}
@MainActor
func exportDatabase() {
browseActionsHelper.exportDatabase()
}
@MainActor
func printDatabase() {
browseActionsHelper.printDatabase()
}
@MainActor
func saveAndNotifyAfterChanges(clearSelectedDetailItem: Bool = false) async -> Bool {
notifyModelUpdated()
if clearSelectedDetailItem, !splitViewController.isCollapsed {
let sb = UIStoryboard(name: "EmptyDetails", bundle: nil)
if let vc = sb.instantiateInitialViewController() {
splitViewController.showDetailViewController(vc, sender: nil)
}
}
return await updateAndQueueSync()
}
@MainActor
func notifyModelUpdated() {
NotificationCenter.default.post(name: .modelEdited, object: viewModel)
}
var syncStatus: SyncStatus {
SyncManager.sharedInstance().getSyncStatus(viewModel.metadata)
}
var isRunningAsyncUpdate: Bool {
viewModel.isRunningAsyncUpdate
}
var lastAsyncUpdateResult: AsyncJobResult? {
viewModel.lastAsyncUpdateResult
}
@MainActor
var hasDoneDatabaseOnLaunchTasks: Bool {
get {
splitViewController.hasDoneDatabaseOnLaunchTasks
}
set {
splitViewController.hasDoneDatabaseOnLaunchTasks = newValue
}
}
}