-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
SwiftUIViewFactory.swift
155 lines (122 loc) · 7 KB
/
SwiftUIViewFactory.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
//
// SwiftUIViewFactory.swift
// Strongbox
//
// Created by Strongbox on 05/07/2023.
// Copyright © 2023 Mark McGuill. All rights reserved.
//
import Foundation
import SwiftUI
class SwiftUIViewFactory: NSObject {
@objc static func makeImportResultViewController(messages: [ImportMessage] = [],
dismissHandler: @escaping ((_ cancel: Bool) -> Void)) -> UIViewController
{
let hostingController = UIHostingController(rootView: ImportResultView(dismiss: dismissHandler, messages: messages))
return hostingController
}
@objc static func makeSaleOfferViewController(sale: Sale,
existingSubscriber: Bool,
redeemHandler: @escaping (() -> Void),
onLifetimeHandler: @escaping (() -> Void),
dismissHandler: @escaping (() -> Void)) -> UIViewController
{
let hostingController = UIHostingController(rootView: SaleOfferView(dismiss: dismissHandler, onLifetime: onLifetimeHandler, redeem: redeemHandler, sale: sale, existingSubscriber: existingSubscriber))
return hostingController
}
#if !IS_APP_EXTENSION
@objc static func makeWhatsNewViewController(_ messages: [WhatsNewMessage], dismissHandler: @escaping (() -> Void)) -> UIViewController {
UIHostingController(rootView: WhatsNewView(messages: messages, dismiss: dismissHandler))
}
#endif
@objc static func makeWiFiSyncPasscodeViewController(_ server: WiFiSyncServerConfig, onDone: @escaping ((_ server: WiFiSyncServerConfig?, _ pinCode: String?) -> Void)) -> UIViewController {
let hostingController = UIHostingController(rootView: PasscodeEntryView(server: server, onDone: onDone))
return hostingController
}
@objc static func showKeyFileGeneratorScreen(keyFile: KeyFile,
onPrint: @escaping (() -> Void),
onSave: @escaping (() -> Bool),
onDismiss: @escaping (() -> Void)) -> UIViewController
{
let view = GenerateKeyFileScreen(keyFile: keyFile, onPrint: onPrint, onSave: onSave) {
onDismiss()
}
let hostingController = UIHostingController(rootView: view)
return hostingController
}
@objc static func showKeyFileRecoveryScreen(onRecover: @escaping ((_ keyFile: KeyFile) -> Void),
onDismiss: @escaping (() -> Void)) -> UIViewController
{
let view = RecoverKeyFileScreen(verifyHash: { codes, hash in
guard let keyFile = KeyFile.fromHexCodes(codes) else {
return false
}
return keyFile.hashString.uppercased() == hash.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
},
validateCodes: { codes in
KeyFile.fromHexCodes(codes) != nil
},
onRecover: { codes in
guard let keyFile = KeyFile.fromHexCodes(codes) else {
swlog("🔴 ERROR: Invalid Hex Codes for Key File, should never happen!")
return
}
onRecover(keyFile)
onDismiss()
}) {
onDismiss()
}
let hostingController = UIHostingController(rootView: view)
return hostingController
}
@objc static func getLargeTextDisplayView(text: String, font: UIFont, colorize: Bool, colorBlind: Bool, onTapped: @escaping (() -> Void)) -> UIViewController {
let view = LargeTextDisplayView(text: text, font: Font(font), colorize: colorize, colorBlind: colorBlind) {
onTapped()
}
let hostingController = UIHostingController(rootView: view.ignoresSafeArea())
return hostingController
}
@objc static func getTagsEditorView(existingTags: Set<String>,
allTags: Set<String>,
completion: @escaping ((_ cancelled: Bool, _ selectedTags: Set<String>?) -> Void)) -> UIViewController
{
let view = TagsEditorView(currentItemTags: existingTags, allTags: allTags, completion: completion)
let hostingController = UIHostingController(rootView: view)
return hostingController
}
#if !IS_APP_EXTENSION && !NO_NETWORKING
@objc static func getOneDriveRootNavigatorView(existing: Bool, completion: @escaping ((_ cancelled: Bool, _ selectedMode: OneDriveNavigationContextMode) -> Void)) -> UIViewController {
let view = OneDriveRootNavigator(selectExisting: existing, appIsPro: AppPreferences.sharedInstance().isPro, completion: completion)
let hostingController = UIHostingController(rootView: view)
return hostingController
}
#endif
#if !IS_APP_EXTENSION
static func getDatabaseHomeView(model: DatabaseHomeViewModel) -> UIViewController {
let view = DatabaseHomeView(model: model)
let hostingController = UIHostingController(rootView: view)
return hostingController
}
static func getAuditIssuesView(model: DatabaseHomeViewModel) -> UIViewController {
UIHostingController(rootView: AuditNavigationView(model: model))
}
@objc
static func getHardwareKeySettingsView(metadata: METADATA_PTR, onSettingsChanged: ((Bool, Int, Int, Bool) -> Void)?, completion: (() -> Void)? = nil) -> UIViewController {
UIHostingController(
rootView: HardwareKeySettingsView(
keyCachingEnabled: metadata.hardwareKeyCRCaching,
autoFillRefreshSuppressed: metadata.doNotRefreshChallengeInAF,
cacheChallengeDurationSecs: metadata.cacheChallengeDurationSecs,
challengeRefreshIntervalSecs: metadata.challengeRefreshIntervalSecs,
onSettingsChanged: onSettingsChanged,
completion: completion
))
}
@objc
static func getTheGarageViewController() -> UIViewController {
let viewModel = TheGarageViewModel(watchStatus: WatchAppManager.shared.status, preferences: AppPreferences.sharedInstance())
let view = TheGarageView(model: viewModel)
.defaultAppStorage(UserDefaults.StrongboxAppGroupUserDefaults)
return UIHostingController(rootView: view)
}
#endif
}