Compare commits

..

1 Commits

Author SHA1 Message Date
chen08209
61465f5178 Add android separates the core process
Support core status check and force restart

Update flutter and pub dependencies
2025-08-27 16:28:34 +08:00
7 changed files with 58 additions and 103 deletions

View File

@@ -1,24 +1,22 @@
package com.follow.clash
import android.os.Bundle
import com.follow.clash.common.GlobalState
import com.follow.clash.plugins.AppPlugin
import com.follow.clash.plugins.ServicePlugin
import com.follow.clash.plugins.TilePlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
class MainActivity : FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GlobalState.launch {
State.destroyServiceEngine()
}
}
class MainActivity : FlutterActivity(),
CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default) {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
launch {
State.destroyServiceEngine()
}
super.configureFlutterEngine(flutterEngine)
flutterEngine.plugins.add(AppPlugin())
flutterEngine.plugins.add(ServicePlugin())

View File

@@ -80,11 +80,9 @@ object State {
suspend fun destroyServiceEngine() {
runLock.withLock {
withContext(Dispatchers.Main) {
try {
runCatching {
serviceFlutterEngine?.destroy()
serviceFlutterEngine = null
} catch (_: Exception) {
}
}
}

View File

@@ -89,14 +89,6 @@ class ServicePlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
return Gson().fromJson(res, VpnOptions::class.java)
}
suspend fun startService(options: VpnOptions, inApp: Boolean) {
Service.startService(options, inApp)
}
suspend fun stopService() {
Service.stopService()
}
val semaphore = Semaphore(10)
fun handleSendEvent(value: String?) {

View File

@@ -3,7 +3,6 @@ package com.follow.clash.service
import android.app.Service
import android.content.Intent
import android.os.IBinder
import com.follow.clash.common.GlobalState
import com.follow.clash.common.ServiceDelegate
import com.follow.clash.common.intent
import com.follow.clash.core.Core
@@ -29,7 +28,6 @@ class RemoteService : Service(),
}
fun onServiceDisconnected() {
GlobalState.log("onServiceDisconnected===>")
handleStopService()
}

View File

@@ -4,6 +4,8 @@ mixin AutoDisposeNotifierMixin<T> on AnyNotifier<T, T> {
set value(T value) {
if (ref.mounted) {
state = value;
} else {
onUpdate(value);
}
}

View File

@@ -28,7 +28,7 @@ class Logs extends _$Logs with AutoDisposeNotifierMixin {
}
void addLog(Log value) {
state = state.copyWith()..add(value);
this.value = state.copyWith()..add(value);
}
@override
@@ -50,7 +50,7 @@ class Requests extends _$Requests with AutoDisposeNotifierMixin {
}
void addRequest(TrackerInfo value) {
state = state.copyWith()..add(value);
this.value = state.copyWith()..add(value);
}
}
@@ -70,7 +70,8 @@ class Providers extends _$Providers with AutoDisposeNotifierMixin {
if (provider == null) return;
final index = state.indexWhere((item) => item.name == provider.name);
if (index == -1) return;
state = List.from(state)..[index] = provider;
final newState = List<ExternalProvider>.from(state)..[index] = provider;
value = newState;
}
}
@@ -101,7 +102,7 @@ class SystemBrightness extends _$SystemBrightness
}
void setState(Brightness value) {
state = value;
this.value = value;
}
}
@@ -118,11 +119,11 @@ class Traffics extends _$Traffics with AutoDisposeNotifierMixin {
}
void addTraffic(Traffic value) {
state = state.copyWith()..add(value);
this.value = state.copyWith()..add(value);
}
void clear() {
state = state.copyWith()..clear();
value = state.copyWith()..clear();
}
}
@@ -150,12 +151,6 @@ class LocalIp extends _$LocalIp with AutoDisposeNotifierMixin {
onUpdate(value) {
globalState.appState = globalState.appState.copyWith(localIp: value);
}
@override
set state(String? value) {
super.state = value;
globalState.appState = globalState.appState.copyWith(localIp: state);
}
}
@riverpod
@@ -332,7 +327,7 @@ class DelayDataSource extends _$DelayDataSource with AutoDisposeNotifierMixin {
newDelayMap[delay.url] = {};
}
newDelayMap[delay.url]![delay.name] = delay.value;
state = newDelayMap;
value = newDelayMap;
}
}
}
@@ -375,7 +370,7 @@ class ProfileOverrideState extends _$ProfileOverrideState
if (value == null) {
return;
}
state = value;
this.value = value;
}
}
@@ -403,6 +398,6 @@ class QueryMap extends _$QueryMap with AutoDisposeNotifierMixin {
}
void updateQuery(QueryTag tag, String value) {
state = Map.from(globalState.appState.queryMap)..[tag] = value;
this.value = Map.from(globalState.appState.queryMap)..[tag] = value;
}
}

View File

