Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Add option to make debouncer leading or trailing

ashilknbe5a29b6de21
diff --git a/mobile/lib/utils/debouncer.dart b/mobile/lib/utils/debouncer.dart
index 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 seconds
final 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