From 93703a8a610dce4b1419ef41482efecc9d9e129c Mon Sep 17 00:00:00 2001 From: Joel-David Date: Sat, 28 Sep 2024 13:59:11 +0800 Subject: [PATCH 1/2] Optimised when otp are updated --- Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift index 358885a..5496f1c 100644 --- a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift +++ b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift @@ -19,9 +19,6 @@ struct TOTPRowView: View { .fontWeight(.light) .lineLimit(1) .onAppear(perform: updateOtp) - .onReceive(timer) { _ in - updateOtp() - } Spacer() @@ -60,10 +57,14 @@ struct TOTPRowView: View { private func updateProgress() { let timeLeft = timeLeftForToken(period: token.period) secsLeft = Int(timeLeft.rounded(.up)) - + // Circle progress will look smooth; however, the high redraw count causes significant CPU load. // progress = timeLeft / Double(token.period) progress = Double(secsLeft) / Double(token.period) + + if secsLeft == token.period { + updateOtp() + } } private func formatOtp(otp: String) -> String { From 7bcc3ee6d90869c3e55356a9b91fb1b8f3e81ead Mon Sep 17 00:00:00 2001 From: Joel-David Date: Sat, 28 Sep 2024 14:03:44 +0800 Subject: [PATCH 2/2] Fixed lint --- Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift index 5496f1c..5013da4 100644 --- a/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift +++ b/Chronos/App/Tabs/Tokens/Row/TOTPRowView.swift @@ -57,11 +57,11 @@ struct TOTPRowView: View { private func updateProgress() { let timeLeft = timeLeftForToken(period: token.period) secsLeft = Int(timeLeft.rounded(.up)) - + // Circle progress will look smooth; however, the high redraw count causes significant CPU load. // progress = timeLeft / Double(token.period) progress = Double(secsLeft) / Double(token.period) - + if secsLeft == token.period { updateOtp() }