Add burst sync and 10s auto sync option
This commit is contained in:
@@ -153,7 +153,9 @@ class _PeyaAppState extends ConsumerState<PeyaApp> {
|
||||
);
|
||||
if (!connected) {
|
||||
ref.read(loggerProvider).w('Failed to connect node after retries.');
|
||||
return;
|
||||
}
|
||||
_scheduleBurstSync();
|
||||
}
|
||||
|
||||
Future<bool> _connectAndSyncWithRetry(
|
||||
@@ -182,6 +184,15 @@ class _PeyaAppState extends ConsumerState<PeyaApp> {
|
||||
return false;
|
||||
}
|
||||
|
||||
void _scheduleBurstSync() {
|
||||
unawaited(
|
||||
ref.read(syncSchedulerProvider).burstSync(
|
||||
count: 4,
|
||||
interval: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _applyStartMinimized(AppConfig config) async {
|
||||
if (_didApplyStartMinimized) {
|
||||
return;
|
||||
|
||||
@@ -302,7 +302,7 @@ class AppConfig {
|
||||
minimizeToTray: false,
|
||||
startMinimized: false,
|
||||
autoSync: true,
|
||||
autoSyncInterval: const Duration(minutes: 1),
|
||||
autoSyncInterval: const Duration(seconds: 10),
|
||||
languagePreference: LanguagePreference.system,
|
||||
hiddenSubaddresses: const {},
|
||||
localNodeArgs: const [],
|
||||
@@ -365,7 +365,7 @@ class AppConfig {
|
||||
startMinimized: json['startMinimized'] as bool? ?? false,
|
||||
autoSync: json['autoSync'] as bool? ?? true,
|
||||
autoSyncInterval: Duration(
|
||||
seconds: json['autoSyncIntervalSeconds'] as int? ?? 60,
|
||||
seconds: json['autoSyncIntervalSeconds'] as int? ?? 10,
|
||||
),
|
||||
languagePreference: LanguagePreference.values.firstWhere(
|
||||
(value) =>
|
||||
|
||||
@@ -363,6 +363,7 @@
|
||||
"syncSettingsTitle": "Auto sync",
|
||||
"autoSyncLabel": "Auto sync",
|
||||
"autoSyncIntervalLabel": "Interval",
|
||||
"interval10s": "10 seconds",
|
||||
"interval30s": "30 seconds",
|
||||
"interval1m": "1 minute",
|
||||
"interval5m": "5 minutes",
|
||||
|
||||
@@ -1772,6 +1772,12 @@ abstract class AppLocalizations {
|
||||
/// **'Interval'**
|
||||
String get autoSyncIntervalLabel;
|
||||
|
||||
/// No description provided for @interval10s.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'10 seconds'**
|
||||
String get interval10s;
|
||||
|
||||
/// No description provided for @interval30s.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -890,6 +890,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get autoSyncIntervalLabel => 'Interval';
|
||||
|
||||
@override
|
||||
String get interval10s => '10 seconds';
|
||||
|
||||
@override
|
||||
String get interval30s => '30 seconds';
|
||||
|
||||
|
||||
@@ -894,6 +894,9 @@ class AppLocalizationsPl extends AppLocalizations {
|
||||
@override
|
||||
String get autoSyncIntervalLabel => 'Interwał';
|
||||
|
||||
@override
|
||||
String get interval10s => '10 sekund';
|
||||
|
||||
@override
|
||||
String get interval30s => '30 sekund';
|
||||
|
||||
|
||||
@@ -363,6 +363,7 @@
|
||||
"syncSettingsTitle": "Auto sync",
|
||||
"autoSyncLabel": "Auto sync",
|
||||
"autoSyncIntervalLabel": "Interwał",
|
||||
"interval10s": "10 sekund",
|
||||
"interval30s": "30 sekund",
|
||||
"interval1m": "1 minuta",
|
||||
"interval5m": "5 minut",
|
||||
|
||||
@@ -35,6 +35,18 @@ class SyncScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> burstSync({
|
||||
int count = 4,
|
||||
Duration interval = const Duration(seconds: 2),
|
||||
}) async {
|
||||
for (var i = 0; i < count; i++) {
|
||||
await triggerSync();
|
||||
if (i + 1 < count) {
|
||||
await Future.delayed(interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||
@@ -168,6 +170,7 @@ class SettingsScreen extends ConsumerWidget {
|
||||
}
|
||||
},
|
||||
items: const [
|
||||
Duration(seconds: 10),
|
||||
Duration(seconds: 30),
|
||||
Duration(minutes: 1),
|
||||
Duration(minutes: 5),
|
||||
@@ -210,6 +213,9 @@ class SettingsScreen extends ConsumerWidget {
|
||||
|
||||
static String _intervalLabel(BuildContext context, Duration duration) {
|
||||
final l10n = context.l10n;
|
||||
if (duration.inSeconds == 10) {
|
||||
return l10n.interval10s;
|
||||
}
|
||||
if (duration.inSeconds == 30) {
|
||||
return l10n.interval30s;
|
||||
}
|
||||
@@ -224,12 +230,13 @@ class SettingsScreen extends ConsumerWidget {
|
||||
|
||||
static Duration _resolveInterval(Duration value) {
|
||||
const options = [
|
||||
Duration(seconds: 10),
|
||||
Duration(seconds: 30),
|
||||
Duration(minutes: 1),
|
||||
Duration(minutes: 5),
|
||||
Duration(minutes: 15),
|
||||
];
|
||||
return options.firstWhere((option) => option == value, orElse: () => options[1]);
|
||||
return options.firstWhere((option) => option == value, orElse: () => options[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,6 +417,12 @@ class _LocalNodeControlsState extends ConsumerState<_LocalNodeControls> {
|
||||
}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
unawaited(
|
||||
ref.read(syncSchedulerProvider).burstSync(
|
||||
count: 4,
|
||||
interval: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ok;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user