aaf934c2d1
Rework the application layer end to end: core IPC client, providers, models, database, managers, and shared utilities, with riverpod 3.4.2 and freezed 4.0.1. Keep a rejected profile selected, push the empty config to Core when a profile fails to build, and fall back to the default activity icon for package icons. Add opt-in proxy authentication that injects credentials into the generated profile and the runtime config, force-clears profile-provided skip-auth-prefixes so loopback stays covered, sends the credentials with the app's own proxied requests, and withholds the Android VPN system proxy while credentials are set. HelperCoreLease treats an unreachable Helper as confirmation once the OS reports the Core pid gone, and the lifecycle reconcile retries a parked stop, so the Core comes back after the Helper service dies. Launch arguments seed LinkManager so a clash:// link raises a silently started window, the access control app list is fetched on every page entry, the desktop header matches a standard title bar height, and the tray icons ship as resolution-aware assets scoped per platform. The version moves to 0.8.97+2026090101. Rule.parse mirrors mihomo's ParseRulePayload: the type is case-insensitive, MATCH rules keep no content field, a two-field rule is payload without a target except for comma-payload types whose lone field is the target, params are matched whole, and the wildcard and REMATCH-NAME types the core accepts get their own actions instead of collapsing into DOMAIN. Window routes show, hide and toggle through one serialized queue and defers the macOS accessory activation switch until a second after the last regular switch, so hotkey bursts no longer leave stray Dock icons. The hotkey manager registers through rust_api instead of hotkey_manager, the window header restyles the caption buttons after the native Windows title bar, and the proxies tab keeps its tab controller alive while the empty state animates in. Bootstrap reads the Android dynamic palette from the plugin channel without the deprecated CorePalette, dynamic_color moves to its material_ui release, navigator_resizable 3.1.0 fixes an assertion when popping mid-transition, reorderable_grid goes, and the SDK floor rises to 3.10. Changelog: Rework the app layer and window handling, and add proxy authentication
170 lines
4.5 KiB
Dart
170 lines
4.5 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:path/path.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
class AppPath {
|
|
static AppPath? _instance;
|
|
Completer<Directory> dataDir = Completer();
|
|
late final Future<Directory?> _downloadDir = downloadDirectory();
|
|
Completer<Directory> tempDir = Completer();
|
|
Completer<Directory> cacheDir = Completer();
|
|
late String appDirPath;
|
|
|
|
@visibleForTesting
|
|
static Future<Directory> Function() supportDirectory =
|
|
getApplicationSupportDirectory;
|
|
|
|
@visibleForTesting
|
|
static Future<Directory> Function() temporaryDirectory =
|
|
getTemporaryDirectory;
|
|
|
|
@visibleForTesting
|
|
static Future<Directory> Function() cacheDirectory =
|
|
getApplicationCacheDirectory;
|
|
|
|
@visibleForTesting
|
|
static Future<Directory?> Function() downloadDirectory =
|
|
getDownloadsDirectory;
|
|
|
|
AppPath._internal() {
|
|
appDirPath = join(dirname(Platform.resolvedExecutable));
|
|
supportDirectory().then((value) {
|
|
dataDir.complete(value);
|
|
});
|
|
temporaryDirectory().then((value) {
|
|
tempDir.complete(value);
|
|
});
|
|
cacheDirectory().then((value) {
|
|
cacheDir.complete(value);
|
|
});
|
|
}
|
|
|
|
factory AppPath() {
|
|
_instance ??= AppPath._internal();
|
|
return _instance!;
|
|
}
|
|
|
|
String get executableExtension {
|
|
return system.isWindows ? '.exe' : '';
|
|
}
|
|
|
|
String get executableDirPath {
|
|
final currentExecutablePath = Platform.resolvedExecutable;
|
|
return dirname(currentExecutablePath);
|
|
}
|
|
|
|
String get corePath {
|
|
return join(executableDirPath, 'FlClashCore$executableExtension');
|
|
}
|
|
|
|
String get helperPath {
|
|
return join(executableDirPath, '$appHelperService$executableExtension');
|
|
}
|
|
|
|
Future<String> get downloadDirPath async {
|
|
final directory = await _downloadDir;
|
|
return directory?.path ?? await homeDirPath;
|
|
}
|
|
|
|
Future<String> get homeDirPath async {
|
|
final directory = await dataDir.future;
|
|
return directory.path;
|
|
}
|
|
|
|
Future<String> get databasePath async {
|
|
final mHomeDirPath = await homeDirPath;
|
|
return join(mHomeDirPath, 'database.sqlite');
|
|
}
|
|
|
|
Future<String> get backupFilePath async {
|
|
final mHomeDirPath = await homeDirPath;
|
|
return join(mHomeDirPath, 'backup.zip');
|
|
}
|
|
|
|
Future<String> get restoreDirPath async {
|
|
final mHomeDirPath = await homeDirPath;
|
|
return join(mHomeDirPath, 'restore');
|
|
}
|
|
|
|
Future<String> get tempFilePath async {
|
|
final mTempDir = await tempDir.future;
|
|
return join(mTempDir.path, 'temp$uniqueId');
|
|
}
|
|
|
|
Future<String> get lockFilePath async {
|
|
final homeDirPath = await appPath.homeDirPath;
|
|
return join(homeDirPath, 'FlClash.lock');
|
|
}
|
|
|
|
Future<String> get configFilePath async {
|
|
final mHomeDirPath = await homeDirPath;
|
|
return join(mHomeDirPath, 'config.yaml');
|
|
}
|
|
|
|
Future<String> get sharedPreferencesPath async {
|
|
final directory = await dataDir.future;
|
|
return join(directory.path, 'shared_preferences.json');
|
|
}
|
|
|
|
Future<String> get profilesPath async {
|
|
final directory = await dataDir.future;
|
|
return join(directory.path, profilesDirectoryName);
|
|
}
|
|
|
|
Future<String> getProfilePath(String fileName) async {
|
|
return join(await profilesPath, '$fileName.yaml');
|
|
}
|
|
|
|
Future<String> get scriptsDirPath async {
|
|
final path = await homeDirPath;
|
|
return join(path, 'scripts');
|
|
}
|
|
|
|
Future<String> getScriptPath(String fileName) async {
|
|
final path = await scriptsDirPath;
|
|
return join(path, '$fileName.js');
|
|
}
|
|
|
|
Future<String> getProvidersRootPath() async {
|
|
final directory = await profilesPath;
|
|
return join(directory, providersDirectoryName);
|
|
}
|
|
|
|
Future<String> getProviderDirPath(int profileId, String type) async {
|
|
final directory = await getProvidersRootPath();
|
|
return join(directory, profileId.toString(), type);
|
|
}
|
|
|
|
Future<void> ensureProviderDirs(int profileId) async {
|
|
for (final type in const [
|
|
proxiesProviderDirectoryName,
|
|
rulesProviderDirectoryName,
|
|
]) {
|
|
final directory = Directory(await getProviderDirPath(profileId, type));
|
|
if (await directory.exists()) {
|
|
continue;
|
|
}
|
|
await directory.create(recursive: true);
|
|
}
|
|
}
|
|
|
|
Future<String> get tempPath async {
|
|
final directory = await tempDir.future;
|
|
return directory.path;
|
|
}
|
|
}
|
|
|
|
final appPath = AppPath();
|
|
|
|
String getBackupFileName() {
|
|
return '${appName}_backup_${DateTime.now().show}.zip';
|
|
}
|
|
|
|
String get logFileName {
|
|
return '${appName}_${DateTime.now().show}.log';
|
|
}
|