Add reconnect alert for config options
This commit is contained in:
@@ -2,6 +2,8 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hiddify/features/config_option/data/config_option_repository.dart';
|
||||
import 'package:hiddify/features/connection/data/connection_data_providers.dart';
|
||||
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
|
||||
import 'package:hiddify/utils/custom_loggers.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -10,7 +12,29 @@ part 'config_option_notifier.g.dart';
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConfigOptionNotifier extends _$ConfigOptionNotifier with AppLogger {
|
||||
@override
|
||||
Future<void> build() async {}
|
||||
Future<bool> build() async {
|
||||
final serviceRunning = await ref.watch(serviceRunningProvider.future);
|
||||
final serviceSingboxOptions =
|
||||
ref.read(connectionRepositoryProvider).configOptionsSnapshot;
|
||||
ref.listen(
|
||||
ConfigOptions.singboxConfigOptions,
|
||||
(previous, next) async {
|
||||
if (!serviceRunning || serviceSingboxOptions == null) return;
|
||||
if (next case AsyncData(:final value) when next != previous) {
|
||||
if (_lastUpdate == null ||
|
||||
DateTime.now().difference(_lastUpdate!) >
|
||||
const Duration(seconds: 3)) {
|
||||
_lastUpdate = DateTime.now();
|
||||
state = AsyncData(value != serviceSingboxOptions);
|
||||
}
|
||||
}
|
||||
},
|
||||
fireImmediately: true,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
DateTime? _lastUpdate;
|
||||
|
||||
Future<void> exportJsonToClipboard() async {
|
||||
final map = {
|
||||
|
||||
Reference in New Issue
Block a user