@@ -14,13 +14,11 @@ class AppSetting extends _$AppSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
appSetting: value,
);
globalState.config = globalState.config.copyWith(appSetting: value);
}
void updateState(AppSettingProps Function(AppSettingProps state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -33,13 +31,11 @@ class WindowSetting extends _$WindowSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
windowProps: value,
);
globalState.config = globalState.config.copyWith(windowProps: value);
}
void updateState(WindowProps Function(WindowProps state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -52,13 +48,11 @@ class VpnSetting extends _$VpnSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
vpnProps: value,
);
globalState.config = globalState.config.copyWith(vpnProps: value);
}
void updateState(VpnProps Function(VpnProps state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -71,13 +65,11 @@ class NetworkSetting extends _$NetworkSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
networkProps: value,
);
globalState.config = globalState.config.copyWith(networkProps: value);
}
void updateState(NetworkProps Function(NetworkProps state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -90,13 +82,11 @@ class ThemeSetting extends _$ThemeSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
themeProps: value,
);
globalState.config = globalState.config.copyWith(themeProps: value);
}
void updateState(ThemeProps Function(ThemeProps state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -109,15 +99,15 @@ class Profiles extends _$Profiles with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
profiles: value,
);
globalState.config = globalState.config.copyWith(profiles: value);
}
String? _getLabel(String? label, String id) {
final realLabel = label ?? id;
final hasDup = state.indexWhere(
(element) => element.label == realLabel && element.id != id) !=
final hasDup =
state.indexWhere(
(element) => element.label == realLabel && element.id != id,
) !=
-1;
if (hasDup) {
return _getLabel(utils.getOverwriteLabel(realLabel), id);
@@ -128,8 +118,9 @@ class Profiles extends _$Profiles with AutoDisposeNotifierMixin {
void setProfile(Profile profile) {
final List<Profile> profilesTemp = List.from(state);
final index =
profilesTemp.indexWhere((element) => element.id == profile.id);
final index = profilesTemp.indexWhere(
(element) => element.id == profile.id,
);
final updateProfile = profile.copyWith(
label: _getLabel(profile.label, profile.id),
);
@@ -138,21 +129,23 @@ class Profiles extends _$Profiles with AutoDisposeNotifierMixin {
} else {
profilesTemp[index] = updateProfile;
}
state = profilesTemp;
value = profilesTemp;
}
void updateProfile(
String profileId, Profile Function(Profile profile) builder) {
String profileId,
Profile Function(Profile profile) builder,
) {
final List<Profile> profilesTemp = List.from(state);
final index = profilesTemp.indexWhere((element) => element.id == profileId);
if (index != -1) {
profilesTemp[index] = builder(profilesTemp[index]);
}
state = profilesTemp;
value = profilesTemp;
}
void deleteProfileById(String id) {
state = state.where((element) => element.id != id).toList();
value = state.where((element) => element.id != id).toList();
}
}
@@ -166,9 +159,7 @@ class CurrentProfileId extends _$CurrentProfileId
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
currentProfileId: value,
);
globalState.config = globalState.config.copyWith(currentProfileId: value);
}
}
@@ -181,13 +172,11 @@ class AppDAVSetting extends _$AppDAVSetting with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
dav: value,
);
globalState.config = globalState.config.copyWith(dav: value);
}
void updateState(DAV? Function(DAV? state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -200,9 +189,7 @@ class OverrideDns extends _$OverrideDns with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
overrideDns: value,
);
globalState.config = globalState.config.copyWith(overrideDns: value);
}
}
@@ -215,9 +202,7 @@ class HotKeyActions extends _$HotKeyActions with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
hotKeyActions: value,
);
globalState.config = globalState.config.copyWith(hotKeyActions: value);
}
}
@@ -231,13 +216,11 @@ class ProxiesStyleSetting extends _$ProxiesStyleSetting
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
proxiesStyle: value,
);
globalState.config = globalState.config.copyWith(proxiesStyle: value);
}
void updateState(ProxiesStyle Function(ProxiesStyle state) builder) {
state = builder(state);
value = builder(state);
}
}
@@ -250,9 +233,7 @@ class ScriptState extends _$ScriptState with AutoDisposeNotifierMixin {
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
scriptProps: value,
);
globalState.config = globalState.config.copyWith(scriptProps: value);
}
void setScript(Script script) {
@@ -263,15 +244,11 @@ class ScriptState extends _$ScriptState with AutoDisposeNotifierMixin {
} else {
list.add(script);
}
state = state.copyWith(
scripts: list,
);
value = state.copyWith(scripts: list);
}
void setId(String id) {
state = state.copyWith(
currentId: state.currentId != id ? id : null,
);
value = state.copyWith(currentId: state.currentId != id ? id : null);
}
void del(String id) {
@@ -281,10 +258,7 @@ class ScriptState extends _$ScriptState with AutoDisposeNotifierMixin {
list.removeAt(index);
}
final nextId = id == state.currentId ? null : state.currentId;
state = state.copyWith(
scripts: list,
currentId: nextId,
);
state = state.copyWith(scripts: list, currentId: nextId);
}
bool isExits(String label) {
@@ -305,13 +279,11 @@ class PatchClashConfig extends _$PatchClashConfig
if (newState == null) {
return;
}
state = newState;
value = newState;
}
@override
onUpdate(value) {
globalState.config = globalState.config.copyWith(
patchClashConfig: value,
);
globalState.config = globalState.config.copyWith(patchClashConfig: value);
}
}