2024-07-24 01:27:49 +08:00
|
|
|
import 'package:fl_clash/clash/clash.dart';
|
2024-09-05 08:59:45 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
2024-07-24 01:27:49 +08:00
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
|
|
|
|
import 'package:fl_clash/models/models.dart';
|
|
|
|
|
import 'package:fl_clash/state.dart';
|
|
|
|
|
|
|
|
|
|
double get listHeaderHeight {
|
2024-09-05 08:59:45 +08:00
|
|
|
final measure = globalState.measure;
|
2025-04-18 17:50:46 +08:00
|
|
|
return 28 + measure.titleMediumHeight + 4 + measure.bodyMediumHeight;
|
2024-07-24 01:27:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getItemHeight(ProxyCardType proxyCardType) {
|
2024-09-05 08:59:45 +08:00
|
|
|
final measure = globalState.measure;
|
2024-07-24 01:27:49 +08:00
|
|
|
final baseHeight =
|
2025-02-09 18:39:38 +08:00
|
|
|
16 + measure.bodyMediumHeight * 2 + measure.bodySmallHeight + 8 + 4;
|
2024-07-24 01:27:49 +08:00
|
|
|
return switch (proxyCardType) {
|
2025-02-09 18:39:38 +08:00
|
|
|
ProxyCardType.expand => baseHeight + measure.labelSmallHeight + 6,
|
2024-07-24 01:27:49 +08:00
|
|
|
ProxyCardType.shrink => baseHeight,
|
|
|
|
|
ProxyCardType.min => baseHeight - measure.bodyMediumHeight,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 19:08:17 +08:00
|
|
|
proxyDelayTest(Proxy proxy, [String? testUrl]) async {
|
2024-09-08 21:21:21 +08:00
|
|
|
final appController = globalState.appController;
|
2025-03-05 16:08:50 +08:00
|
|
|
final state = appController.getProxyCardState(proxy.name);
|
|
|
|
|
final url = state.testUrl.getSafeValue(
|
|
|
|
|
appController.getRealTestUrl(testUrl),
|
|
|
|
|
);
|
2025-03-08 04:36:40 +08:00
|
|
|
if (state.proxyName.isEmpty) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setDelay(
|
2024-09-08 21:21:21 +08:00
|
|
|
Delay(
|
2025-01-13 19:08:17 +08:00
|
|
|
url: url,
|
2025-03-05 16:08:50 +08:00
|
|
|
name: state.proxyName,
|
2024-09-08 21:21:21 +08:00
|
|
|
value: 0,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setDelay(
|
2025-01-13 19:08:17 +08:00
|
|
|
await clashCore.getDelay(
|
|
|
|
|
url,
|
2025-03-05 16:08:50 +08:00
|
|
|
state.proxyName,
|
2025-01-13 19:08:17 +08:00
|
|
|
),
|
|
|
|
|
);
|
2024-09-08 21:21:21 +08:00
|
|
|
}
|
|
|
|
|
|
2025-01-13 19:08:17 +08:00
|
|
|
delayTest(List<Proxy> proxies, [String? testUrl]) async {
|
2024-07-24 01:27:49 +08:00
|
|
|
final appController = globalState.appController;
|
2025-03-05 16:08:50 +08:00
|
|
|
final proxyNames = proxies.map((proxy) => proxy.name).toSet().toList();
|
2025-01-13 19:08:17 +08:00
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
final delayProxies = proxyNames.map<Future>((proxyName) async {
|
2025-03-05 16:08:50 +08:00
|
|
|
final state = appController.getProxyCardState(proxyName);
|
|
|
|
|
final url = state.testUrl.getSafeValue(
|
|
|
|
|
appController.getRealTestUrl(testUrl),
|
|
|
|
|
);
|
|
|
|
|
final name = state.proxyName;
|
2025-03-08 04:36:40 +08:00
|
|
|
if (name.isEmpty) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setDelay(
|
2024-07-24 01:27:49 +08:00
|
|
|
Delay(
|
2025-01-13 19:08:17 +08:00
|
|
|
url: url,
|
2025-03-05 16:08:50 +08:00
|
|
|
name: name,
|
2024-07-24 01:27:49 +08:00
|
|
|
value: 0,
|
|
|
|
|
),
|
|
|
|
|
);
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.setDelay(
|
2025-01-13 19:08:17 +08:00
|
|
|
await clashCore.getDelay(
|
|
|
|
|
url,
|
2025-03-05 16:08:50 +08:00
|
|
|
name,
|
2025-01-13 19:08:17 +08:00
|
|
|
),
|
|
|
|
|
);
|
2024-09-05 08:59:45 +08:00
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
final batchesDelayProxies = delayProxies.batch(100);
|
|
|
|
|
for (final batchDelayProxies in batchesDelayProxies) {
|
|
|
|
|
await Future.wait(batchDelayProxies);
|
|
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
appController.addSortNum();
|
2024-07-24 01:27:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getScrollToSelectedOffset({
|
|
|
|
|
required String groupName,
|
|
|
|
|
required List<Proxy> proxies,
|
|
|
|
|
}) {
|
|
|
|
|
final appController = globalState.appController;
|
2025-02-09 18:39:38 +08:00
|
|
|
final columns = appController.getProxiesColumns();
|
|
|
|
|
final proxyCardType = globalState.config.proxiesStyle.cardType;
|
|
|
|
|
final selectedProxyName = appController.getSelectedProxyName(groupName);
|
2024-07-24 01:27:49 +08:00
|
|
|
final findSelectedIndex = proxies.indexWhere(
|
2025-02-09 18:39:38 +08:00
|
|
|
(proxy) => proxy.name == selectedProxyName,
|
2024-07-24 01:27:49 +08:00
|
|
|
);
|
|
|
|
|
final selectedIndex = findSelectedIndex != -1 ? findSelectedIndex : 0;
|
2024-07-26 08:05:22 +08:00
|
|
|
final rows = (selectedIndex / columns).floor();
|
2024-09-08 21:21:21 +08:00
|
|
|
return rows * getItemHeight(proxyCardType) + (rows - 1) * 8;
|
2024-07-24 01:27:49 +08:00
|
|
|
}
|