2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/clash/clash.dart';
|
|
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/models/models.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:fl_clash/plugins/app.dart';
|
|
|
|
|
|
|
|
|
|
class ClashMessageContainer extends StatefulWidget {
|
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
const ClashMessageContainer({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.child,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<ClashMessageContainer> createState() => _ClashMessageContainerState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _ClashMessageContainerState extends State<ClashMessageContainer>
|
|
|
|
|
with ClashMessageListener {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return widget.child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
clashMessage.addListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> dispose() async {
|
|
|
|
|
clashMessage.removeListener(this);
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onDelay(Delay delay) {
|
2024-05-11 17:02:34 +08:00
|
|
|
final appController = globalState.appController;
|
2024-05-06 19:03:49 +08:00
|
|
|
appController.setDelay(delay);
|
2024-04-30 23:38:49 +08:00
|
|
|
super.onDelay(delay);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onLog(Log log) {
|
2024-05-11 17:02:34 +08:00
|
|
|
globalState.appController.appState.addLog(log);
|
2024-04-30 23:38:49 +08:00
|
|
|
super.onLog(log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2024-07-02 08:08:31 +08:00
|
|
|
Future<void> onTun(Fd fd) async {
|
|
|
|
|
await proxyManager.setProtect(fd.value);
|
|
|
|
|
clashCore.setFdMap(fd.id);
|
2024-04-30 23:38:49 +08:00
|
|
|
super.onTun(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2024-06-13 23:43:42 +08:00
|
|
|
void onProcess(Process process) async {
|
|
|
|
|
var packageName = await app?.resolverProcess(process);
|
|
|
|
|
clashCore.setProcessMap(
|
|
|
|
|
ProcessMapItem(
|
|
|
|
|
id: process.id,
|
2024-06-16 19:04:33 +08:00
|
|
|
value: packageName ?? "",
|
2024-06-13 23:43:42 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
super.onProcess(process);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onRequest(Connection connection) async {
|
|
|
|
|
globalState.appController.appState.addRequest(connection);
|
|
|
|
|
super.onRequest(connection);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
2024-07-02 08:08:31 +08:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void onLoaded(String groupName) {
|
|
|
|
|
final appController = globalState.appController;
|
|
|
|
|
final currentSelectedMap = appController.config.currentSelectedMap;
|
|
|
|
|
final proxyName = currentSelectedMap[groupName];
|
|
|
|
|
if (proxyName == null) return;
|
|
|
|
|
clashCore.changeProxy(
|
|
|
|
|
ChangeProxyParams(
|
|
|
|
|
groupName: groupName,
|
|
|
|
|
proxyName: proxyName,
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-07-07 10:02:10 +08:00
|
|
|
appController.addCheckIpNumDebounce();
|
2024-07-02 08:08:31 +08:00
|
|
|
super.onLoaded(proxyName);
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|