-
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathTwoFactorView.swift
More file actions
156 lines (131 loc) · 5.65 KB
/
TwoFactorView.swift
File metadata and controls
156 lines (131 loc) · 5.65 KB
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
//
// TwoFactorView.swift
// Strongbox
//
// Created by Strongbox on 26/07/2024.
// Copyright © 2024 Mark McGuill. All rights reserved.
//
import SwiftUI
@available(iOS 16.0, *)
struct TwoFactorView: View {
var totp: OTPToken
var updateMode: TwoFactorUpdateMode
var easyReadSeparator: Bool
var font: Font
var hideCountdownDigits: Bool
var radius: CGFloat = 55
var title: String? = nil
var subtitle: String? = nil
var image: IMAGE_TYPE_PTR? = nil
var onQrCode: (() -> Void)? = nil
@ViewBuilder
var imageView: some View {
if let image {
#if os(macOS)
Image(nsImage: image)
.resizable()
#else
Image(uiImage: image)
.resizable()
#endif
} else {
EmptyView()
}
}
var body: some View {
VStack(alignment: .leading) {
HStack {
imageView
.scaledToFit()
.frame(width: 40, height: 40)
.cornerRadius(3.0)
.shadow(radius: 3)
.foregroundStyle(.blue)
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 4) {
if let title {
Text(title)
.font(.headline)
.lineLimit(1)
}
if let subtitle {
Text(subtitle)
.foregroundStyle(.secondary)
.font(.caption2)
.lineLimit(1)
} else {
Text("generic_fieldname_totp")
.foregroundStyle(.secondary)
.font(.caption2)
.lineLimit(1)
}
}
TwoFactorCodeView(totp: totp, updateMode: updateMode, easyReadSeparator: easyReadSeparator, isPro: true, limitNonPro: false, font: font, colorize: false)
if let issuerAndName = totp.issuerAndName {
Text(issuerAndName)
.foregroundStyle(.tertiary)
.font(.caption2)
.lineLimit(1)
}
}
Spacer()
HStack {
TwoFactorCodeCircularProgressView(
totp: totp,
radius: radius,
updateMode: updateMode,
hideCountdownDigits: hideCountdownDigits
)
if let onQrCode {
Button {
onQrCode()
} label: {
Image(systemName: "qrcode").font(.title)
}
.buttonStyle(.plain)
}
}
}
}
#if os(macOS)
.padding(.vertical)
#endif
}
}
@available(iOS 16.0, *)
#Preview {
let otpAuthUrl = "otpauth:
let token = OTPToken(url: URL(string: otpAuthUrl))!
let otpAuthUrl8Digit = "otpauth:
let token8Digit = OTPToken(url: URL(string: otpAuthUrl8Digit))!
let otpAuthUrl8Digits60Seconds = "otpauth:
let token8Digits60Seconds = OTPToken(url: URL(string: otpAuthUrl8Digits60Seconds))!
let otpAuthUrl8Digits120Seconds = "otpauth:
let token8Digits120Seconds = OTPToken(url: URL(string: otpAuthUrl8Digits120Seconds))!
let otpAuthUrlSha25645Seconds = "otpauth:
let tokenSha25645Seconds = OTPToken(url: URL(string: otpAuthUrlSha25645Seconds))!
let otpAuthUrlSha51215Seconds = "otpauth:
let tokenSha51215Seconds = OTPToken(url: URL(string: otpAuthUrlSha51215Seconds))!
let otpAuthUrlSteam = "otpauth:
let tokenSteam = OTPToken(url: URL(string: otpAuthUrlSteam))!
#if os(macOS)
let bar = NSImage(named: "AppIcon-2019-1024")!
#else
let bar = UIImage(named: "AppIcon-2019-1024")!
#endif
return NavigationView {
List {
TwoFactorView(totp: token, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true, title: "HSBC", subtitle: "markymark", image: bar) {}
TwoFactorView(totp: tokenSteam, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
TwoFactorView(totp: token8Digits120Seconds, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
TwoFactorView(totp: token8Digit, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
TwoFactorView(totp: token8Digits60Seconds, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
TwoFactorView(totp: tokenSha25645Seconds, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
TwoFactorView(totp: tokenSha51215Seconds, updateMode: .automatic, easyReadSeparator: true, font: Font(FontManager.sharedInstance().easyReadFontForTotp), hideCountdownDigits: true)
}
.navigationTitle("Sample Item")
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
}