2024-07-08 17:34:14 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/models/models.dart';
|
2024-05-11 17:02:34 +08:00
|
|
|
import 'package:fl_clash/state.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-07-08 17:34:14 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
|
|
|
|
|
class WindowContainer extends StatefulWidget {
|
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
const WindowContainer({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.child,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<WindowContainer> createState() => _WindowContainerState();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 17:34:14 +08:00
|
|
|
class _WindowContainerState extends State<WindowContainer> with WindowListener {
|
|
|
|
|
|
|
|
|
|
_autoLaunchContainer(Widget child) {
|
|
|
|
|
return Selector<Config, bool>(
|
|
|
|
|
selector: (_, config) => config.autoLaunch,
|
|
|
|
|
builder: (_, isAutoLaunch, child) {
|
|
|
|
|
autoLaunch?.updateStatus(isAutoLaunch);
|
|
|
|
|
return child!;
|
|
|
|
|
},
|
|
|
|
|
child: child,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-07-08 17:34:14 +08:00
|
|
|
return _autoLaunchContainer(widget.child);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
windowManager.addListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onWindowClose() async {
|
2024-05-11 17:02:34 +08:00
|
|
|
await globalState.appController.handleBackOrExit();
|
2024-04-30 23:38:49 +08:00
|
|
|
super.onWindowClose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onWindowMinimize() async {
|
2024-05-11 17:02:34 +08:00
|
|
|
await globalState.appController.savePreferences();
|
2024-04-30 23:38:49 +08:00
|
|
|
super.onWindowMinimize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> dispose() async {
|
|
|
|
|
windowManager.removeListener(this);
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|