Skip to content

Commit

Permalink
Fix the problem that vpn cannot be started in some cases
Browse files Browse the repository at this point in the history
Fix the problem that geodata url does not take effect
  • Loading branch information
chen08209 committed Jul 13, 2024
1 parent 2dd4506 commit 1765576
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 51 deletions.
35 changes: 20 additions & 15 deletions android/app/src/main/kotlin/com/follow/clash/GlobalState.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.follow.clash

import android.app.Activity
import android.content.Context
import androidx.lifecycle.MutableLiveData
import com.follow.clash.plugins.AppPlugin
Expand All @@ -9,15 +8,20 @@ import com.follow.clash.plugins.TilePlugin
import io.flutter.FlutterInjector
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor
import java.util.Date
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock

enum class RunState {
START,
PENDING,
STOP
}


object GlobalState {

private val lock = ReentrantLock()

val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
var flutterEngine: FlutterEngine? = null
private var serviceEngine: FlutterEngine? = null
Expand All @@ -39,19 +43,20 @@ object GlobalState {

fun initServiceEngine(context: Context) {
if (serviceEngine != null) return
val serviceEngine = FlutterEngine(context)
serviceEngine.plugins.add(ProxyPlugin())
serviceEngine.plugins.add(AppPlugin())
serviceEngine.plugins.add(TilePlugin())
val vpnService = DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
"vpnService"
)
serviceEngine.dartExecutor.executeDartEntrypoint(
vpnService,
listOf("${flutterEngine == null}")
)
GlobalState.serviceEngine = serviceEngine
lock.withLock {
if (serviceEngine != null) return
serviceEngine = FlutterEngine(context)
serviceEngine?.plugins?.add(ProxyPlugin())
serviceEngine?.plugins?.add(AppPlugin())
serviceEngine?.plugins?.add(TilePlugin())
val vpnService = DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
"vpnService"
)
serviceEngine?.dartExecutor?.executeDartEntrypoint(
vpnService,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
flClashVpnService = binder.getService()
if (isStart) {
startVpn()
} else {
flClashVpnService?.initServiceEngine()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class FlClashVpnService : VpnService() {
PendingIntent.FLAG_UPDATE_CURRENT
)
}

with(NotificationCompat.Builder(this, CHANNEL)) {
setSmallIcon(R.drawable.ic_stat_name)
setContentTitle("FlClash")
Expand All @@ -127,7 +126,7 @@ class FlClashVpnService : VpnService() {
setOngoing(true)
setShowWhen(false)
setOnlyAlertOnce(true)
setAutoCancel(true);
setAutoCancel(true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/Clash.Meta
Submodule Clash.Meta updated 1 files
+1 −1 config/config.go
2 changes: 2 additions & 0 deletions core/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
targetConfig.Tun.Stack = patchConfig.Tun.Stack
targetConfig.GeodataLoader = patchConfig.GeodataLoader
targetConfig.Profile.StoreSelected = false
targetConfig.GeoXUrl = patchConfig.GeoXUrl
targetConfig.GlobalUA = patchConfig.GlobalUA
if targetConfig.DNS.Enable == false {
targetConfig.DNS = patchConfig.DNS
}
Expand Down
48 changes: 24 additions & 24 deletions lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,30 @@ class GlobalState {
required String message,
SnackBarAction? action,
}) {
// final width = context.width;
// EdgeInsets margin;
// if (width < 600) {
// margin = const EdgeInsets.only(
// bottom: 96,
// right: 16,
// left: 16,
// );
// } else {
// margin = EdgeInsets.only(
// bottom: 16,
// left: 16,
// right: width - 316,
// );
// }
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// action: action,
// content: Text(message),
// behavior: SnackBarBehavior.floating,
// duration: const Duration(milliseconds: 1500),
// margin: margin,
// ),
// );
final width = context.width;
EdgeInsets margin;
if (width < 600) {
margin = const EdgeInsets.only(
bottom: 16,
right: 16,
left: 16,
);
} else {
margin = EdgeInsets.only(
bottom: 16,
left: 16,
right: width - 316,
);
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
action: action,
content: Text(message),
behavior: SnackBarBehavior.floating,
duration: const Duration(milliseconds: 1500),
margin: margin,
),
);
}

Future<T?> safeRun<T>(
Expand Down
9 changes: 0 additions & 9 deletions lib/widgets/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
class CommonScaffold extends StatefulWidget {
final Widget body;
final Widget? bottomNavigationBar;
final Widget? floatingActionButton;
final String title;
final Widget? leading;
final List<Widget>? actions;
Expand All @@ -20,7 +19,6 @@ class CommonScaffold extends StatefulWidget {
this.leading,
required this.title,
this.actions,
this.floatingActionButton,
this.automaticallyImplyLeading = true,
});

Expand Down Expand Up @@ -125,13 +123,6 @@ class CommonScaffoldState extends State<CommonScaffold> {
Widget build(BuildContext context) {
return _platformContainer(
child: Scaffold(
floatingActionButton: widget.floatingActionButton ??
ValueListenableBuilder(
valueListenable: _floatingActionButton,
builder: (_, floatingActionButton, __) {
return floatingActionButton ?? Container();
},
),
resizeToAvoidBottomInset: true,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
Expand Down

0 comments on commit 1765576

Please sign in to comment.