mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
8edccb8a0f
clean up async handling improve styled alerts
51 lines
1.1 KiB
Dart
51 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:async_tools/async_tools.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
import 'veilid_processor/veilid_processor.dart';
|
|
|
|
class BackgroundTicker extends StatefulWidget {
|
|
const BackgroundTicker({required this.child, super.key});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
BackgroundTickerState createState() => BackgroundTickerState();
|
|
}
|
|
|
|
class BackgroundTickerState extends State<BackgroundTicker> {
|
|
Timer? _tickTimer;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tickTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
|
singleFuture(this, _onTick);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tickTimer?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
// ignore: prefer_expression_function_bodies
|
|
Widget build(BuildContext context) {
|
|
return widget.child;
|
|
}
|
|
|
|
Future<void> _onTick() async {
|
|
if (!ProcessorRepository
|
|
.instance.processorConnectionState.isPublicInternetReady) {
|
|
return;
|
|
}
|
|
|
|
// Tick DHT record pool
|
|
await DHTRecordPool.instance.tick();
|
|
}
|
|
}
|