From b73ba4a22f3d0d54c5f22a7f575ed674c11f7154 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:42:29 +0530 Subject: [PATCH 1/5] [auth][mac] build changes --- auth/macos/Runner.xcodeproj/project.pbxproj | 1 + auth/pubspec.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/auth/macos/Runner.xcodeproj/project.pbxproj b/auth/macos/Runner.xcodeproj/project.pbxproj index 492f710ada..a2ed68c3c5 100644 --- a/auth/macos/Runner.xcodeproj/project.pbxproj +++ b/auth/macos/Runner.xcodeproj/project.pbxproj @@ -429,6 +429,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.14; + ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.ente.auth.mac; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; diff --git a/auth/pubspec.lock b/auth/pubspec.lock index b6e72978b2..c42a124ad7 100644 --- a/auth/pubspec.lock +++ b/auth/pubspec.lock @@ -42,10 +42,10 @@ packages: dependency: "direct main" description: name: app_links - sha256: ad1a6d598e7e39b46a34f746f9a8b011ee147e4c275d407fa457e7a62f84dd99 + sha256: "433df2e61b10519407475d7f69e470789d23d593f28224c38ba1068597be7950" url: "https://pub.dev" source: hosted - version: "6.3.2" + version: "6.3.3" app_links_linux: dependency: transitive description: @@ -528,10 +528,10 @@ packages: dependency: "direct main" description: name: flutter_inappwebview - sha256: "93cfcca02bdda4b26cd700cf70d9ddba09d8348e3e8f2857638c23ed23a4fcb4" + sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5" url: "https://pub.dev" source: hosted - version: "6.1.4" + version: "6.1.5" flutter_inappwebview_android: dependency: transitive description: @@ -584,10 +584,10 @@ packages: dependency: transitive description: name: flutter_inappwebview_windows - sha256: "95ebc65aecfa63b2084c822aec6ba0545f0a0afaa3899f2c752ec96c09108db5" + sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055" url: "https://pub.dev" source: hosted - version: "0.5.0+2" + version: "0.6.0" flutter_launcher_icons: dependency: "direct main" description: @@ -1655,10 +1655,10 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3" + sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603" url: "https://pub.dev" source: hosted - version: "6.3.0" + version: "6.3.1" url_launcher_android: dependency: transitive description: @@ -1668,7 +1668,7 @@ packages: source: hosted version: "6.3.11" url_launcher_ios: - dependency: transitive + dependency: "direct main" description: name: url_launcher_ios sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e From e0abb2de9c64b97f3cffa046254d166513241e71 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 26 Dec 2024 11:44:37 +0530 Subject: [PATCH 2/5] [auth] Add dependency on super_text_layout --- auth/pubspec.lock | 92 +++++++++++++++++++++++++++++++++++++++++++++-- auth/pubspec.yaml | 1 + 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/auth/pubspec.lock b/auth/pubspec.lock index c42a124ad7..a19f886e22 100644 --- a/auth/pubspec.lock +++ b/auth/pubspec.lock @@ -94,6 +94,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + attributed_text: + dependency: transitive + description: + name: attributed_text + sha256: fb65cf441784612544eda4d5df7a3caad56e7f673c68bf1d48d9048228375189 + url: "https://pub.dev" + source: hosted + version: "0.4.0" auto_size_text: dependency: "direct main" description: @@ -286,6 +294,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" + coverage: + dependency: transitive + description: + name: coverage + sha256: e3493833ea012784c740e341952298f1cc77f1f01b1bbc3eb4eecf6984fb7f43 + url: "https://pub.dev" + source: hosted + version: "1.11.1" cross_file: dependency: transitive description: @@ -985,10 +1001,10 @@ packages: dependency: "direct main" description: name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" macros: dependency: transitive description: @@ -1077,6 +1093,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" otp: dependency: "direct main" description: @@ -1405,6 +1429,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 + url: "https://pub.dev" + source: hosted + version: "1.1.3" shelf_web_socket: dependency: transitive description: @@ -1458,6 +1498,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.4" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b + url: "https://pub.dev" + source: hosted + version: "2.1.2" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" + url: "https://pub.dev" + source: hosted + version: "0.10.13" source_span: dependency: transitive description: @@ -1571,6 +1627,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.0" + super_text_layout: + dependency: "direct main" + description: + name: super_text_layout + sha256: "0c85c295164edaab175c477584f2b7abc295dfd2a7f81987a88e538cf75b7898" + url: "https://pub.dev" + source: hosted + version: "0.1.17" synchronized: dependency: transitive description: @@ -1587,6 +1651,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + test: + dependency: transitive + description: + name: test + sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" + url: "https://pub.dev" + source: hosted + version: "1.25.7" test_api: dependency: transitive description: @@ -1595,6 +1667,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" + test_core: + dependency: transitive + description: + name: test_core + sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" + url: "https://pub.dev" + source: hosted + version: "0.6.4" timezone: dependency: transitive description: @@ -1795,6 +1875,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" win32: dependency: "direct main" description: diff --git a/auth/pubspec.yaml b/auth/pubspec.yaml index 6d2a932c40..3356410238 100644 --- a/auth/pubspec.yaml +++ b/auth/pubspec.yaml @@ -86,6 +86,7 @@ dependencies: sentry_flutter: ^8.7.0 share_plus: ^10.0.2 shared_preferences: ^2.0.5 + super_text_layout: ^0.1.17 sqflite: git: url: https://github.com/tekartik/sqflite From bf9d0e3d6b7281c860a40d632aa84ea8650e9bf7 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:18:35 +0530 Subject: [PATCH 3/5] [auth] Reduce refresh rate for progress bar to lower CPU usage --- auth/lib/ui/code_timer_progress.dart | 69 ++++++++++++---------- auth/lib/ui/code_widget.dart | 6 +- auth/pubspec.lock | 88 ---------------------------- auth/pubspec.yaml | 1 - 4 files changed, 41 insertions(+), 123 deletions(-) diff --git a/auth/lib/ui/code_timer_progress.dart b/auth/lib/ui/code_timer_progress.dart index e594e15fb1..2b29be0403 100644 --- a/auth/lib/ui/code_timer_progress.dart +++ b/auth/lib/ui/code_timer_progress.dart @@ -1,58 +1,59 @@ -import 'package:ente_auth/services/preference_service.dart'; +import 'dart:async'; +import 'dart:io'; + import 'package:ente_auth/theme/ente_theme.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/scheduler.dart'; - -class CodeTimerProgressCache { - static final Map _cache = {}; - - static CodeTimerProgress getCachedWidget(int period) { - if (!_cache.containsKey(period)) { - _cache[period] = CodeTimerProgress(period: period); - } - return _cache[period]!; - } -} +import 'package:flutter_launcher_icons/logger.dart'; class CodeTimerProgress extends StatefulWidget { final int period; - + final bool isCompactMode; const CodeTimerProgress({ super.key, required this.period, + this.isCompactMode = false, }); @override State createState() => _CodeTimerProgressState(); } -class _CodeTimerProgressState extends State - with SingleTickerProviderStateMixin { - late final Ticker _ticker; +class _CodeTimerProgressState extends State { + late final Timer _timer; late final ValueNotifier _progress; - late final int _microSecondsInPeriod; - late bool _isCompactMode=false; + late final int _periodInMicros; + + // Cache the start time to avoid repeated system calls + late final int _startMicros; + + // Reduce update frequency + final int _updateIntervalMs = + (Platform.isAndroid || Platform.isIOS) ? 16 : 500; // approximately 60 FPS @override void initState() { super.initState(); - _microSecondsInPeriod = widget.period * 1000000; + _periodInMicros = widget.period * 1000000; _progress = ValueNotifier(0.0); - _ticker = createTicker(_updateTimeRemaining); - _ticker.start(); - _isCompactMode = PreferenceService.instance.isCompactMode(); - _updateTimeRemaining(Duration.zero); + _startMicros = DateTime.now().microsecondsSinceEpoch; + + // Use a Timer instead of a Ticker + _timer = Timer.periodic(Duration(milliseconds: _updateIntervalMs), (timer) { + final now = DateTime.now().microsecondsSinceEpoch; + _updateTimeRemaining(now); + }); } - void _updateTimeRemaining(Duration elapsed) { - int timeRemaining = _microSecondsInPeriod - - (DateTime.now().microsecondsSinceEpoch % _microSecondsInPeriod); - _progress.value = timeRemaining / _microSecondsInPeriod; + void _updateTimeRemaining(int currentMicros) { + // More efficient time calculation using modulo + final elapsed = (currentMicros - _startMicros) % _periodInMicros; + final timeRemaining = _periodInMicros - elapsed; + _progress.value = timeRemaining / _periodInMicros; } @override void dispose() { - _ticker.dispose(); + _timer.cancel(); _progress.dispose(); super.dispose(); } @@ -60,18 +61,19 @@ class _CodeTimerProgressState extends State @override Widget build(BuildContext context) { return SizedBox( - height: _isCompactMode ?1:3, + height: widget.isCompactMode ? 1 : 3, child: ValueListenableBuilder( valueListenable: _progress, builder: (context, progress, _) { return CustomPaint( + key: Key(progress.toString()), // Add key here painter: _ProgressPainter( progress: progress, color: progress > 0.4 ? getEnteColorScheme(context).primary700 : Colors.orange, ), - size: Size.infinite, + size: const Size.fromHeight(double.infinity), ); }, ), @@ -83,7 +85,10 @@ class _ProgressPainter extends CustomPainter { final double progress; final Color color; - _ProgressPainter({required this.progress, required this.color}); + const _ProgressPainter({ + required this.progress, + required this.color, + }); @override void paint(Canvas canvas, Size size) { diff --git a/auth/lib/ui/code_widget.dart b/auth/lib/ui/code_widget.dart index c04feddfb0..509060f3cd 100644 --- a/auth/lib/ui/code_widget.dart +++ b/auth/lib/ui/code_widget.dart @@ -146,8 +146,10 @@ class _CodeWidgetState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ if (widget.code.type.isTOTPCompatible) - CodeTimerProgressCache.getCachedWidget( - widget.code.period, + CodeTimerProgress( + key: ValueKey('period_${widget.code.period}'), + period: widget.code.period, + isCompactMode: widget.isCompactMode, ), widget.isCompactMode ? const SizedBox(height: 4) diff --git a/auth/pubspec.lock b/auth/pubspec.lock index a19f886e22..0568bf396d 100644 --- a/auth/pubspec.lock +++ b/auth/pubspec.lock @@ -94,14 +94,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" - attributed_text: - dependency: transitive - description: - name: attributed_text - sha256: fb65cf441784612544eda4d5df7a3caad56e7f673c68bf1d48d9048228375189 - url: "https://pub.dev" - source: hosted - version: "0.4.0" auto_size_text: dependency: "direct main" description: @@ -294,14 +286,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" - coverage: - dependency: transitive - description: - name: coverage - sha256: e3493833ea012784c740e341952298f1cc77f1f01b1bbc3eb4eecf6984fb7f43 - url: "https://pub.dev" - source: hosted - version: "1.11.1" cross_file: dependency: transitive description: @@ -1093,14 +1077,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.0" - node_preamble: - dependency: transitive - description: - name: node_preamble - sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" - url: "https://pub.dev" - source: hosted - version: "2.0.2" otp: dependency: "direct main" description: @@ -1429,22 +1405,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - shelf_static: - dependency: transitive - description: - name: shelf_static - sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 - url: "https://pub.dev" - source: hosted - version: "1.1.3" shelf_web_socket: dependency: transitive description: @@ -1498,22 +1458,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.4" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b - url: "https://pub.dev" - source: hosted - version: "2.1.2" - source_maps: - dependency: transitive - description: - name: source_maps - sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" - url: "https://pub.dev" - source: hosted - version: "0.10.13" source_span: dependency: transitive description: @@ -1627,14 +1571,6 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.0" - super_text_layout: - dependency: "direct main" - description: - name: super_text_layout - sha256: "0c85c295164edaab175c477584f2b7abc295dfd2a7f81987a88e538cf75b7898" - url: "https://pub.dev" - source: hosted - version: "0.1.17" synchronized: dependency: transitive description: @@ -1651,14 +1587,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" - test: - dependency: transitive - description: - name: test - sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" - url: "https://pub.dev" - source: hosted - version: "1.25.7" test_api: dependency: transitive description: @@ -1667,14 +1595,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" - test_core: - dependency: transitive - description: - name: test_core - sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" - url: "https://pub.dev" - source: hosted - version: "0.6.4" timezone: dependency: transitive description: @@ -1875,14 +1795,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" - webkit_inspection_protocol: - dependency: transitive - description: - name: webkit_inspection_protocol - sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" - url: "https://pub.dev" - source: hosted - version: "1.2.1" win32: dependency: "direct main" description: diff --git a/auth/pubspec.yaml b/auth/pubspec.yaml index 3356410238..6d2a932c40 100644 --- a/auth/pubspec.yaml +++ b/auth/pubspec.yaml @@ -86,7 +86,6 @@ dependencies: sentry_flutter: ^8.7.0 share_plus: ^10.0.2 shared_preferences: ^2.0.5 - super_text_layout: ^0.1.17 sqflite: git: url: https://github.com/tekartik/sqflite From d23c22762b939351db3cbe33abd114dfac87fff1 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:12:29 +0530 Subject: [PATCH 4/5] [auth] Bump version 4.2.1 --- auth/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/pubspec.yaml b/auth/pubspec.yaml index 6d2a932c40..e691cd8d16 100644 --- a/auth/pubspec.yaml +++ b/auth/pubspec.yaml @@ -1,6 +1,6 @@ name: ente_auth description: ente two-factor authenticator -version: 4.2.0+420 +version: 4.2.1+421 publish_to: none environment: From 2a19c30d0e5ea215b1c6d2f54f3aefbb9fc2f216 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:12:42 +0530 Subject: [PATCH 5/5] Lint fix --- auth/lib/ui/code_timer_progress.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/auth/lib/ui/code_timer_progress.dart b/auth/lib/ui/code_timer_progress.dart index 2b29be0403..ea62860268 100644 --- a/auth/lib/ui/code_timer_progress.dart +++ b/auth/lib/ui/code_timer_progress.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:ente_auth/theme/ente_theme.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_launcher_icons/logger.dart'; class CodeTimerProgress extends StatefulWidget { final int period;