An open-source cross-platform alternative to AirDrop
perf: coalesce native taskbar progress updates (#3597)
Shlomoedf3879766e7
diff --git a/app/lib/util/native/taskbar_helper.dart b/app/lib/util/native/taskbar_helper.dartindex b016fb32..a9b45fbe 100644--- a/app/lib/util/native/taskbar_helper.dart+++ b/app/lib/util/native/taskbar_helper.dart@@ -9,8 +9,10 @@ enum TaskbarIcon { regular, error, success }class TaskbarHelper {static final _isWindows = checkPlatform([TargetPlatform.windows]);static final _isMacos = checkPlatform([TargetPlatform.macOS]);+ static int? _lastProgressPercent;static Future<void> clearProgressBar() async {+ _lastProgressPercent = null;if (_isWindows) {await WindowsTaskbar.setProgressMode(TaskbarProgressMode.noProgress);} else if (_isMacos) {@@ -21,14 +23,24 @@ class TaskbarHelper {static Future<void> setProgressBar(int progress, int total) async {// Scale down to 0-100 range because Windows Taskbar only supports 32-bit integers// This ensures that files with a size of 2^32 bytes or greater can still be displayed correctly- final (digestedProgress, digestedTotal) = _scaleRange(progress, total);- if (total != double.minPositive.toInt() && total != double.maxFinite.toInt()) {- if (_isWindows) {- await WindowsTaskbar.setProgress(digestedProgress, digestedTotal);- } else if (_isMacos) {- await updateDockProgress(progress / total);+ if (total > 0 && total != double.maxFinite.toInt()) {+ final (digestedProgress, digestedTotal) = _scaleRange(progress, total);+ if (_lastProgressPercent == digestedProgress) {+ return;+ }+ _lastProgressPercent = digestedProgress;+ try {+ if (_isWindows) {+ await WindowsTaskbar.setProgress(digestedProgress, digestedTotal);+ } else if (_isMacos) {+ await updateDockProgress(digestedProgress / digestedTotal);+ }+ } catch (_) {+ _lastProgressPercent = null;+ rethrow;}} else {+ _lastProgressPercent = null;if (_isWindows) {await WindowsTaskbar.setProgressMode(TaskbarProgressMode.indeterminate);}@@ -36,6 +48,7 @@ class TaskbarHelper {}static Future<void> setProgressBarMode(int mode) async {+ _lastProgressPercent = null;if (_isWindows) {await WindowsTaskbar.setProgressMode(mode);}