Compare commits

..

1 Commits

Author SHA1 Message Date
chen08209
79ce7cadf6 Add sqlite store
Optimize android quick action

Optimize backup and restore

Optimize more details
2026-01-24 12:14:54 +08:00
19 changed files with 82 additions and 144 deletions

View File

@@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--dart-define-from-file env.json" />
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
<method v="2" />
</configuration>
</component>

10
Makefile Normal file
View File

@@ -0,0 +1,10 @@
android_arm64:
dart ./setup.dart android --arch arm64
macos_arm64:
dart ./setup.dart macos --arch arm64
android_app:
dart ./setup.dart android
android_arm64_core:
dart ./setup.dart android --arch arm64 --out core
macos_arm64_core:
dart ./setup.dart macos --arch arm64 --out core

View File

@@ -99,47 +99,27 @@ func handleValidateConfig(path string) string {
func handleGetProxies() ProxiesData {
runLock.Lock()
defer runLock.Unlock()
nameList := config.GetProxyNameList()
var all = []string{"GLOBAL"}
all = append(all, config.ProxyList...)
proxies := make(map[string]constant.Proxy)
for name, proxy := range tunnel.Proxies() {
proxies[name] = proxy
}
for _, p := range tunnel.Providers() {
for _, proxy := range p.Proxies() {
proxies[proxy.Name()] = proxy
name := proxy.Name()
proxies[name] = proxy
}
}
hasGlobal := false
allNames := make([]string, 0, len(nameList)+1)
for _, name := range nameList {
if name == "GLOBAL" {
hasGlobal = true
}
p, ok := proxies[name]
if !ok || p == nil {
continue
}
switch p.Type() {
case constant.Selector, constant.URLTest, constant.Fallback, constant.Relay, constant.LoadBalance:
allNames = append(allNames, name)
default:
}
types := []constant.AdapterType{
constant.Selector, constant.URLTest, constant.Fallback, constant.Relay, constant.LoadBalance,
}
if !hasGlobal {
if p, ok := proxies["GLOBAL"]; ok && p != nil {
allNames = append([]string{"GLOBAL"}, allNames...)
}
}
nextAll := slices.DeleteFunc(all, func(name string) bool {
return !slices.Contains(types, proxies[name].Type())
})
return ProxiesData{
All: allNames,
All: nextAll,
Proxies: proxies,
}
}

View File

@@ -20,16 +20,7 @@ class Migration {
}) async {
_oldVersion = await preferences.getVersion();
if (_oldVersion == currentVersion) {
try {
return Config.realFromJson(configMap);
} catch (_) {
final isV0 = configMap?['proxiesStyle'] != null;
if (isV0) {
_oldVersion = 0;
} else {
throw 'Local data is damaged. A reset is required to fix this issue.';
}
}
return Config.realFromJson(configMap);
}
MigrationData data = MigrationData(configMap: configMap);
if (_oldVersion == 0 && configMap != null) {

View File

@@ -576,14 +576,14 @@ Future<MigrationData> _restoreTask(RootIsolateToken token) async {
final scripts = results[1].cast<Script>();
final profilesMigration = profiles.map(
(item) => VM2(
_getProfilePath(restoreDirPath, item.id.toString()),
_getProfilePath(homeDirPath, item.id.toString()),
_getProfilePath(restoreDirPath, item.fileName),
_getProfilePath(homeDirPath, item.fileName),
),
);
final scriptsMigration = scripts.map(
(item) => VM2(
_getScriptPath(restoreDirPath, item.id.toString()),
_getScriptPath(homeDirPath, item.id.toString()),
_getScriptPath(restoreDirPath, item.fileName),
_getScriptPath(homeDirPath, item.fileName),
),
);
await _copyWithMapList([...profilesMigration, ...scriptsMigration]);

View File

@@ -7,6 +7,7 @@ import 'package:fl_clash/plugins/app.dart';
import 'package:fl_clash/providers/providers.dart';
import 'package:fl_clash/state.dart';
import 'package:fl_clash/widgets/dialog.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -550,20 +551,18 @@ extension SetupControllerExt on AppController {
Future<void> updateStatus(bool isStart, {bool isInit = false}) async {
if (isStart) {
_ref.read(runTimeProvider.notifier).update((state) {
return state ?? 0;
});
final res = await tryStartCore(true);
if (res) {
return;
}
if (!isInit) {
final res = await tryStartCore(true);
if (res) {
return;
}
if (!_ref.read(initProvider)) {
return;
}
await globalState.handleStart([updateRunTime, updateTraffic]);
applyProfileDebounce(force: true, silence: true);
} else {
_ref.read(runTimeProvider.notifier).value = 0;
await applyProfile(
force: true,
preloadInvoke: () async {
@@ -611,18 +610,6 @@ extension SetupControllerExt on AppController {
_ref.read(checkIpNumProvider.notifier).add();
}
void tryCheckIp() {
final isTimeout = _ref.read(
networkDetectionProvider.select(
(state) => state.ipInfo == null && state.isLoading == false,
),
);
if (!isTimeout) {
return;
}
_ref.read(checkIpNumProvider.notifier).add();
}
void applyProfileDebounce({bool silence = false, bool force = false}) {
debouncer.call(FunctionTag.applyProfile, (silence, force) {
applyProfile(silence: silence, force: force);
@@ -808,6 +795,9 @@ extension CoreControllerExt on AppController {
}
Future<Result<bool>> _requestAdmin(bool enableTun) async {
if (system.isWindows && kDebugMode) {
return Result.success(false);
}
final realTunEnable = _ref.read(realTunEnableProvider);
if (enableTun != realTunEnable && realTunEnable == false) {
final code = await system.authorizeCore();
@@ -827,8 +817,8 @@ extension CoreControllerExt on AppController {
}
Future<void> restartCore([bool start = false]) async {
_ref.read(coreStatusProvider.notifier).value = CoreStatus.disconnected;
await coreController.shutdown(true);
globalState.isUserDisconnected = true;
await coreController.shutdown();
await _connectCore();
await _initCore();
if (start || _ref.read(isStartProvider)) {
@@ -1188,8 +1178,8 @@ extension CommonControllerExt on AppController {
}
final res = await futureFunction();
return res;
} catch (e, s) {
commonPrint.log('$title ===> $e, $s', logLevel: LogLevel.warning);
} catch (e) {
commonPrint.log('$title===> $e', logLevel: LogLevel.warning);
if (silence) {
globalState.showNotifier(e.toString());
} else {

View File

@@ -65,8 +65,8 @@ class CoreController {
);
}
Future<void> shutdown(bool isUser) async {
await _interface.shutdown(isUser);
Future<void> shutdown() async {
await _interface.shutdown();
}
FutureOr<bool> get isInit => _interface.isInit;
@@ -201,10 +201,9 @@ class CoreController {
final profilePath = await appPath.getProfilePath(id.toString());
final res = await _interface.getConfig(profilePath);
if (res.isSuccess) {
final data = Map<String, dynamic>.from(res.data);
data['rules'] = data['rule'];
data.remove('rule');
return data;
res.data['rules'] = res.data['rule'];
res.data.remove('rule');
return res.data;
} else {
throw res.message;
}

View File

@@ -11,7 +11,7 @@ mixin CoreInterface {
Future<String> preload();
Future<bool> shutdown(bool isUser);
Future<bool> shutdown();
Future<bool> get isInit;
@@ -86,9 +86,7 @@ abstract class CoreHandlerInterface with CoreInterface {
Duration? timeout,
}) async {
try {
if (!completer.isCompleted) {
return null;
}
await completer.future.timeout(const Duration(seconds: 10));
} catch (e) {
commonPrint.log(
'Invoke pre ${method.name} timeout $e',
@@ -100,9 +98,9 @@ abstract class CoreHandlerInterface with CoreInterface {
commonPrint.log('Invoke ${method.name} ${DateTime.now()} $data');
}
return await utils.handleWatch(
return utils.handleWatch(
function: () async {
return await invoke<T>(method: method, data: data, timeout: timeout);
return await invoke(method: method, data: data, timeout: timeout);
},
onWatch: (data, elapsedMilliseconds) {
commonPrint.log('Invoke ${method.name} ${elapsedMilliseconds}ms');
@@ -133,7 +131,7 @@ abstract class CoreHandlerInterface with CoreInterface {
}
@override
Future<bool> shutdown(bool isUser);
Future<bool> shutdown();
@override
Future<bool> get isInit async {
@@ -165,8 +163,8 @@ abstract class CoreHandlerInterface with CoreInterface {
@override
Future<Result> getConfig(String path) async {
final res = await _invoke(method: ActionMethod.getConfig, data: path);
return res ?? Result.success({});
return await _invoke<Result>(method: ActionMethod.getConfig, data: path) ??
Result.success({});
}
@override

View File

@@ -37,12 +37,10 @@ class CoreLib extends CoreHandlerInterface {
}
@override
Future<bool> shutdown(_) async {
if (!_connectedCompleter.isCompleted) {
return false;
}
Future<bool> shutdown() async {
await service?.shutdown();
_connectedCompleter = Completer();
return service?.shutdown() ?? true;
return true;
}
@override

View File

@@ -16,8 +16,6 @@ class CoreService extends CoreHandlerInterface {
Completer<Socket> _socketCompleter = Completer();
Completer<bool> _shutdownCompleter = Completer();
final Map<String, Completer> _callbackCompleterMap = {};
Process? _process;
@@ -37,9 +35,6 @@ class CoreService extends CoreHandlerInterface {
if (result.id?.isEmpty == true) {
coreEventManager.sendEvent(CoreEvent.fromJson(result.data));
}
if (completer?.isCompleted == true) {
return;
}
completer?.complete(data);
}
@@ -81,9 +76,6 @@ class CoreService extends CoreHandlerInterface {
})
.onDone(() {
_handleInvokeCrashEvent();
if (!_shutdownCompleter.isCompleted) {
_shutdownCompleter.complete(true);
}
});
}
@@ -95,7 +87,7 @@ class CoreService extends CoreHandlerInterface {
Future<void> start() async {
if (_process != null) {
await shutdown(false);
await shutdown();
}
final serverSocket = await _serverCompleter.future;
final arg = system.isWindows
@@ -121,7 +113,7 @@ class CoreService extends CoreHandlerInterface {
@override
destroy() async {
final server = await _serverCompleter.future;
await shutdown(false);
await shutdown();
await server.close();
await _deleteSocketFile();
return true;
@@ -143,16 +135,12 @@ class CoreService extends CoreHandlerInterface {
if (_socketCompleter.isCompleted) {
final socket = await _socketCompleter.future;
_socketCompleter = Completer();
await socket.close();
socket.close();
}
}
@override
shutdown(bool isUser) async {
if (!_socketCompleter.isCompleted && _process == null) {
return false;
}
_shutdownCompleter = Completer();
shutdown() async {
await _destroySocket();
_clearCompleter();
if (system.isWindows) {
@@ -160,11 +148,7 @@ class CoreService extends CoreHandlerInterface {
}
_process?.kill();
_process = null;
if (isUser) {
return _shutdownCompleter.future;
} else {
return true;
}
return true;
}
void _clearCompleter() {

View File

@@ -68,8 +68,8 @@ class _AppStateManagerState extends ConsumerState<AppStateManager>
if (state == AppLifecycleState.resumed) {
render?.resume();
WidgetsBinding.instance.addPostFrameCallback((_) {
appController.tryCheckIp();
if (system.isAndroid) {
appController.addCheckIp();
appController.tryStartCore();
}
});

View File

@@ -98,14 +98,16 @@ class _CoreContainerState extends ConsumerState<CoreManager>
@override
Future<void> onCrash(String message) async {
if (!globalState.isUserDisconnected &&
WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) {
context.showNotifier(message);
}
globalState.isUserDisconnected = false;
if (ref.read(coreStatusProvider) != CoreStatus.connected) {
return;
}
ref.read(coreStatusProvider.notifier).value = CoreStatus.disconnected;
if (WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) {
context.showNotifier(message);
}
await coreController.shutdown(false);
await coreController.shutdown();
super.onCrash(message);
}
}

View File

@@ -13,7 +13,7 @@ class InitErrorScreen extends StatelessWidget {
return Scaffold(
appBar: AppBar(
title: const Text('Init Failed'),
title: const Text('System Init Failed'),
backgroundColor: colorScheme.error,
foregroundColor: colorScheme.onError,
elevation: 0,
@@ -24,6 +24,7 @@ class InitErrorScreen extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 1. Header Section
Row(
children: [
Icon(

View File

@@ -1822,7 +1822,7 @@ final class NetworkDetectionProvider
}
}
String _$networkDetectionHash() => r'501babec2bbf2a38e4fef96cf20c76e9352bc5ee';
String _$networkDetectionHash() => r'29770de6a7ea2ac04b6584145d5200a7d43e45b0';
abstract class _$NetworkDetection extends $Notifier<NetworkDetectionState> {
NetworkDetectionState build();

View File

@@ -41,6 +41,7 @@ class GlobalState {
CorePalette? corePalette;
DateTime? startTime;
UpdateTasks tasks = [];
bool isUserDisconnected = false;
SetupState? lastSetupState;
VpnState? lastVpnState;
@@ -87,7 +88,9 @@ class GlobalState {
configMap,
sync: (data) async {
final newConfigMap = data.configMap;
final config = Config.realFromJson(newConfigMap);
final config = newConfigMap != null
? Config.fromJson(newConfigMap)
: Config(themeProps: defaultThemeProps);
await Future.wait([
database.restore(data.profiles, data.scripts, data.rules, data.links),
preferences.saveConfig(config),

View File

@@ -30,7 +30,7 @@ class _EditProfileViewState extends State<EditProfileView> {
late final TextEditingController _labelController;
late final TextEditingController _urlController;
late final TextEditingController _autoUpdateDurationController;
late bool _autoUpdate;
late final bool _autoUpdate;
String? _rawText;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final _fileInfoNotifier = ValueNotifier<FileInfo?>(null);

View File

@@ -1,7 +1,7 @@
name: fl_clash
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
publish_to: 'none'
version: 0.8.92+2026012502
version: 0.8.92+2026012301
environment:
sdk: '>=3.8.0 <4.0.0'

View File

@@ -369,15 +369,6 @@ class BuildCommand extends Command {
.map((e) => e.arch!)
.toList();
Future<void> _buildEnvFile(String env, {String? coreSha256}) async {
final data = {
'APP_ENV': env,
if (coreSha256 != null) 'CORE_SHA256': coreSha256,
};
final envFile = File(join(current, 'env.json'))..create();
await envFile.writeAsString(json.encode(data));
}
Future<void> _getLinuxDependencies(Arch arch) async {
await Build.exec(Build.getExecutable('sudo apt update -y'));
await Build.exec(
@@ -421,7 +412,7 @@ class BuildCommand extends Command {
await Build.exec(
name: name,
Build.getExecutable(
'flutter_distributor package --skip-clean --platform ${target.name} --targets $targets --flutter-build-args=verbose,dart-define-from-file=env.json$args',
'flutter_distributor package --skip-clean --platform ${target.name} --targets $targets --flutter-build-args=verbose$args --build-dart-define=APP_ENV=$env',
),
);
}
@@ -457,23 +448,21 @@ class BuildCommand extends Command {
mode: mode,
);
String? coreSha256;
if (Platform.isWindows) {
coreSha256 = await Build.calcSha256(corePaths.first);
await Build.buildHelper(target, coreSha256);
}
await _buildEnvFile(env, coreSha256: coreSha256);
if (out != 'app') {
return;
}
switch (target) {
case Target.windows:
final token = target != Target.android
? await Build.calcSha256(corePaths.first)
: null;
Build.buildHelper(target, token!);
_buildDistributor(
target: target,
targets: 'exe,zip',
args: ' --description $archName',
args:
' --description $archName --build-dart-define=CORE_SHA256=$token',
env: env,
);
return;