d3fa2252b0
Changelog: Launcher shortcuts and one-step on-demand access
52 lines
1.4 KiB
Dart
52 lines
1.4 KiB
Dart
import 'package:fl_clash/common/common.dart';
|
|
import 'package:fl_clash/enum/enum.dart';
|
|
import 'package:fl_clash/models/models.dart';
|
|
import 'package:fl_clash/providers/action.dart';
|
|
import 'package:fl_clash/providers/app.dart';
|
|
import 'package:fl_clash/providers/state.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class VpnManager extends ConsumerStatefulWidget {
|
|
final Widget child;
|
|
|
|
const VpnManager({super.key, required this.child});
|
|
|
|
@override
|
|
ConsumerState<VpnManager> createState() => _VpnContainerState();
|
|
}
|
|
|
|
class _VpnContainerState extends ConsumerState<VpnManager> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
ref.listenManual(vpnOptionsProvider.select((state) => state.effective), (
|
|
prev,
|
|
next,
|
|
) {
|
|
final running = ref.read(runningVpnOptionsProvider)?.effective;
|
|
if (prev != next && running != null && running != next) {
|
|
_showRestartTip();
|
|
}
|
|
});
|
|
}
|
|
|
|
void _showRestartTip() {
|
|
dialogs.showNotifier(
|
|
currentAppLocalizations.vpnConfigChangeDetected,
|
|
level: MessageLevel.warning,
|
|
actionState: MessageActionState(
|
|
actionText: currentAppLocalizations.restart,
|
|
action: () async {
|
|
await ref.read(setupActionProvider.notifier).restartVpn();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return widget.child;
|
|
}
|
|
}
|