|
|
@@ -417,39 +417,40 @@ class DataNotifier extends StateNotifier<DataState> {
|
|
|
RealtimeChannel? realtimeCsvupdates;
|
|
|
Timer? _timer;
|
|
|
|
|
|
- final timerretrymin = Duration(minutes: 1);
|
|
|
- final timerretrymax = Duration(minutes: 5);
|
|
|
-
|
|
|
- _resetTimer(Duration dur) {
|
|
|
- print(
|
|
|
- "data: datastate: resettimer: timer reseteed ${dur.inMinutes}min ${Jiffy.now().Hms}");
|
|
|
- _timer?.cancel();
|
|
|
- // _timer = Timer.periodic(dur, (timer) async {
|
|
|
- // print("data: datastate: timer: activated ${Jiffy.now().Hms}");
|
|
|
- // await downloadModifiedFiles();
|
|
|
- // });
|
|
|
+ _startTimer() {
|
|
|
+ _timer = Timer.periodic(Duration(seconds: 60), (timer) async {
|
|
|
+ // print("data: datastate: timer: activated ${Jiffy.now().Hms}");
|
|
|
+ if (Jiffy.now().dateTime.difference(lastupdate.dateTime).inSeconds >
|
|
|
+ (5 * 60)) {
|
|
|
+ print(
|
|
|
+ "data: datanotifier: last update ${Jiffy.now().dateTime.difference(lastupdate.dateTime).inMinutes} minutes, trying download");
|
|
|
+ await downloadModifiedFiles();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ Jiffy get lastupdate => pnleg3time
|
|
|
+ .max(pnlegmoistime ?? Jiffy.now().subtract(years: 1))
|
|
|
+ .max(aclegtime ?? Jiffy.now().subtract(years: 1));
|
|
|
+
|
|
|
DataNotifier() : super(DataState()) {
|
|
|
Future.delayed(Duration.zero).then((x) async {
|
|
|
await loadAll();
|
|
|
- await downloadModifiedFiles();
|
|
|
-
|
|
|
+ // await downloadModifiedFiles();
|
|
|
+ _startTimer();
|
|
|
final csvhich = Supabase.instance.client.channel('csvhichstorage');
|
|
|
-
|
|
|
- csvhich
|
|
|
- .onBroadcast(
|
|
|
- event: 'upload',
|
|
|
- callback: (payload) async {
|
|
|
- final pay = payload; //["payload"] ?? payload;
|
|
|
- print("data: datanotifier: realtime: $pay");
|
|
|
- if (pay is Map && pay.keys.contains("filename")) {
|
|
|
- await downloadFile(pay["filename"] ?? "unknown.file");
|
|
|
- }
|
|
|
- })
|
|
|
- .subscribe((st, ob) {
|
|
|
+ csvhich.subscribe((st, ob) {
|
|
|
print("Data: datanotifier: Subscription status: $st | object: $ob");
|
|
|
});
|
|
|
+ csvhich.onBroadcast(
|
|
|
+ event: 'upload',
|
|
|
+ callback: (payload) async {
|
|
|
+ final pay = payload; //["payload"] ?? payload;
|
|
|
+ print("data: datanotifier: realtime: $pay");
|
|
|
+ if (pay is Map && pay.keys.contains("filename")) {
|
|
|
+ await downloadFile(pay["filename"] ?? "unknown.file");
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -472,9 +473,6 @@ class DataNotifier extends StateNotifier<DataState> {
|
|
|
print('data: downloadfile: Downloaded file: $fileName');
|
|
|
await localFile.copy(PathTo().csvFile(fileName));
|
|
|
await loadAll();
|
|
|
- _resetTimer(timerretrymax);
|
|
|
- } else {
|
|
|
- _resetTimer(timerretrymin);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -489,7 +487,6 @@ class DataNotifier extends StateNotifier<DataState> {
|
|
|
if (!await directory.exists()) {
|
|
|
await directory.create(recursive: true);
|
|
|
}
|
|
|
- Duration timerdur = timerretrymin;
|
|
|
try {
|
|
|
// List files in the "csv" bucket
|
|
|
final filelist = await supabaseClient.storage.from('csv').list();
|
|
|
@@ -517,7 +514,6 @@ class DataNotifier extends StateNotifier<DataState> {
|
|
|
print(
|
|
|
'data: downloadmodified file: Downloaded modified file: $fileName');
|
|
|
await localFile.copy(PathTo().csvFile(fileName));
|
|
|
- timerdur = timerretrymax;
|
|
|
await loadAll();
|
|
|
} else {
|
|
|
print('Failed to download file: $fileName');
|
|
|
@@ -529,8 +525,6 @@ class DataNotifier extends StateNotifier<DataState> {
|
|
|
} catch (e) {
|
|
|
print(
|
|
|
"data: downloadmodified files: unable to list files on supabase bucket");
|
|
|
- } finally {
|
|
|
- _resetTimer(timerdur);
|
|
|
}
|
|
|
}
|
|
|
|