2024-12-09 01:40:39 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2025-10-14 15:13:52 +08:00
|
|
|
import 'package:fl_clash/models/models.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:fl_clash/providers/state.dart';
|
2024-08-26 20:44:30 +08:00
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2025-02-09 18:39:38 +08:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-08-26 20:44:30 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class VpnManager extends ConsumerStatefulWidget {
|
2024-08-26 20:44:30 +08:00
|
|
|
final Widget child;
|
|
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
const VpnManager({super.key, required this.child});
|
2024-08-26 20:44:30 +08:00
|
|
|
|
|
|
|
|
@override
|
2025-02-09 18:39:38 +08:00
|
|
|
ConsumerState<VpnManager> createState() => _VpnContainerState();
|
2024-08-26 20:44:30 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
class _VpnContainerState extends ConsumerState<VpnManager> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
ref.listenManual(vpnStateProvider, (prev, next) {
|
2025-10-14 15:13:52 +08:00
|
|
|
if (prev != next) {
|
|
|
|
|
showTip(next);
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-14 15:13:52 +08:00
|
|
|
void showTip(VpnState state) {
|
2025-07-31 17:09:18 +08:00
|
|
|
throttler.call(
|
2025-05-02 02:24:12 +08:00
|
|
|
FunctionTag.vpnTip,
|
2024-12-09 01:40:39 +08:00
|
|
|
() {
|
2025-10-14 15:13:52 +08:00
|
|
|
if (!ref.read(isStartProvider) || state == globalState.lastVpnState) {
|
|
|
|
|
return;
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
2025-10-14 15:13:52 +08:00
|
|
|
globalState.showNotifier(
|
|
|
|
|
appLocalizations.vpnConfigChangeDetected,
|
|
|
|
|
actionState: MessageActionState(
|
|
|
|
|
actionText: appLocalizations.restart,
|
|
|
|
|
action: () async {
|
|
|
|
|
await globalState.handleStop();
|
|
|
|
|
await globalState.appController.updateStatus(true);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-12-09 01:40:39 +08:00
|
|
|
},
|
2025-07-31 17:09:18 +08:00
|
|
|
duration: const Duration(seconds: 6),
|
|
|
|
|
fire: true,
|
2024-12-09 01:40:39 +08:00
|
|
|
);
|
2024-08-26 20:44:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-02-09 18:39:38 +08:00
|
|
|
return widget.child;
|
2024-08-26 20:44:30 +08:00
|
|
|
}
|
|
|
|
|
}
|