[PM-1748] Fix Watch TOTP details on Always On Display (#2515)

* PM-1748 Fix watchOS issue where the TOTP code wasn't being regenerated after always on display. Also, blurred totp code and timer value when entering in Always On Display

* Fixed PR labeler for WatchOS changes

* PM-1748 watchOS made username privacy sensitive for always on display

* Revert "Fixed PR labeler for WatchOS changes"

This reverts commit 3c55f38069.

---------

Co-authored-by: Álison Fernandes <vvolkgang@users.noreply.github.com>
This commit is contained in:
Federico Maccaroni 2023-05-10 16:59:49 +02:00 committed by GitHub
parent 6bb654e630
commit 37f1a7087e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 11 deletions

View File

@ -2,7 +2,7 @@ import Foundation
struct CipherMock {
static let ciphers:[Cipher] = [
Cipher(id: "0", name: "1933", userId: "123123", login: Login(username: "thisisatest@testing.com", totp: "otpauth://account?period=10&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)),
Cipher(id: "0", name: "MySite", userId: "123123", login: Login(username: "test@testing.com", totp: "otpauth://account?period=10&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)),
Cipher(id: "1", name: "GitHub", userId: "123123", login: Login(username: "thisisatest@testing.com", totp: "LLLLLLLLLLLLLLLL", uris: cipherLoginUris)),
Cipher(id: "2", name: "No user", userId: "123123", login: Login(username: nil, totp: "otpauth://account?period=10&digits=8&algorithm=sha256&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)),
Cipher(id: "3", name: "Site 2", userId: "123123", login: Login(username: "longtestemail000000@fastmailasdfasdf.com", totp: "otpauth://account?period=10&digits=7&algorithm=sha512&secret=LLLLLLLLLLLLLLLL", uris: cipherLoginUris)),

View File

@ -34,30 +34,34 @@ class CipherDetailsViewModel: ObservableObject{
self.counter = self.period - mod
self.progress = Double(self.counter) / Double(self.period)
}
if mod == 0 || self.totpFormatted == "" {
do {
var totpF = try TotpService.shared.GetCodeAsync(key: self.key) ?? ""
if totpF.count > 4 {
let halfIndex = totpF.index(totpF.startIndex, offsetBy: totpF.count / 2)
totpF = "\(totpF[totpF.startIndex..<halfIndex]) \(totpF[halfIndex..<totpF.endIndex])"
}
DispatchQueue.main.async {
self.totpFormatted = totpF
}
try self.regenerateTotp()
} catch {
DispatchQueue.main.async {
self.totpFormatted = "error"
t.invalidate()
}
}
}
})
RunLoop.current.add(timer!, forMode: .common)
timer?.fire()
}
func stopGeneration(){
func stopGeneration() {
self.timer?.invalidate()
}
func regenerateTotp() throws {
var totpF = try TotpService.shared.GetCodeAsync(key: self.key) ?? ""
if totpF.count > 4 {
let halfIndex = totpF.index(totpF.startIndex, offsetBy: totpF.count / 2)
totpF = "\(totpF[totpF.startIndex..<halfIndex]) \(totpF[halfIndex..<totpF.endIndex])"
}
DispatchQueue.main.async {
self.totpFormatted = totpF
}
}
}

View File

@ -2,6 +2,7 @@ import SwiftUI
struct CipherDetailsView: View {
@ObservedObject var cipherDetailsViewModel: CipherDetailsViewModel
@Environment(\.scenePhase) var scenePhase
let iconSize: CGSize = CGSize(width: 30, height: 30)
@ -49,6 +50,7 @@ struct CipherDetailsView: View {
.fontWeight(.bold)
.lineLimit(1)
.truncationMode(.tail)
.privacySensitive()
}
if cipherDetailsViewModel.totpFormatted == "" {
ProgressView()
@ -61,6 +63,7 @@ struct CipherDetailsView: View {
.minimumScaleFactor(0.01)
.lineLimit(1)
.id(cipherDetailsViewModel.totpFormatted)
.privacySensitive()
.transition(transition)
.animation(.default.speed(0.7), value: cipherDetailsViewModel.totpFormatted)
Spacer()
@ -70,6 +73,7 @@ struct CipherDetailsView: View {
Text("\(cipherDetailsViewModel.counter)")
.font(.title3)
.fontWeight(.semibold)
.privacySensitive()
}
}
.padding(.top, 20)
@ -83,6 +87,11 @@ struct CipherDetailsView: View {
.onDisappear{
self.cipherDetailsViewModel.stopGeneration()
}
.onChange(of: scenePhase) { newPhase in
if newPhase == .active {
try? self.cipherDetailsViewModel.regenerateTotp()
}
}
}
var iconPlaceholderImage: some View{

View File

@ -36,6 +36,7 @@ struct CipherItemView: View {
.truncationMode(.tail)
.foregroundColor(Color.ui.darkTextMuted)
.frame(maxWidth: .infinity, alignment: .leading)
.privacySensitive()
}
}
.padding()

View File

@ -87,6 +87,7 @@ struct CipherListView: View {
.font(.headline)
.lineLimit(1)
.truncationMode(.tail)
.privacySensitive()
}
}