Fix ChangeProfile block

This commit is contained in:
chen08209
2024-05-04 16:39:21 +08:00
parent aef50fe0e3
commit 89e6f17794
3 changed files with 37 additions and 23 deletions

View File

@@ -123,12 +123,18 @@ class AppController {
);
}
applyProfile() {
globalState.applyProfile(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
changeProfile(String? value) async {
if (value == config.currentProfileId) return;
config.currentProfileId = value;
await updateClashConfig(isPatch: false);
await updateGroups();
changeProxy();
await applyProfile();
appState.delayMap = {};
saveConfigPreferences();
}
@@ -142,10 +148,7 @@ class AppController {
)
.isBeforeNow();
if (isNotNeedUpdate == false) continue;
final result = await profile.update();
if (result.type == ResultType.error) continue;
await updateGroups();
changeProxy();
await profile.update();
}
}

View File

@@ -5,7 +5,6 @@ import 'dart:io';
import 'package:animations/animations.dart';
import 'package:fl_clash/clash/clash.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/models/clash_config.dart';
import 'package:fl_clash/plugins/app.dart';
import 'package:fl_clash/widgets/scaffold.dart';
import 'package:flutter/material.dart';
@@ -88,6 +87,24 @@ class GlobalState {
updateCurrentDelayDebounce!([proxyName]);
}
applyProfile({
required AppState appState,
required Config config,
required ClashConfig clashConfig,
}) async {
await updateClashConfig(
clashConfig: clashConfig,
config: config,
isPatch: false,
);
await updateGroups(appState);
changeProxy(
appState: appState,
config: config,
clashConfig: clashConfig,
);
}
init({
required AppState appState,
required Config config,
@@ -101,18 +118,12 @@ class GlobalState {
);
}
if (!appState.isInit) return;
await updateClashConfig(
clashConfig: clashConfig,
config: config,
isPatch: false,
);
updateGroups(appState);
updateCoreVersionInfo(appState);
changeProxy(
await applyProfile(
appState: appState,
config: config,
clashConfig: clashConfig,
);
updateCoreVersionInfo(appState);
}
changeProxy({
@@ -167,7 +178,7 @@ class GlobalState {
}
Future<void> updateGroups(AppState appState) async {
appState.groups = await clashCore.getProxiesGroups();
appState.groups = await clashCore.getProxiesGroups();
}
showMessage({