π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Add option to make debouncer leading or trailing
ashilknbe5a29b6de21
diff --git a/mobile/lib/utils/debouncer.dart b/mobile/lib/utils/debouncer.dartindex 31e9709521..07097440f0 100644--- a/mobile/lib/utils/debouncer.dart+++ b/mobile/lib/utils/debouncer.dart@@ -15,12 +15,24 @@ class Debouncer {/// This is useful for example when you want to execute a callback every 5 secondsfinal Duration? executionInterval;Timer? _debounceTimer;+ final bool leading;- Debouncer(this._duration, {this.executionInterval});+ Debouncer(this._duration, {this.executionInterval, this.leading = false});final Stopwatch _stopwatch = Stopwatch();void run(FutureVoidCallback fn) {+ if (leading && !isActive()) {+ _stopwatch.stop();+ _stopwatch.reset();+ fn();+ _debounceTimer = Timer(_duration, () {+ _debounceActiveNotifier.value = false;+ });+ _debounceActiveNotifier.value = true;+ return;+ }+bool shouldRunImmediately = false;if (executionInterval != null) {// ensure the stop watch is running