Files
umbrix/lib/features/connection/widget/connection_wrapper.dart

58 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2024-03-03 14:03:36 +03:30
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/notification/in_app_notification_controller.dart';
import 'package:hiddify/features/config_option/notifier/config_option_notifier.dart';
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
2024-03-03 14:03:36 +03:30
import 'package:hiddify/features/profile/notifier/active_profile_notifier.dart';
import 'package:hiddify/utils/custom_loggers.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ConnectionWrapper extends StatefulHookConsumerWidget {
const ConnectionWrapper(this.child, {super.key});
final Widget child;
@override
2024-07-14 10:17:46 +02:00
ConsumerState<ConsumerStatefulWidget> createState() => _ConnectionWrapperState();
}
2024-07-14 10:17:46 +02:00
class _ConnectionWrapperState extends ConsumerState<ConnectionWrapper> with AppLogger {
@override
Widget build(BuildContext context) {
ref.listen(connectionNotifierProvider, (_, __) {});
ref.listen(configOptionNotifierProvider, (previous, next) async {
2024-03-03 14:03:36 +03:30
if (next case AsyncData(value: true)) {
final t = ref.read(translationsProvider);
2024-07-14 10:17:46 +02:00
ref.watch(inAppNotificationControllerProvider).showInfoToast(
t.connection.reconnectMsg,
// actionText: t.connection.reconnect,
// callback: () async {
// await ref
// .read(connectionNotifierProvider.notifier)
// .reconnect(await ref.read(activeProfileProvider.future));
// },
);
await ref.read(connectionNotifierProvider.notifier).reconnect(await ref.read(activeProfileProvider.future));
2024-03-03 14:03:36 +03:30
}
});
return widget.child;
}
@override
void initState() {
super.initState();
2023-12-31 10:32:05 +03:30
// remove for now...
//
// Future.delayed(const Duration(seconds: 2)).then(
// (_) async {
// if (ref.read(startedByUserProvider) && PlatformUtils.isDesktop) {
// loggy.debug("previously started by user, trying to connect");
// return ref.read(connectionNotifierProvider.notifier).mayConnect();
// }
// },
// );
}
}