Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa4ffbe4fb | ||
|
|
3d25298639 | ||
|
|
1765576d09 | ||
|
|
2dd45062f1 | ||
|
|
c6407984ac | ||
|
|
53af86238e |
@@ -1,10 +1,15 @@
|
||||
package com.follow.clash
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.follow.clash.plugins.AppPlugin
|
||||
import com.follow.clash.plugins.ProxyPlugin
|
||||
import com.follow.clash.plugins.TilePlugin
|
||||
import io.flutter.FlutterInjector
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import java.util.Date
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
enum class RunState {
|
||||
START,
|
||||
@@ -12,16 +17,46 @@ enum class RunState {
|
||||
STOP
|
||||
}
|
||||
|
||||
class GlobalState {
|
||||
companion object {
|
||||
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
||||
var runTime: Date? = null
|
||||
var flutterEngine: FlutterEngine? = null
|
||||
fun getCurrentTilePlugin(): TilePlugin? =
|
||||
flutterEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
||||
|
||||
fun getCurrentAppPlugin(): AppPlugin? =
|
||||
flutterEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
|
||||
object GlobalState {
|
||||
|
||||
private val lock = ReentrantLock()
|
||||
|
||||
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
|
||||
var flutterEngine: FlutterEngine? = null
|
||||
private var serviceEngine: FlutterEngine? = null
|
||||
|
||||
fun getCurrentAppPlugin(): AppPlugin? {
|
||||
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
||||
return currentEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
|
||||
}
|
||||
|
||||
fun getCurrentTitlePlugin(): TilePlugin? {
|
||||
val currentEngine = if (flutterEngine != null) flutterEngine else serviceEngine
|
||||
return currentEngine?.plugins?.get(TilePlugin::class.java) as TilePlugin?
|
||||
}
|
||||
|
||||
fun destroyServiceEngine() {
|
||||
serviceEngine?.destroy()
|
||||
serviceEngine = null
|
||||
}
|
||||
|
||||
fun initServiceEngine(context: Context) {
|
||||
if (serviceEngine != null) return
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import io.flutter.embedding.engine.FlutterEngine
|
||||
class MainActivity : FlutterActivity() {
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
GlobalState.flutterEngine?.destroy()
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
flutterEngine.plugins.add(AppPlugin())
|
||||
flutterEngine.plugins.add(ProxyPlugin())
|
||||
|
||||
@@ -2,27 +2,27 @@ package com.follow.clash.plugins
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.follow.clash.GlobalState
|
||||
import com.follow.clash.extensions.getBase64
|
||||
import com.follow.clash.extensions.getInetSocketAddress
|
||||
import com.follow.clash.extensions.getProtocol
|
||||
import com.follow.clash.models.Process
|
||||
import com.follow.clash.models.Package
|
||||
import com.follow.clash.models.Process
|
||||
import com.google.gson.Gson
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.Result
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
@@ -30,6 +30,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
|
||||
class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||
|
||||
private var activity: Activity? = null
|
||||
@@ -47,30 +48,41 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
||||
private val iconMap = mutableMapOf<String, String?>()
|
||||
|
||||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
scope = CoroutineScope(Dispatchers.Default)
|
||||
context = flutterPluginBinding.applicationContext;
|
||||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "app")
|
||||
channel.setMethodCallHandler(this)
|
||||
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
scope.cancel()
|
||||
}
|
||||
|
||||
private fun tip(message: String?) {
|
||||
if (toast != null) {
|
||||
toast!!.cancel()
|
||||
if(GlobalState.flutterEngine == null){
|
||||
if (toast != null) {
|
||||
toast!!.cancel()
|
||||
}
|
||||
toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
|
||||
toast!!.show()
|
||||
}
|
||||
toast = Toast.makeText(context, message, Toast.LENGTH_SHORT)
|
||||
toast!!.show()
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
||||
override fun onMethodCall(call: MethodCall, result: Result) {
|
||||
when (call.method) {
|
||||
"moveTaskToBack" -> {
|
||||
activity?.moveTaskToBack(true)
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
"updateExcludeFromRecents" -> {
|
||||
val value = call.argument<Boolean>("value")
|
||||
updateExcludeFromRecents(value)
|
||||
result.success(true);
|
||||
}
|
||||
|
||||
"getPackages" -> {
|
||||
scope.launch {
|
||||
result.success(getPackages())
|
||||
@@ -115,7 +127,7 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
||||
}
|
||||
scope.launch {
|
||||
withContext(Dispatchers.Default) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
result.success(null)
|
||||
return@withContext
|
||||
}
|
||||
@@ -158,6 +170,24 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateExcludeFromRecents(value: Boolean?) {
|
||||
if (context == null) return
|
||||
val am = getSystemService(context!!, ActivityManager::class.java)
|
||||
val task = am?.appTasks?.firstOrNull {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
it.taskInfo.taskId == activity?.taskId
|
||||
} else {
|
||||
it.taskInfo.id == activity?.taskId
|
||||
}
|
||||
}
|
||||
|
||||
when (value) {
|
||||
true -> task?.setExcludeFromRecents(value)
|
||||
false -> task?.setExcludeFromRecents(value)
|
||||
null -> task?.setExcludeFromRecents(false)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getPackageIcon(packageName: String): String? {
|
||||
val packageManager = context?.packageManager
|
||||
if (iconMap[packageName] == null) {
|
||||
@@ -197,11 +227,10 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
||||
|
||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||
activity = binding.activity;
|
||||
scope = CoroutineScope(Dispatchers.Default)
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivityForConfigChanges() {
|
||||
activity = null;
|
||||
activity = null
|
||||
}
|
||||
|
||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||
@@ -210,7 +239,6 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
|
||||
|
||||
override fun onDetachedFromActivity() {
|
||||
channel.invokeMethod("exit", null)
|
||||
scope.cancel()
|
||||
activity = null;
|
||||
activity = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.follow.clash.plugins
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
@@ -9,8 +8,7 @@ import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.VpnService
|
||||
import android.os.Build.VERSION
|
||||
import android.os.Build.VERSION_CODES
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -25,38 +23,36 @@ import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.util.Date
|
||||
|
||||
|
||||
class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {
|
||||
|
||||
private lateinit var flutterMethodChannel: MethodChannel
|
||||
|
||||
val VPN_PERMISSION_REQUEST_CODE = 1001
|
||||
val NOTIFICATION_PERMISSION_REQUEST_CODE = 1002
|
||||
|
||||
private lateinit var flutterMethodChannel: MethodChannel
|
||||
|
||||
private var activity: Activity? = null
|
||||
private var context: Context? = null
|
||||
private var flClashVpnService: FlClashVpnService? = null
|
||||
private var isBound = false
|
||||
private var port: Int? = null
|
||||
private var port: Int = 7890
|
||||
private var props: Props? = null
|
||||
private lateinit var title: String
|
||||
private lateinit var content: String
|
||||
var isBlockNotification: Boolean = false
|
||||
private var isBlockNotification: Boolean = false
|
||||
private var isStart: Boolean = false
|
||||
|
||||
private val connection = object : ServiceConnection {
|
||||
override fun onServiceConnected(className: ComponentName, service: IBinder) {
|
||||
val binder = service as FlClashVpnService.LocalBinder
|
||||
flClashVpnService = binder.getService()
|
||||
port?.let { startVpn(it) }
|
||||
isBound = true
|
||||
if (isStart) {
|
||||
startVpn()
|
||||
} else {
|
||||
flClashVpnService?.initServiceEngine()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||
override fun onServiceDisconnected(arg: ComponentName) {
|
||||
flClashVpnService = null
|
||||
isBound = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,21 +67,29 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
}
|
||||
|
||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) = when (call.method) {
|
||||
"StartProxy" -> {
|
||||
port = call.argument<Int>("port")
|
||||
val args = call.argument<String>("args")
|
||||
props =
|
||||
if (args != null) Gson().fromJson(args, Props::class.java) else null
|
||||
handleStartVpn()
|
||||
"initService" -> {
|
||||
isStart = false
|
||||
initService()
|
||||
requestNotificationsPermission()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
"StopProxy" -> {
|
||||
"startProxy" -> {
|
||||
isStart = true
|
||||
port = call.argument<Int>("port")!!
|
||||
val args = call.argument<String>("args")
|
||||
props =
|
||||
if (args != null) Gson().fromJson(args, Props::class.java) else null
|
||||
startVpn()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
"stopProxy" -> {
|
||||
stopVpn()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
"SetProtect" -> {
|
||||
"setProtect" -> {
|
||||
val fd = call.argument<Int>("fd")
|
||||
if (fd != null) {
|
||||
flClashVpnService?.protect(fd)
|
||||
@@ -95,14 +99,10 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
}
|
||||
}
|
||||
|
||||
"GetRunTimeStamp" -> {
|
||||
result.success(GlobalState.runTime?.time)
|
||||
}
|
||||
|
||||
"startForeground" -> {
|
||||
title = call.argument<String>("title") as String
|
||||
content = call.argument<String>("content") as String
|
||||
requestNotificationsPermission()
|
||||
val title = call.argument<String>("title") as String
|
||||
val content = call.argument<String>("content") as String
|
||||
startForeground(title, content)
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
@@ -111,65 +111,41 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleStartVpn() {
|
||||
private fun initService() {
|
||||
val intent = VpnService.prepare(context)
|
||||
if (intent != null) {
|
||||
activity?.startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
||||
} else {
|
||||
bindService()
|
||||
if (flClashVpnService != null) {
|
||||
flClashVpnService!!.initServiceEngine()
|
||||
} else {
|
||||
bindService()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startVpn(port: Int) {
|
||||
if (GlobalState.runState.value == RunState.START) return;
|
||||
flClashVpnService?.start(port, props)
|
||||
private fun startVpn() {
|
||||
if (flClashVpnService == null) {
|
||||
bindService()
|
||||
return
|
||||
}
|
||||
if (GlobalState.runState.value == RunState.START) return
|
||||
GlobalState.runState.value = RunState.START
|
||||
GlobalState.runTime = Date()
|
||||
startAfter()
|
||||
flutterMethodChannel.invokeMethod("started", flClashVpnService?.start(port, props))
|
||||
}
|
||||
|
||||
private fun stopVpn() {
|
||||
if (GlobalState.runState.value == RunState.STOP) return
|
||||
GlobalState.runState.value = RunState.STOP
|
||||
flClashVpnService?.stop()
|
||||
unbindService()
|
||||
GlobalState.runState.value = RunState.STOP;
|
||||
GlobalState.runTime = null;
|
||||
GlobalState.destroyServiceEngine()
|
||||
}
|
||||
|
||||
private fun startForeground() {
|
||||
private fun startForeground(title: String, content: String) {
|
||||
if (GlobalState.runState.value != RunState.START) return
|
||||
flClashVpnService?.startForeground(title, content)
|
||||
}
|
||||
|
||||
private fun requestNotificationsPermission() {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
|
||||
val permission = context?.let {
|
||||
ContextCompat.checkSelfPermission(
|
||||
it,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
if (permission == PackageManager.PERMISSION_GRANTED) {
|
||||
startForeground()
|
||||
} else {
|
||||
if (isBlockNotification) return
|
||||
if (activity == null) return
|
||||
ActivityCompat.requestPermissions(
|
||||
activity!!,
|
||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||
NOTIFICATION_PERMISSION_REQUEST_CODE
|
||||
)
|
||||
|
||||
}
|
||||
} else {
|
||||
startForeground()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startAfter() {
|
||||
flutterMethodChannel.invokeMethod("startAfter", flClashVpnService?.fd)
|
||||
}
|
||||
|
||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||
activity = binding.activity
|
||||
binding.addActivityResultListener(::onActivityResult)
|
||||
@@ -184,7 +160,7 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
stopVpn()
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
|
||||
private fun onRequestPermissionsResultListener(
|
||||
@@ -194,18 +170,32 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
): Boolean {
|
||||
if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
|
||||
isBlockNotification = true
|
||||
if (grantResults.isNotEmpty()) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
startForeground()
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
private fun requestNotificationsPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
val permission = context?.let {
|
||||
ContextCompat.checkSelfPermission(
|
||||
it,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
if (isBlockNotification) return
|
||||
if (activity == null) return
|
||||
ActivityCompat.requestPermissions(
|
||||
activity!!,
|
||||
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
|
||||
NOTIFICATION_PERMISSION_REQUEST_CODE
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivityForConfigChanges() {
|
||||
activity = null;
|
||||
activity = null
|
||||
}
|
||||
|
||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||
@@ -213,7 +203,6 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivity() {
|
||||
stopVpn()
|
||||
activity = null
|
||||
}
|
||||
|
||||
@@ -221,11 +210,4 @@ class ProxyPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAwar
|
||||
val intent = Intent(context, FlClashVpnService::class.java)
|
||||
context?.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
|
||||
private fun unbindService() {
|
||||
if (isBound) {
|
||||
context?.unbindService(connection)
|
||||
isBound = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
package com.follow.clash.plugins
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.follow.clash.services
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
import androidx.annotation.RequiresApi
|
||||
@@ -11,14 +11,9 @@ import androidx.lifecycle.Observer
|
||||
import com.follow.clash.GlobalState
|
||||
import com.follow.clash.RunState
|
||||
import com.follow.clash.TempActivity
|
||||
import com.follow.clash.plugins.AppPlugin
|
||||
import com.follow.clash.plugins.ProxyPlugin
|
||||
import com.follow.clash.plugins.TilePlugin
|
||||
import io.flutter.FlutterInjector
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.embedding.engine.dart.DartExecutor
|
||||
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
class FlClashTileService : TileService() {
|
||||
|
||||
private val observer = Observer<RunState> { runState ->
|
||||
@@ -62,42 +57,25 @@ class FlClashTileService : TileService() {
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
startActivityAndCollapse(pendingIntent)
|
||||
}else{
|
||||
} else {
|
||||
startActivityAndCollapse(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private var flutterEngine: FlutterEngine? = null;
|
||||
|
||||
private fun initFlutterEngine() {
|
||||
flutterEngine = FlutterEngine(this)
|
||||
flutterEngine?.plugins?.add(ProxyPlugin())
|
||||
flutterEngine?.plugins?.add(TilePlugin())
|
||||
flutterEngine?.plugins?.add(AppPlugin())
|
||||
GlobalState.flutterEngine = flutterEngine
|
||||
if (flutterEngine?.dartExecutor?.isExecutingDart != true) {
|
||||
val vpnService = DartExecutor.DartEntrypoint(
|
||||
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
|
||||
"vpnService"
|
||||
)
|
||||
flutterEngine?.dartExecutor?.executeDartEntrypoint(vpnService)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
super.onClick()
|
||||
activityTransfer()
|
||||
val currentTilePlugin = GlobalState.getCurrentTilePlugin()
|
||||
if (GlobalState.runState.value == RunState.STOP) {
|
||||
GlobalState.runState.value = RunState.PENDING
|
||||
if(currentTilePlugin == null){
|
||||
initFlutterEngine()
|
||||
}else{
|
||||
currentTilePlugin.handleStart()
|
||||
val titlePlugin = GlobalState.getCurrentTitlePlugin()
|
||||
if (titlePlugin != null) {
|
||||
titlePlugin.handleStart()
|
||||
} else {
|
||||
GlobalState.initServiceEngine(this)
|
||||
}
|
||||
} else if(GlobalState.runState.value == RunState.START){
|
||||
} else if (GlobalState.runState.value == RunState.START) {
|
||||
GlobalState.runState.value = RunState.PENDING
|
||||
currentTilePlugin?.handleStop()
|
||||
GlobalState.getCurrentTitlePlugin()?.handleStop()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,8 @@ import com.follow.clash.models.Props
|
||||
|
||||
|
||||
class FlClashVpnService : VpnService() {
|
||||
|
||||
|
||||
private val CHANNEL = "FlClash"
|
||||
|
||||
var fd: Int? = null
|
||||
private val notificationId: Int = 1
|
||||
|
||||
private val passList = listOf(
|
||||
@@ -47,8 +44,13 @@ class FlClashVpnService : VpnService() {
|
||||
"192.168.*"
|
||||
)
|
||||
|
||||
fun start(port: Int, props: Props?) {
|
||||
fd = with(Builder()) {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
initServiceEngine()
|
||||
}
|
||||
|
||||
fun start(port: Int, props: Props?): Int? {
|
||||
return with(Builder()) {
|
||||
addAddress("172.16.0.1", 30)
|
||||
setMtu(9000)
|
||||
addRoute("0.0.0.0", 0)
|
||||
@@ -94,7 +96,6 @@ class FlClashVpnService : VpnService() {
|
||||
stopForeground()
|
||||
}
|
||||
|
||||
|
||||
private val notificationBuilder: NotificationCompat.Builder by lazy {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
|
||||
@@ -113,7 +114,6 @@ class FlClashVpnService : VpnService() {
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
}
|
||||
|
||||
with(NotificationCompat.Builder(this, CHANNEL)) {
|
||||
setSmallIcon(R.drawable.ic_stat_name)
|
||||
setContentTitle("FlClash")
|
||||
@@ -126,10 +126,14 @@ class FlClashVpnService : VpnService() {
|
||||
setOngoing(true)
|
||||
setShowWhen(false)
|
||||
setOnlyAlertOnce(true)
|
||||
setAutoCancel(true);
|
||||
setAutoCancel(true)
|
||||
}
|
||||
}
|
||||
|
||||
fun initServiceEngine() {
|
||||
GlobalState.initServiceEngine(this)
|
||||
}
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
super.onTrimMemory(level)
|
||||
GlobalState.getCurrentAppPlugin()?.requestGc()
|
||||
@@ -171,7 +175,6 @@ class FlClashVpnService : VpnService() {
|
||||
}
|
||||
|
||||
override fun onUnbind(intent: Intent?): Boolean {
|
||||
GlobalState.getCurrentTilePlugin()?.handleStop();
|
||||
return super.onUnbind(intent)
|
||||
}
|
||||
|
||||
|
||||
BIN
assets/data/GeoIP.dat
Normal file
BIN
assets/data/GeoIP.dat
Normal file
Binary file not shown.
Submodule core/Clash.Meta updated: 8a64960265...9def8ceda4
@@ -84,26 +84,11 @@ type TestDelayParams struct {
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
type Delay struct {
|
||||
Name string `json:"name"`
|
||||
Value int32 `json:"value"`
|
||||
}
|
||||
|
||||
type Process struct {
|
||||
Id int64 `json:"id"`
|
||||
Metadata *constant.Metadata `json:"metadata"`
|
||||
}
|
||||
|
||||
type ProcessMapItem struct {
|
||||
Id int64 `json:"id"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type Now struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type ExternalProvider struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
@@ -337,11 +322,11 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
|
||||
targetConfig.ExternalUIURL = ""
|
||||
targetConfig.TCPConcurrent = patchConfig.TCPConcurrent
|
||||
targetConfig.UnifiedDelay = patchConfig.UnifiedDelay
|
||||
targetConfig.GeodataMode = false
|
||||
//targetConfig.GeodataMode = false
|
||||
targetConfig.IPv6 = patchConfig.IPv6
|
||||
targetConfig.LogLevel = patchConfig.LogLevel
|
||||
targetConfig.Port = 0
|
||||
targetConfig.SocksPort = 0
|
||||
//targetConfig.Port = 0
|
||||
//targetConfig.SocksPort = 0
|
||||
targetConfig.MixedPort = patchConfig.MixedPort
|
||||
targetConfig.FindProcessMode = patchConfig.FindProcessMode
|
||||
targetConfig.AllowLan = patchConfig.AllowLan
|
||||
@@ -352,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
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func InitDartApi(api unsafe.Pointer) {
|
||||
}
|
||||
}
|
||||
|
||||
func SendToPort(port int64, msg string) {
|
||||
func SendToPort(port int64, msg string) bool {
|
||||
var obj C.Dart_CObject
|
||||
obj._type = C.Dart_CObject_kString
|
||||
msgString := C.CString(msg)
|
||||
@@ -34,6 +34,7 @@ func SendToPort(port int64, msg string) {
|
||||
*(**C.char)(ptr) = msgString
|
||||
isSuccess := C.GoDart_PostCObject(C.Dart_Port_DL(port), &obj)
|
||||
if !isSuccess {
|
||||
fmt.Println("ERROR: post to port ", port, " failed", msg)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package dart_bridge
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
var Port *int64
|
||||
|
||||
type MessageType string
|
||||
|
||||
const (
|
||||
Log MessageType = "log"
|
||||
Tun MessageType = "tun"
|
||||
Delay MessageType = "delay"
|
||||
Now MessageType = "now"
|
||||
Process MessageType = "process"
|
||||
Request MessageType = "request"
|
||||
Run MessageType = "run"
|
||||
Loaded MessageType = "loaded"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Type MessageType `json:"type"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func (message *Message) Json() (string, error) {
|
||||
data, err := json.Marshal(message)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
func SendMessage(message Message) {
|
||||
if Port == nil {
|
||||
return
|
||||
}
|
||||
s, err := message.Json()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
SendToPort(*Port, s)
|
||||
}
|
||||
53
core/hub.go
53
core/hub.go
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/metacubex/mihomo/adapter/provider"
|
||||
"github.com/metacubex/mihomo/common/structure"
|
||||
"github.com/metacubex/mihomo/common/utils"
|
||||
"github.com/metacubex/mihomo/component/geodata"
|
||||
"github.com/metacubex/mihomo/component/mmdb"
|
||||
"github.com/metacubex/mihomo/config"
|
||||
"github.com/metacubex/mihomo/constant"
|
||||
@@ -35,6 +36,8 @@ var configParams = ConfigExtendedParams{}
|
||||
|
||||
var isInit = false
|
||||
|
||||
var currentProfileName = ""
|
||||
|
||||
//export initClash
|
||||
func initClash(homeDirStr *C.char) bool {
|
||||
if !isInit {
|
||||
@@ -73,6 +76,16 @@ func forceGc() {
|
||||
}()
|
||||
}
|
||||
|
||||
//export setCurrentProfileName
|
||||
func setCurrentProfileName(s *C.char) {
|
||||
currentProfileName = C.GoString(s)
|
||||
}
|
||||
|
||||
//export getCurrentProfileName
|
||||
func getCurrentProfileName() *C.char {
|
||||
return C.CString(currentProfileName)
|
||||
}
|
||||
|
||||
//export validateConfig
|
||||
func validateConfig(s *C.char, port C.longlong) {
|
||||
i := int64(port)
|
||||
@@ -384,34 +397,44 @@ func updateExternalProvider(providerName *C.char, providerType *C.char, port C.l
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
case "GeoIp":
|
||||
case "MMDB":
|
||||
err := mmdb.DownloadMMDB(constant.Path.Resolve(providerNameString))
|
||||
if err != nil {
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
case "GeoSite":
|
||||
err := mmdb.DownloadGeoSite(constant.Path.Resolve(providerNameString))
|
||||
if err != nil {
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
case "ASN":
|
||||
err := mmdb.DownloadASN(constant.Path.Resolve(providerNameString))
|
||||
if err != nil {
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
case "GeoIp":
|
||||
err := geodata.DownloadGeoIP(constant.Path.Resolve(providerNameString))
|
||||
if err != nil {
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
case "GeoSite":
|
||||
err := geodata.DownloadGeoSite(constant.Path.Resolve(providerNameString))
|
||||
if err != nil {
|
||||
bridge.SendToPort(i, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
bridge.SendToPort(i, "")
|
||||
}()
|
||||
}
|
||||
|
||||
//export initNativeApiBridge
|
||||
func initNativeApiBridge(api unsafe.Pointer, port C.longlong) {
|
||||
func initNativeApiBridge(api unsafe.Pointer) {
|
||||
bridge.InitDartApi(api)
|
||||
}
|
||||
|
||||
//export initMessage
|
||||
func initMessage(port C.longlong) {
|
||||
i := int64(port)
|
||||
bridge.Port = &i
|
||||
Port = i
|
||||
}
|
||||
|
||||
//export freeCString
|
||||
@@ -429,20 +452,20 @@ func init() {
|
||||
} else {
|
||||
delayData.Value = int32(delay)
|
||||
}
|
||||
bridge.SendMessage(bridge.Message{
|
||||
Type: bridge.Delay,
|
||||
SendMessage(Message{
|
||||
Type: DelayMessage,
|
||||
Data: delayData,
|
||||
})
|
||||
}
|
||||
statistic.DefaultRequestNotify = func(c statistic.Tracker) {
|
||||
bridge.SendMessage(bridge.Message{
|
||||
Type: bridge.Request,
|
||||
SendMessage(Message{
|
||||
Type: RequestMessage,
|
||||
Data: c,
|
||||
})
|
||||
}
|
||||
executor.DefaultProxyProviderLoadedHook = func(providerName string) {
|
||||
bridge.SendMessage(bridge.Message{
|
||||
Type: bridge.Loaded,
|
||||
SendMessage(Message{
|
||||
Type: LoadedMessage,
|
||||
Data: providerName,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import "C"
|
||||
import (
|
||||
bridge "core/dart-bridge"
|
||||
"github.com/metacubex/mihomo/common/observable"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
)
|
||||
@@ -21,11 +20,11 @@ func startLog() {
|
||||
if logData.LogLevel < log.Level() {
|
||||
continue
|
||||
}
|
||||
message := &bridge.Message{
|
||||
Type: bridge.Log,
|
||||
message := &Message{
|
||||
Type: LogMessage,
|
||||
Data: logData,
|
||||
}
|
||||
bridge.SendMessage(*message)
|
||||
SendMessage(*message)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
77
core/message.go
Normal file
77
core/message.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
bridge "core/dart-bridge"
|
||||
"encoding/json"
|
||||
"github.com/metacubex/mihomo/constant"
|
||||
)
|
||||
|
||||
var Port int64
|
||||
var ServicePort int64
|
||||
|
||||
type MessageType string
|
||||
|
||||
const (
|
||||
LogMessage MessageType = "log"
|
||||
ProtectMessage MessageType = "protect"
|
||||
DelayMessage MessageType = "delay"
|
||||
ProcessMessage MessageType = "process"
|
||||
RequestMessage MessageType = "request"
|
||||
StartedMessage MessageType = "started"
|
||||
LoadedMessage MessageType = "loaded"
|
||||
)
|
||||
|
||||
type Delay struct {
|
||||
Name string `json:"name"`
|
||||
Value int32 `json:"value"`
|
||||
}
|
||||
|
||||
type Process struct {
|
||||
Id int64 `json:"id"`
|
||||
Metadata *constant.Metadata `json:"metadata"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
Type MessageType `json:"type"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func (message *Message) Json() (string, error) {
|
||||
data, err := json.Marshal(message)
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
func SendMessage(message Message) {
|
||||
s, err := message.Json()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if handler, ok := messageHandlers[message.Type]; ok {
|
||||
handler(s)
|
||||
} else {
|
||||
sendToPort(s)
|
||||
}
|
||||
}
|
||||
|
||||
var messageHandlers = map[MessageType]func(string) bool{
|
||||
ProtectMessage: sendToServicePort,
|
||||
ProcessMessage: sendToServicePort,
|
||||
StartedMessage: conditionalSend,
|
||||
LoadedMessage: conditionalSend,
|
||||
}
|
||||
|
||||
func sendToPort(s string) bool {
|
||||
return bridge.SendToPort(Port, s)
|
||||
}
|
||||
|
||||
func sendToServicePort(s string) bool {
|
||||
return bridge.SendToPort(ServicePort, s)
|
||||
}
|
||||
|
||||
func conditionalSend(s string) bool {
|
||||
isSuccess := sendToPort(s)
|
||||
if !isSuccess {
|
||||
return sendToServicePort(s)
|
||||
}
|
||||
return isSuccess
|
||||
}
|
||||
@@ -4,7 +4,6 @@ package main
|
||||
|
||||
import "C"
|
||||
import (
|
||||
bridge "core/dart-bridge"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/metacubex/mihomo/component/process"
|
||||
@@ -43,8 +42,8 @@ func init() {
|
||||
|
||||
timeout := time.After(200 * time.Millisecond)
|
||||
|
||||
bridge.SendMessage(bridge.Message{
|
||||
Type: bridge.Process,
|
||||
SendMessage(Message{
|
||||
Type: ProcessMessage,
|
||||
Data: Process{
|
||||
Id: id,
|
||||
Metadata: metadata,
|
||||
|
||||
41
core/tun.go
41
core/tun.go
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/metacubex/mihomo/component/dialer"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
"golang.org/x/sync/semaphore"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
|
||||
var tunLock sync.Mutex
|
||||
var tun *t.Tun
|
||||
var runTime *time.Time
|
||||
|
||||
type FdMap struct {
|
||||
m sync.Map
|
||||
@@ -35,7 +37,9 @@ func (cm *FdMap) Load(key int64) bool {
|
||||
var fdMap FdMap
|
||||
|
||||
//export startTUN
|
||||
func startTUN(fd C.int) {
|
||||
func startTUN(fd C.int, port C.longlong) {
|
||||
i := int64(port)
|
||||
ServicePort = i
|
||||
go func() {
|
||||
tunLock.Lock()
|
||||
defer tunLock.Unlock()
|
||||
@@ -44,6 +48,7 @@ func startTUN(fd C.int) {
|
||||
tun.Close()
|
||||
tun = nil
|
||||
}
|
||||
|
||||
f := int(fd)
|
||||
gateway := "172.16.0.1/30"
|
||||
portal := "172.16.0.2"
|
||||
@@ -61,15 +66,34 @@ func startTUN(fd C.int) {
|
||||
tempTun.Closer = closer
|
||||
|
||||
tun = tempTun
|
||||
|
||||
now := time.Now()
|
||||
|
||||
runTime = &now
|
||||
|
||||
SendMessage(Message{
|
||||
Type: StartedMessage,
|
||||
Data: strconv.FormatInt(runTime.UnixMilli(), 10),
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
//export getRunTime
|
||||
func getRunTime() *C.char {
|
||||
if runTime == nil {
|
||||
return C.CString("")
|
||||
}
|
||||
return C.CString(strconv.FormatInt(runTime.UnixMilli(), 10))
|
||||
}
|
||||
|
||||
//export stopTun
|
||||
func stopTun() {
|
||||
go func() {
|
||||
tunLock.Lock()
|
||||
defer tunLock.Unlock()
|
||||
|
||||
runTime = nil
|
||||
|
||||
if tun != nil {
|
||||
tun.Close()
|
||||
tun = nil
|
||||
@@ -87,6 +111,18 @@ func setFdMap(fd C.long) {
|
||||
}()
|
||||
}
|
||||
|
||||
type Fd struct {
|
||||
Id int64 `json:"id"`
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
func markSocket(fd Fd) {
|
||||
SendMessage(Message{
|
||||
Type: ProtectMessage,
|
||||
Data: fd,
|
||||
})
|
||||
}
|
||||
|
||||
var fdCounter int64 = 0
|
||||
|
||||
func init() {
|
||||
@@ -102,7 +138,8 @@ func init() {
|
||||
fdInt := int64(fd)
|
||||
timeout := time.After(100 * time.Millisecond)
|
||||
id := atomic.AddInt64(&fdCounter, 1)
|
||||
tun.MarkSocket(t.Fd{
|
||||
|
||||
markSocket(Fd{
|
||||
Id: id,
|
||||
Value: fdInt,
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ package tun
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
bridge "core/dart-bridge"
|
||||
"encoding/binary"
|
||||
"github.com/Kr328/tun2socket"
|
||||
"github.com/Kr328/tun2socket/nat"
|
||||
@@ -185,24 +184,3 @@ func Start(fd int, gateway, portal, dns string) (io.Closer, error) {
|
||||
|
||||
return stack, nil
|
||||
}
|
||||
|
||||
type Fd struct {
|
||||
Id int64 `json:"id"`
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
func (t *Tun) MarkSocket(fd Fd) {
|
||||
_ = t.Limit.Acquire(context.Background(), 1)
|
||||
defer t.Limit.Release(1)
|
||||
|
||||
if t.Closed {
|
||||
return
|
||||
}
|
||||
|
||||
message := &bridge.Message{
|
||||
Type: bridge.Tun,
|
||||
Data: fd,
|
||||
}
|
||||
|
||||
bridge.SendMessage(*message)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ class ClashCore {
|
||||
clashFFI = ClashFFI(lib);
|
||||
clashFFI.initNativeApiBridge(
|
||||
NativeApi.initializeApiDLData,
|
||||
receiver.sendPort.nativePort,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,6 +94,28 @@ class ClashCore {
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
initMessage() {
|
||||
clashFFI.initMessage(
|
||||
receiver.sendPort.nativePort,
|
||||
);
|
||||
}
|
||||
|
||||
setProfileName(String profileName) {
|
||||
final profileNameChar = profileName.toNativeUtf8().cast<Char>();
|
||||
clashFFI.setCurrentProfileName(
|
||||
profileNameChar,
|
||||
);
|
||||
malloc.free(profileNameChar);
|
||||
}
|
||||
|
||||
getProfileName() {
|
||||
final currentProfileNameRaw = clashFFI.getCurrentProfileName();
|
||||
final currentProfileName =
|
||||
currentProfileNameRaw.cast<Utf8>().toDartString();
|
||||
clashFFI.freeCString(currentProfileNameRaw);
|
||||
return currentProfileName;
|
||||
}
|
||||
|
||||
Future<List<Group>> getProxiesGroups() {
|
||||
final proxiesRaw = clashFFI.getProxies();
|
||||
final proxiesRawString = proxiesRaw.cast<Utf8>().toDartString();
|
||||
@@ -242,8 +263,9 @@ class ClashCore {
|
||||
clashFFI.stopLog();
|
||||
}
|
||||
|
||||
startTun(int fd) {
|
||||
clashFFI.startTUN(fd);
|
||||
startTun(int fd, int port) {
|
||||
if (!Platform.isAndroid) return;
|
||||
clashFFI.startTUN(fd, port);
|
||||
}
|
||||
|
||||
requestGc() {
|
||||
@@ -265,11 +287,13 @@ class ClashCore {
|
||||
clashFFI.setFdMap(fd);
|
||||
}
|
||||
|
||||
// DateTime? getRunTime() {
|
||||
// final runTimeString = clashFFI.getRunTime().cast<Utf8>().toDartString();
|
||||
// if (runTimeString.isEmpty) return null;
|
||||
// return DateTime.fromMillisecondsSinceEpoch(int.parse(runTimeString));
|
||||
// }
|
||||
DateTime? getRunTime() {
|
||||
final runTimeRaw = clashFFI.getRunTime();
|
||||
final runTimeString = runTimeRaw.cast<Utf8>().toDartString();
|
||||
clashFFI.freeCString(runTimeRaw);
|
||||
if (runTimeString.isEmpty) return null;
|
||||
return DateTime.fromMillisecondsSinceEpoch(int.parse(runTimeString));
|
||||
}
|
||||
|
||||
List<Connection> getConnections() {
|
||||
final connectionsDataRaw = clashFFI.getConnections();
|
||||
|
||||
@@ -5190,6 +5190,30 @@ class ClashFFI {
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function()>>('forceGc');
|
||||
late final _forceGc = _forceGcPtr.asFunction<void Function()>();
|
||||
|
||||
void setCurrentProfileName(
|
||||
ffi.Pointer<ffi.Char> s,
|
||||
) {
|
||||
return _setCurrentProfileName(
|
||||
s,
|
||||
);
|
||||
}
|
||||
|
||||
late final _setCurrentProfileNamePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Char>)>>(
|
||||
'setCurrentProfileName');
|
||||
late final _setCurrentProfileName = _setCurrentProfileNamePtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Char>)>();
|
||||
|
||||
ffi.Pointer<ffi.Char> getCurrentProfileName() {
|
||||
return _getCurrentProfileName();
|
||||
}
|
||||
|
||||
late final _getCurrentProfileNamePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>(
|
||||
'getCurrentProfileName');
|
||||
late final _getCurrentProfileName =
|
||||
_getCurrentProfileNamePtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
|
||||
|
||||
void validateConfig(
|
||||
ffi.Pointer<ffi.Char> s,
|
||||
int port,
|
||||
@@ -5406,20 +5430,30 @@ class ClashFFI {
|
||||
|
||||
void initNativeApiBridge(
|
||||
ffi.Pointer<ffi.Void> api,
|
||||
int port,
|
||||
) {
|
||||
return _initNativeApiBridge(
|
||||
api,
|
||||
);
|
||||
}
|
||||
|
||||
late final _initNativeApiBridgePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
|
||||
'initNativeApiBridge');
|
||||
late final _initNativeApiBridge = _initNativeApiBridgePtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
void initMessage(
|
||||
int port,
|
||||
) {
|
||||
return _initMessage(
|
||||
port,
|
||||
);
|
||||
}
|
||||
|
||||
late final _initNativeApiBridgePtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.Void>, ffi.LongLong)>>('initNativeApiBridge');
|
||||
late final _initNativeApiBridge = _initNativeApiBridgePtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Void>, int)>();
|
||||
late final _initMessagePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.LongLong)>>(
|
||||
'initMessage');
|
||||
late final _initMessage = _initMessagePtr.asFunction<void Function(int)>();
|
||||
|
||||
void freeCString(
|
||||
ffi.Pointer<ffi.Char> s,
|
||||
@@ -5467,15 +5501,28 @@ class ClashFFI {
|
||||
|
||||
void startTUN(
|
||||
int fd,
|
||||
int port,
|
||||
) {
|
||||
return _startTUN(
|
||||
fd,
|
||||
port,
|
||||
);
|
||||
}
|
||||
|
||||
late final _startTUNPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int)>>('startTUN');
|
||||
late final _startTUN = _startTUNPtr.asFunction<void Function(int)>();
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int, ffi.LongLong)>>(
|
||||
'startTUN');
|
||||
late final _startTUN = _startTUNPtr.asFunction<void Function(int, int)>();
|
||||
|
||||
ffi.Pointer<ffi.Char> getRunTime() {
|
||||
return _getRunTime();
|
||||
}
|
||||
|
||||
late final _getRunTimePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>(
|
||||
'getRunTime');
|
||||
late final _getRunTime =
|
||||
_getRunTimePtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
|
||||
|
||||
void stopTun() {
|
||||
return _stopTun();
|
||||
|
||||
@@ -7,24 +7,6 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'core.dart';
|
||||
|
||||
abstract mixin class ClashMessageListener {
|
||||
void onLog(Log log) {}
|
||||
|
||||
void onTun(Fd fd) {}
|
||||
|
||||
void onDelay(Delay delay) {}
|
||||
|
||||
void onProcess(Process process) {}
|
||||
|
||||
void onRequest(Connection connection) {}
|
||||
|
||||
void onNow(Now now) {}
|
||||
|
||||
void onRun(String runTime) {}
|
||||
|
||||
void onLoaded(String groupName) {}
|
||||
}
|
||||
|
||||
class ClashMessage {
|
||||
StreamSubscription? subscription;
|
||||
|
||||
@@ -34,31 +16,22 @@ class ClashMessage {
|
||||
subscription = null;
|
||||
}
|
||||
subscription = ClashCore.receiver.listen((message) {
|
||||
final m = Message.fromJson(json.decode(message));
|
||||
for (final ClashMessageListener listener in _listeners) {
|
||||
final m = AppMessage.fromJson(json.decode(message));
|
||||
for (final AppMessageListener listener in _listeners) {
|
||||
switch (m.type) {
|
||||
case MessageType.log:
|
||||
case AppMessageType.log:
|
||||
listener.onLog(Log.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.tun:
|
||||
listener.onTun(Fd.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.delay:
|
||||
case AppMessageType.delay:
|
||||
listener.onDelay(Delay.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.process:
|
||||
listener.onProcess(Process.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.now:
|
||||
listener.onNow(Now.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.request:
|
||||
case AppMessageType.request:
|
||||
listener.onRequest(Connection.fromJson(m.data));
|
||||
break;
|
||||
case MessageType.run:
|
||||
listener.onRun(m.data);
|
||||
case AppMessageType.started:
|
||||
listener.onStarted(m.data);
|
||||
break;
|
||||
case MessageType.loaded:
|
||||
case AppMessageType.loaded:
|
||||
listener.onLoaded(m.data);
|
||||
break;
|
||||
}
|
||||
@@ -68,18 +41,18 @@ class ClashMessage {
|
||||
|
||||
static final ClashMessage instance = ClashMessage._();
|
||||
|
||||
final ObserverList<ClashMessageListener> _listeners =
|
||||
ObserverList<ClashMessageListener>();
|
||||
final ObserverList<AppMessageListener> _listeners =
|
||||
ObserverList<AppMessageListener>();
|
||||
|
||||
bool get hasListeners {
|
||||
return _listeners.isNotEmpty;
|
||||
}
|
||||
|
||||
void addListener(ClashMessageListener listener) {
|
||||
void addListener(AppMessageListener listener) {
|
||||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
void removeListener(ClashMessageListener listener) {
|
||||
void removeListener(AppMessageListener listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class ClashService {
|
||||
}
|
||||
const geoFileNameList = [
|
||||
mmdbFileName,
|
||||
geoIpFileName,
|
||||
geoSiteFileName,
|
||||
asnFileName,
|
||||
];
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fl_clash/clash/clash.dart';
|
||||
import 'package:fl_clash/plugins/app.dart';
|
||||
|
||||
class Android {
|
||||
init() async {
|
||||
app?.onExit = () {
|
||||
clashCore.shutdown();
|
||||
exit(0);
|
||||
};
|
||||
app?.onExit = () {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fl_clash/models/clash_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const appName = "FlClash";
|
||||
@@ -10,8 +11,15 @@ const moreDuration = Duration(milliseconds: 100);
|
||||
const animateDuration = Duration(milliseconds: 100);
|
||||
const defaultUpdateDuration = Duration(days: 1);
|
||||
const mmdbFileName = "geoip.metadb";
|
||||
const geoSiteFileName = "GeoSite.dat";
|
||||
const asnFileName = "ASN.mmdb";
|
||||
const geoIpFileName = "GeoIP.dat";
|
||||
const geoSiteFileName = "GeoSite.dat";
|
||||
const GeoXMap defaultGeoXMap = {
|
||||
"mmdb":"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb",
|
||||
"asn":"https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb",
|
||||
"geoip":"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoIP.dat",
|
||||
"geosite":"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat"
|
||||
};
|
||||
const profilesDirectoryName = "profiles";
|
||||
const localhost = "127.0.0.1";
|
||||
const clashConfigKey = "clash_config";
|
||||
|
||||
@@ -39,6 +39,9 @@ class Other {
|
||||
}
|
||||
final diff = timeStamp / 1000;
|
||||
final inHours = (diff / 3600).floor();
|
||||
if (inHours > 99) {
|
||||
return "99:59:59";
|
||||
}
|
||||
final inMinutes = (diff / 60 % 60).floor();
|
||||
final inSeconds = (diff % 60).floor();
|
||||
|
||||
@@ -171,7 +174,7 @@ class Other {
|
||||
}
|
||||
|
||||
List<String> parseReleaseBody(String? body) {
|
||||
if(body == null) return [];
|
||||
if (body == null) return [];
|
||||
const pattern = r'- (.+?)\. \[.+?\]';
|
||||
final regex = RegExp(pattern);
|
||||
return regex
|
||||
@@ -181,7 +184,7 @@ class Other {
|
||||
.toList();
|
||||
}
|
||||
|
||||
ViewMode getViewMode(double viewWidth){
|
||||
ViewMode getViewMode(double viewWidth) {
|
||||
if (viewWidth <= maxMobileWidth) return ViewMode.mobile;
|
||||
if (viewWidth <= maxLaptopWidth) return ViewMode.laptop;
|
||||
return ViewMode.desktop;
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'common.dart';
|
||||
extension PackageInfoExtension on PackageInfo {
|
||||
String get ua => [
|
||||
"$appName/v$version",
|
||||
"clash-verge/v1.6.6",
|
||||
"clash-verge",
|
||||
"Platform/${Platform.operatingSystem}",
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
@@ -28,20 +28,6 @@ class ProxyManager {
|
||||
return await (_proxy as Proxy).updateStartTime();
|
||||
}
|
||||
|
||||
Future<bool?> setProtect(int fd) async {
|
||||
if (_proxy is! Proxy) return null;
|
||||
return await (_proxy as Proxy).setProtect(fd);
|
||||
}
|
||||
|
||||
Future<bool?> startForeground({
|
||||
required String title,
|
||||
required String content,
|
||||
}) async {
|
||||
if (_proxy is! Proxy) return null;
|
||||
return await (_proxy as Proxy)
|
||||
.startForeground(title: title, content: content);
|
||||
}
|
||||
|
||||
factory ProxyManager() {
|
||||
_instance ??= ProxyManager._internal();
|
||||
return _instance!;
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
extension StringExtension on String {
|
||||
bool get isUrl {
|
||||
return RegExp(
|
||||
r'^(https?:\/\/)?'
|
||||
r'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'
|
||||
r'((\d{1,3}\.){3}\d{1,3}))'
|
||||
r'(:\d+)?'
|
||||
r'(\/[-a-z\d%_.~+]*)*'
|
||||
r'(\?[;&a-z\d%_.~+=-]*)?'
|
||||
r'(\#[-a-z\d_]*)?$',
|
||||
caseSensitive: false,
|
||||
).hasMatch(this);
|
||||
return RegExp(r'^(http|https|ftp)://').hasMatch(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class AppController {
|
||||
updateClashConfigDebounce = debounce<Function()>(() async {
|
||||
await updateClashConfig();
|
||||
});
|
||||
addCheckIpNumDebounce = debounce((){
|
||||
addCheckIpNumDebounce = debounce(() {
|
||||
appState.checkIpNum++;
|
||||
});
|
||||
measure = Measure.of(context);
|
||||
@@ -70,7 +70,6 @@ class AppController {
|
||||
|
||||
updateTraffic() {
|
||||
globalState.updateTraffic(
|
||||
config: config,
|
||||
appState: appState,
|
||||
);
|
||||
}
|
||||
@@ -121,6 +120,14 @@ class AppController {
|
||||
});
|
||||
}
|
||||
|
||||
Future rawApplyProfile() async {
|
||||
await globalState.applyProfile(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
}
|
||||
|
||||
changeProfile(String? value) async {
|
||||
if (value == config.currentProfileId) return;
|
||||
config.currentProfileId = value;
|
||||
|
||||
@@ -56,14 +56,18 @@ enum ProfileType { file, url }
|
||||
|
||||
enum ResultType { success, error }
|
||||
|
||||
enum MessageType {
|
||||
enum AppMessageType {
|
||||
log,
|
||||
tun,
|
||||
delay,
|
||||
process,
|
||||
now,
|
||||
request,
|
||||
run,
|
||||
started,
|
||||
loaded,
|
||||
}
|
||||
|
||||
enum ServiceMessageType {
|
||||
protect,
|
||||
process,
|
||||
started,
|
||||
loaded,
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ class _AccessFragmentState extends State<AccessFragment> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@@ -112,55 +111,48 @@ class _AccessFragmentState extends State<AccessFragment> {
|
||||
);
|
||||
}
|
||||
|
||||
_buildSelectedAllButton({
|
||||
Widget _buildSelectedAllButton({
|
||||
required bool isAccessControl,
|
||||
required bool isSelectedAll,
|
||||
required List<String> allValueList,
|
||||
}) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final tooltip = isSelectedAll
|
||||
? appLocalizations.cancelSelectAll
|
||||
: appLocalizations.selectAll;
|
||||
final commonScaffoldState =
|
||||
context.findAncestorStateOfType<CommonScaffoldState>();
|
||||
commonScaffoldState?.floatingActionButton = DisabledMask(
|
||||
status: !isAccessControl,
|
||||
child: AbsorbPointer(
|
||||
absorbing: !isAccessControl,
|
||||
child: FloatingActionButton (
|
||||
tooltip: tooltip,
|
||||
onPressed: () {
|
||||
final config = globalState.appController.config;
|
||||
final isAccept =
|
||||
config.accessControl.mode == AccessControlMode.acceptSelected;
|
||||
final tooltip = isSelectedAll
|
||||
? appLocalizations.cancelSelectAll
|
||||
: appLocalizations.selectAll;
|
||||
return AbsorbPointer(
|
||||
absorbing: !isAccessControl,
|
||||
child: FloatingActionButton(
|
||||
tooltip: tooltip,
|
||||
onPressed: () {
|
||||
final config = globalState.appController.config;
|
||||
final isAccept =
|
||||
config.accessControl.mode == AccessControlMode.acceptSelected;
|
||||
|
||||
if (isSelectedAll) {
|
||||
config.accessControl = switch (isAccept) {
|
||||
true => config.accessControl.copyWith(
|
||||
acceptList: [],
|
||||
),
|
||||
false => config.accessControl.copyWith(
|
||||
rejectList: [],
|
||||
),
|
||||
};
|
||||
} else {
|
||||
config.accessControl = switch (isAccept) {
|
||||
true => config.accessControl.copyWith(
|
||||
acceptList: allValueList,
|
||||
),
|
||||
false => config.accessControl.copyWith(
|
||||
rejectList: allValueList,
|
||||
),
|
||||
};
|
||||
}
|
||||
},
|
||||
child: isSelectedAll
|
||||
? const Icon(Icons.deselect)
|
||||
: const Icon(Icons.select_all),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
if (isSelectedAll) {
|
||||
config.accessControl = switch (isAccept) {
|
||||
true => config.accessControl.copyWith(
|
||||
acceptList: [],
|
||||
),
|
||||
false => config.accessControl.copyWith(
|
||||
rejectList: [],
|
||||
),
|
||||
};
|
||||
} else {
|
||||
config.accessControl = switch (isAccept) {
|
||||
true => config.accessControl.copyWith(
|
||||
acceptList: allValueList,
|
||||
),
|
||||
false => config.accessControl.copyWith(
|
||||
rejectList: allValueList,
|
||||
),
|
||||
};
|
||||
}
|
||||
},
|
||||
child: isSelectedAll
|
||||
? const Icon(Icons.deselect)
|
||||
: const Icon(Icons.select_all),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPackageList() {
|
||||
@@ -213,137 +205,141 @@ class _AccessFragmentState extends State<AccessFragment> {
|
||||
accessControlMode == AccessControlMode.acceptSelected
|
||||
? appLocalizations.accessControlAllowDesc
|
||||
: appLocalizations.accessControlNotAllowDesc;
|
||||
_buildSelectedAllButton(
|
||||
isAccessControl: isAccessControl,
|
||||
isSelectedAll: valueList.length == packageNameList.length,
|
||||
allValueList: packageNameList,
|
||||
);
|
||||
return DisabledMask(
|
||||
status: !isAccessControl,
|
||||
child: Column(
|
||||
children: [
|
||||
AbsorbPointer(
|
||||
absorbing: !isAccessControl,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
left: 16,
|
||||
right: 8,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Expanded(
|
||||
child: IntrinsicHeight(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
appLocalizations.selected,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
child: FloatLayout(
|
||||
floatingWidget: FloatWrapper(
|
||||
child: _buildSelectedAllButton(
|
||||
isAccessControl: isAccessControl,
|
||||
isSelectedAll: valueList.length == packageNameList.length,
|
||||
allValueList: packageNameList,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
AbsorbPointer(
|
||||
absorbing: !isAccessControl,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
bottom: 4,
|
||||
left: 16,
|
||||
right: 8,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Expanded(
|
||||
child: IntrinsicHeight(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
appLocalizations.selected,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
width: 8,
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
"${valueList.length}",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
"${valueList.length}",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.labelLarge
|
||||
?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(describe),
|
||||
)
|
||||
],
|
||||
Flexible(
|
||||
child: Text(describe),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Flexible(
|
||||
child: _buildSearchButton(currentPackages)),
|
||||
Flexible(child: _buildFilterSystemAppButton()),
|
||||
Flexible(child: _buildAppProxyModePopup()),
|
||||
],
|
||||
),
|
||||
],
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Flexible(
|
||||
child: _buildSearchButton(currentPackages)),
|
||||
Flexible(child: _buildFilterSystemAppButton()),
|
||||
Flexible(child: _buildAppProxyModePopup()),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: FadeBox(
|
||||
key: const Key("fade_box"),
|
||||
child: currentPackages.isEmpty
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: currentPackages.length,
|
||||
itemBuilder: (_, index) {
|
||||
final package = currentPackages[index];
|
||||
return PackageListItem(
|
||||
key: Key(package.packageName),
|
||||
package: package,
|
||||
value:
|
||||
valueList.contains(package.packageName),
|
||||
isActive: isAccessControl,
|
||||
onChanged: (value) {
|
||||
if (value == true) {
|
||||
valueList.add(package.packageName);
|
||||
} else {
|
||||
valueList.remove(package.packageName);
|
||||
}
|
||||
final config =
|
||||
globalState.appController.config;
|
||||
if (accessControlMode ==
|
||||
AccessControlMode.acceptSelected) {
|
||||
config.accessControl =
|
||||
config.accessControl.copyWith(
|
||||
acceptList: valueList,
|
||||
);
|
||||
} else {
|
||||
config.accessControl =
|
||||
config.accessControl.copyWith(
|
||||
rejectList: valueList,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: FadeBox(
|
||||
key: const Key("fade_box"),
|
||||
child: currentPackages.isEmpty
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: currentPackages.length,
|
||||
itemBuilder: (_, index) {
|
||||
final package = currentPackages[index];
|
||||
return PackageListItem(
|
||||
key: Key(package.packageName),
|
||||
package: package,
|
||||
value:
|
||||
valueList.contains(package.packageName),
|
||||
isActive: isAccessControl,
|
||||
onChanged: (value) {
|
||||
if (value == true) {
|
||||
valueList.add(package.packageName);
|
||||
} else {
|
||||
valueList.remove(package.packageName);
|
||||
}
|
||||
final config =
|
||||
globalState.appController.config;
|
||||
if (accessControlMode ==
|
||||
AccessControlMode.acceptSelected) {
|
||||
config.accessControl =
|
||||
config.accessControl.copyWith(
|
||||
acceptList: valueList,
|
||||
);
|
||||
} else {
|
||||
config.accessControl =
|
||||
config.accessControl.copyWith(
|
||||
rejectList: valueList,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -89,6 +89,24 @@ class ApplicationSettingFragment extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
if (Platform.isAndroid)
|
||||
Selector<Config, bool>(
|
||||
selector: (_, config) => config.isExclude,
|
||||
builder: (_, isExclude, child) {
|
||||
return ListItem.switchItem(
|
||||
leading: const Icon(Icons.visibility_off),
|
||||
title: Text(appLocalizations.exclude),
|
||||
subtitle: Text(appLocalizations.excludeDesc),
|
||||
delegate: SwitchDelegate(
|
||||
value: isExclude,
|
||||
onChanged: (value) {
|
||||
final config = context.read<Config>();
|
||||
config.isExclude = value;
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (Platform.isAndroid)
|
||||
Selector<Config, bool>(
|
||||
selector: (_, config) => config.isAnimateToPage,
|
||||
|
||||
@@ -35,7 +35,7 @@ class _BackupAndRecoveryState extends State<BackupAndRecovery> {
|
||||
});
|
||||
if (res != true) return;
|
||||
globalState.showMessage(
|
||||
title: appLocalizations.recovery,
|
||||
title: appLocalizations.backup,
|
||||
message: TextSpan(text: appLocalizations.backupSuccess),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class OutboundMode extends StatelessWidget {
|
||||
if (value == null || clashConfig.mode == value) return;
|
||||
clashConfig.mode = value;
|
||||
await appController.updateClashConfig();
|
||||
appController.addCheckIpNumDebounce();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -76,13 +76,6 @@ class _ProfilesFragmentState extends State<ProfilesFragment> {
|
||||
width: 8,
|
||||
)
|
||||
];
|
||||
commonScaffoldState?.floatingActionButton = FloatingActionButton(
|
||||
heroTag: null,
|
||||
onPressed: _handleShowAddExtendPage,
|
||||
child: const Icon(
|
||||
Icons.add,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -113,74 +106,86 @@ class _ProfilesFragmentState extends State<ProfilesFragment> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Selector<AppState, bool>(
|
||||
selector: (_, appState) => appState.currentLabel == 'profiles',
|
||||
builder: (_, isCurrent, child) {
|
||||
if (isCurrent) {
|
||||
_initScaffoldState();
|
||||
}
|
||||
return child!;
|
||||
},
|
||||
child: Selector2<AppState, Config, ProfilesSelectorState>(
|
||||
selector: (_, appState, config) => ProfilesSelectorState(
|
||||
profiles: config.profiles,
|
||||
currentProfileId: config.currentProfileId,
|
||||
viewMode: appState.viewMode,
|
||||
return FloatLayout(
|
||||
floatingWidget: FloatWrapper(
|
||||
child: FloatingActionButton(
|
||||
heroTag: null,
|
||||
onPressed: _handleShowAddExtendPage,
|
||||
child: const Icon(
|
||||
Icons.add,
|
||||
),
|
||||
),
|
||||
builder: (context, state, child) {
|
||||
if (state.profiles.isEmpty) {
|
||||
return NullStatus(
|
||||
label: appLocalizations.nullProfileDesc,
|
||||
);
|
||||
),
|
||||
child: Selector<AppState, bool>(
|
||||
selector: (_, appState) => appState.currentLabel == 'profiles',
|
||||
builder: (_, isCurrent, child) {
|
||||
if (isCurrent) {
|
||||
_initScaffoldState();
|
||||
}
|
||||
profileItemKeys = state.profiles
|
||||
.map((profile) => GlobalObjectKey<_ProfileItemState>(profile.id))
|
||||
.toList();
|
||||
final columns = _getColumns(state.viewMode);
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (scrollNotification) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) {
|
||||
hasPadding.value =
|
||||
scrollNotification.metrics.maxScrollExtent > 0;
|
||||
},
|
||||
);
|
||||
return true;
|
||||
},
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: hasPadding,
|
||||
builder: (_, hasPadding, __) {
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
bottom: 16 + (hasPadding ? 56 : 0),
|
||||
),
|
||||
child: Grid(
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
crossAxisCount: columns,
|
||||
children: [
|
||||
for (int i = 0; i < state.profiles.length; i++)
|
||||
GridItem(
|
||||
child: ProfileItem(
|
||||
key: profileItemKeys[i],
|
||||
profile: state.profiles[i],
|
||||
groupValue: state.currentProfileId,
|
||||
onChanged: _changeProfile,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return child!;
|
||||
},
|
||||
child: Selector2<AppState, Config, ProfilesSelectorState>(
|
||||
selector: (_, appState, config) => ProfilesSelectorState(
|
||||
profiles: config.profiles,
|
||||
currentProfileId: config.currentProfileId,
|
||||
viewMode: appState.viewMode,
|
||||
),
|
||||
builder: (context, state, child) {
|
||||
if (state.profiles.isEmpty) {
|
||||
return NullStatus(
|
||||
label: appLocalizations.nullProfileDesc,
|
||||
);
|
||||
}
|
||||
profileItemKeys = state.profiles
|
||||
.map(
|
||||
(profile) => GlobalObjectKey<_ProfileItemState>(profile.id))
|
||||
.toList();
|
||||
final columns = _getColumns(state.viewMode);
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (scrollNotification) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) {
|
||||
hasPadding.value =
|
||||
scrollNotification.metrics.maxScrollExtent > 0;
|
||||
},
|
||||
);
|
||||
return true;
|
||||
},
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: hasPadding,
|
||||
builder: (_, hasPadding, __) {
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
bottom: 16 + (hasPadding ? 56 : 0),
|
||||
),
|
||||
child: Grid(
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
crossAxisCount: columns,
|
||||
children: [
|
||||
for (int i = 0; i < state.profiles.length; i++)
|
||||
GridItem(
|
||||
child: ProfileItem(
|
||||
key: profileItemKeys[i],
|
||||
profile: state.profiles[i],
|
||||
groupValue: state.currentProfileId,
|
||||
onChanged: _changeProfile,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -216,7 +221,12 @@ class _ProfileItemState extends State<ProfileItem> {
|
||||
Future updateProfile([isSingle = true]) async {
|
||||
isUpdating.value = true;
|
||||
try {
|
||||
await globalState.appController.updateProfile(widget.profile);
|
||||
final appController = globalState.appController;
|
||||
await appController.updateProfile(widget.profile);
|
||||
if (widget.profile.id == appController.config.currentProfile?.id &&
|
||||
!appController.appState.isStart) {
|
||||
globalState.appController.rawApplyProfile();
|
||||
}
|
||||
} catch (e) {
|
||||
isUpdating.value = false;
|
||||
if (!isSingle) {
|
||||
|
||||
@@ -387,7 +387,6 @@ class _ProxyGroupViewState extends State<ProxyGroupView> {
|
||||
final lines = (sortedProxies.length / columns).ceil();
|
||||
final minLines =
|
||||
innerHeight >= 200 ? (innerHeight / itemHeight).floor() : 3;
|
||||
final hasScrollable = lines > minLines;
|
||||
final height = (itemHeight + 8) * min(lines, minLines) - 8;
|
||||
return Selector<Config, Set<String>>(
|
||||
selector: (_, config) => config.currentUnfoldSet,
|
||||
|
||||
@@ -7,14 +7,17 @@ import 'package:fl_clash/state.dart';
|
||||
import 'package:fl_clash/widgets/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' hide context;
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@immutable
|
||||
class GeoItem {
|
||||
final String label;
|
||||
final String key;
|
||||
final String fileName;
|
||||
|
||||
const GeoItem({
|
||||
required this.label,
|
||||
required this.key,
|
||||
required this.fileName,
|
||||
});
|
||||
}
|
||||
@@ -52,11 +55,12 @@ class _ResourcesState extends State<Resources> {
|
||||
|
||||
_syncExternalProviders() async {
|
||||
externalProviders = await clashCore.getExternalProviders();
|
||||
setState(() {});
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
_updateProviders() async {
|
||||
print(providerItemKeys);
|
||||
final updateProviders = providerItemKeys.map<Future>(
|
||||
(key) async => await key.currentState?.updateProvider(false),
|
||||
);
|
||||
@@ -66,13 +70,18 @@ class _ResourcesState extends State<Resources> {
|
||||
|
||||
List<Widget> _buildExternalProviderSection() {
|
||||
List<GlobalObjectKey<_ProviderItemState>> keys = [];
|
||||
final res = generateSection(
|
||||
title: appLocalizations.externalResources,
|
||||
final res = generateInfoSection(
|
||||
info: Info(
|
||||
iconData: Icons.source,
|
||||
label: appLocalizations.externalResources,
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
IconButton.filledTonal(
|
||||
onPressed: () {
|
||||
_updateProviders();
|
||||
},
|
||||
padding: const EdgeInsets.all(4),
|
||||
iconSize: 20,
|
||||
icon: const Icon(
|
||||
Icons.sync,
|
||||
),
|
||||
@@ -99,12 +108,25 @@ class _ResourcesState extends State<Resources> {
|
||||
|
||||
List<Widget> _buildGeoDataSection() {
|
||||
const geoItems = <GeoItem>[
|
||||
GeoItem(label: "GeoIp", fileName: mmdbFileName),
|
||||
GeoItem(label: "GeoSite", fileName: geoSiteFileName),
|
||||
GeoItem(label: "ASN", fileName: asnFileName),
|
||||
GeoItem(
|
||||
label: "GeoIp",
|
||||
fileName: geoIpFileName,
|
||||
key: "geoip",
|
||||
),
|
||||
GeoItem(label: "GeoSite", fileName: geoSiteFileName, key: "geosite"),
|
||||
GeoItem(
|
||||
label: "MMDB",
|
||||
fileName: mmdbFileName,
|
||||
key: "mmdb",
|
||||
),
|
||||
GeoItem(label: "ASN", fileName: asnFileName, key: "asn"),
|
||||
];
|
||||
return generateSection(
|
||||
title: appLocalizations.geoData,
|
||||
|
||||
return generateInfoSection(
|
||||
info: Info(
|
||||
iconData: Icons.storage,
|
||||
label: appLocalizations.geoData,
|
||||
),
|
||||
items: geoItems.map(
|
||||
(geoItem) => GeoDataListItem(
|
||||
geoItem: geoItem,
|
||||
@@ -141,6 +163,33 @@ class _GeoDataListItemState extends State<GeoDataListItem> {
|
||||
|
||||
GeoItem get geoItem => widget.geoItem;
|
||||
|
||||
_updateUrl(String url) async {
|
||||
final newUrl = await globalState.showCommonDialog<String>(
|
||||
child: UpdateGeoUrlFormDialog(
|
||||
title: geoItem.label,
|
||||
url: url,
|
||||
),
|
||||
);
|
||||
if (newUrl != null && newUrl != url && mounted) {
|
||||
try {
|
||||
if (!newUrl.isUrl) {
|
||||
throw "Invalid url";
|
||||
}
|
||||
final appController = globalState.appController;
|
||||
appController.clashConfig.geoXUrl =
|
||||
Map.from(appController.clashConfig.geoXUrl)..[geoItem.key] = newUrl;
|
||||
appController.updateClashConfigDebounce();
|
||||
} catch (e) {
|
||||
globalState.showMessage(
|
||||
title: geoItem.label,
|
||||
message: TextSpan(
|
||||
text: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<FileInfo> _getGeoFileLastModified(String fileName) async {
|
||||
final homePath = await appPath.getHomeDirPath();
|
||||
final file = File(join(homePath, fileName));
|
||||
@@ -168,7 +217,7 @@ class _GeoDataListItemState extends State<GeoDataListItem> {
|
||||
return "${fileInfo.size} · ${fileInfo.lastModified.lastUpdateTimeDesc}";
|
||||
}
|
||||
|
||||
Widget _buildSubtitle() {
|
||||
Widget _buildSubtitle(String url) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -197,6 +246,13 @@ class _GeoDataListItemState extends State<GeoDataListItem> {
|
||||
);
|
||||
},
|
||||
),
|
||||
Text(
|
||||
url,
|
||||
style: context.textTheme.bodyMedium?.toLight,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
@@ -204,13 +260,13 @@ class _GeoDataListItemState extends State<GeoDataListItem> {
|
||||
runSpacing: 6,
|
||||
spacing: 12,
|
||||
children: [
|
||||
// CommonChip(
|
||||
// avatar: const Icon(Icons.upload),
|
||||
// label: "编辑",
|
||||
// onPressed: () {
|
||||
// _uploadGeoFile(geoItem.fileName);
|
||||
// },
|
||||
// ),
|
||||
CommonChip(
|
||||
avatar: const Icon(Icons.edit),
|
||||
label: appLocalizations.edit,
|
||||
onPressed: () {
|
||||
_updateUrl(url);
|
||||
},
|
||||
),
|
||||
CommonChip(
|
||||
avatar: const Icon(Icons.sync),
|
||||
label: appLocalizations.sync,
|
||||
@@ -259,7 +315,12 @@ class _GeoDataListItemState extends State<GeoDataListItem> {
|
||||
vertical: 4,
|
||||
),
|
||||
title: Text(geoItem.label),
|
||||
subtitle: _buildSubtitle(),
|
||||
subtitle: Selector<ClashConfig, String>(
|
||||
selector: (_, clashConfig) => clashConfig.geoXUrl[geoItem.key]!,
|
||||
builder: (_, value, __) {
|
||||
return _buildSubtitle(value);
|
||||
},
|
||||
),
|
||||
trailing: SizedBox(
|
||||
height: 48,
|
||||
width: 48,
|
||||
@@ -391,3 +452,62 @@ class _ProviderItemState extends State<ProviderItem> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateGeoUrlFormDialog extends StatefulWidget {
|
||||
final String title;
|
||||
final String url;
|
||||
|
||||
const UpdateGeoUrlFormDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.url,
|
||||
});
|
||||
|
||||
@override
|
||||
State<UpdateGeoUrlFormDialog> createState() => _UpdateGeoUrlFormDialogState();
|
||||
}
|
||||
|
||||
class _UpdateGeoUrlFormDialogState extends State<UpdateGeoUrlFormDialog> {
|
||||
late TextEditingController urlController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
urlController = TextEditingController(text: widget.url);
|
||||
}
|
||||
|
||||
_handleUpdate() async {
|
||||
final url = urlController.value.text;
|
||||
if (url.isEmpty) return;
|
||||
Navigator.of(context).pop<String>(url);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(widget.title),
|
||||
content: SizedBox(
|
||||
width: 300,
|
||||
child: Wrap(
|
||||
runSpacing: 16,
|
||||
children: [
|
||||
TextField(
|
||||
maxLines: 5,
|
||||
minLines: 1,
|
||||
controller: urlController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _handleUpdate,
|
||||
child: Text(appLocalizations.submit),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -193,5 +193,7 @@
|
||||
"copy": "Copy",
|
||||
"paste": "Paste",
|
||||
"testUrl": "Test url",
|
||||
"sync": "Sync"
|
||||
"sync": "Sync",
|
||||
"exclude": "Hidden from recent tasks",
|
||||
"excludeDesc": "When the app is in the background, the app is hidden from the recent task"
|
||||
}
|
||||
@@ -193,5 +193,7 @@
|
||||
"copy": "复制",
|
||||
"paste": "粘贴",
|
||||
"testUrl": "测速链接",
|
||||
"sync": "同步"
|
||||
"sync": "同步",
|
||||
"exclude": "从最近任务中隐藏",
|
||||
"excludeDesc": "应用在后台时,从最近任务中隐藏应用"
|
||||
}
|
||||
@@ -121,6 +121,10 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"download": MessageLookupByLibrary.simpleMessage("Download"),
|
||||
"edit": MessageLookupByLibrary.simpleMessage("Edit"),
|
||||
"en": MessageLookupByLibrary.simpleMessage("English"),
|
||||
"exclude":
|
||||
MessageLookupByLibrary.simpleMessage("Hidden from recent tasks"),
|
||||
"excludeDesc": MessageLookupByLibrary.simpleMessage(
|
||||
"When the app is in the background, the app is hidden from the recent task"),
|
||||
"exit": MessageLookupByLibrary.simpleMessage("Exit"),
|
||||
"expirationTime":
|
||||
MessageLookupByLibrary.simpleMessage("Expiration time"),
|
||||
|
||||
@@ -100,6 +100,9 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"download": MessageLookupByLibrary.simpleMessage("下载"),
|
||||
"edit": MessageLookupByLibrary.simpleMessage("编辑"),
|
||||
"en": MessageLookupByLibrary.simpleMessage("英语"),
|
||||
"exclude": MessageLookupByLibrary.simpleMessage("从最近任务中隐藏"),
|
||||
"excludeDesc":
|
||||
MessageLookupByLibrary.simpleMessage("应用在后台时,从最近任务中隐藏应用"),
|
||||
"exit": MessageLookupByLibrary.simpleMessage("退出"),
|
||||
"expirationTime": MessageLookupByLibrary.simpleMessage("到期时间"),
|
||||
"externalController": MessageLookupByLibrary.simpleMessage("外部控制器"),
|
||||
|
||||
@@ -1999,6 +1999,26 @@ class AppLocalizations {
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// `Hidden from recent tasks`
|
||||
String get exclude {
|
||||
return Intl.message(
|
||||
'Hidden from recent tasks',
|
||||
name: 'exclude',
|
||||
desc: '',
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// `When the app is in the background, the app is hidden from the recent task`
|
||||
String get excludeDesc {
|
||||
return Intl.message(
|
||||
'When the app is in the background, the app is hidden from the recent task',
|
||||
name: 'excludeDesc',
|
||||
desc: '',
|
||||
args: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AppLocalizationDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
|
||||
115
lib/main.dart
115
lib/main.dart
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:fl_clash/clash/clash.dart';
|
||||
import 'package:fl_clash/plugins/app.dart';
|
||||
import 'package:fl_clash/plugins/proxy.dart';
|
||||
import 'package:fl_clash/plugins/tile.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -16,6 +17,7 @@ Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await android?.init();
|
||||
await window?.init();
|
||||
clashCore.initMessage();
|
||||
globalState.packageInfo = await PackageInfo.fromPlatform();
|
||||
final config = await preferences.getConfig() ?? Config();
|
||||
final clashConfig = await preferences.getClashConfig() ?? ClashConfig();
|
||||
@@ -44,6 +46,7 @@ Future<void> main() async {
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> vpnService() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
globalState.isVpnService = true;
|
||||
final config = await preferences.getConfig() ?? Config();
|
||||
final clashConfig = await preferences.getClashConfig() ?? ClashConfig();
|
||||
final appState = AppState(
|
||||
@@ -51,12 +54,35 @@ Future<void> vpnService() async {
|
||||
isCompatible: config.isCompatible,
|
||||
selectedMap: config.currentSelectedMap,
|
||||
);
|
||||
clashMessage.addListener(
|
||||
ClashMessageListenerWithVpn(
|
||||
onTun: (Fd fd) async {
|
||||
await proxyManager.setProtect(fd.value);
|
||||
await globalState.init(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
|
||||
proxy?.setServiceMessageHandler(
|
||||
ServiceMessageHandler(
|
||||
onProtect: (Fd fd) async {
|
||||
await proxy?.setProtect(fd.value);
|
||||
clashCore.setFdMap(fd.id);
|
||||
},
|
||||
onProcess: (Process process) async {
|
||||
print(process);
|
||||
var packageName = await app?.resolverProcess(process);
|
||||
clashCore.setProcessMap(
|
||||
ProcessMapItem(
|
||||
id: process.id,
|
||||
value: packageName ?? "",
|
||||
),
|
||||
);
|
||||
},
|
||||
onStarted: (String runTime) {
|
||||
globalState.applyProfile(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
},
|
||||
onLoaded: (String groupName) {
|
||||
final currentSelectedMap = config.currentSelectedMap;
|
||||
final proxyName = currentSelectedMap[groupName];
|
||||
@@ -70,70 +96,69 @@ Future<void> vpnService() async {
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await globalState.init(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
|
||||
globalState.applyProfile(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
|
||||
final appLocalizations = await AppLocalizations.load(
|
||||
other.getLocaleForString(config.locale) ??
|
||||
WidgetsBinding.instance.platformDispatcher.locale,
|
||||
);
|
||||
|
||||
handleStart() async {
|
||||
await app?.tip(appLocalizations.startVpn);
|
||||
await globalState.startSystemProxy(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
globalState.updateTraffic(config: config);
|
||||
globalState.updateFunctionLists = [
|
||||
() {
|
||||
globalState.updateTraffic(config: config);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
handleStart();
|
||||
await app?.tip(appLocalizations.startVpn);
|
||||
await globalState.startSystemProxy(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
);
|
||||
|
||||
tile?.addListener(
|
||||
TileListenerWithVpn(
|
||||
onStop: () async {
|
||||
await app?.tip(appLocalizations.stopVpn);
|
||||
await globalState.stopSystemProxy();
|
||||
clashCore.shutdown();
|
||||
exit(0);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
globalState.updateTraffic();
|
||||
globalState.updateFunctionLists = [
|
||||
() {
|
||||
globalState.updateTraffic();
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
class ClashMessageListenerWithVpn with ClashMessageListener {
|
||||
final Function(Fd fd) _onTun;
|
||||
final Function(String) _onLoaded;
|
||||
@immutable
|
||||
class ServiceMessageHandler with ServiceMessageListener {
|
||||
final Function(Fd fd) _onProtect;
|
||||
final Function(Process process) _onProcess;
|
||||
final Function(String runTime) _onStarted;
|
||||
final Function(String groupName) _onLoaded;
|
||||
|
||||
ClashMessageListenerWithVpn({
|
||||
required Function(Fd fd) onTun,
|
||||
required Function(String) onLoaded,
|
||||
}) : _onTun = onTun,
|
||||
const ServiceMessageHandler({
|
||||
required Function(Fd fd) onProtect,
|
||||
required Function(Process process) onProcess,
|
||||
required Function(String runTime) onStarted,
|
||||
required Function(String groupName) onLoaded,
|
||||
}) : _onProtect = onProtect,
|
||||
_onProcess = onProcess,
|
||||
_onStarted = onStarted,
|
||||
_onLoaded = onLoaded;
|
||||
|
||||
@override
|
||||
void onTun(Fd fd) {
|
||||
_onTun(fd);
|
||||
onProtect(Fd fd) {
|
||||
_onProtect(fd);
|
||||
}
|
||||
|
||||
@override
|
||||
void onLoaded(String groupName) {
|
||||
onProcess(Process process) {
|
||||
_onProcess(process);
|
||||
}
|
||||
|
||||
@override
|
||||
onStarted(String runTime) {
|
||||
_onStarted(runTime);
|
||||
}
|
||||
|
||||
@override
|
||||
onLoaded(String groupName) {
|
||||
_onLoaded(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -106,6 +107,8 @@ class Dns {
|
||||
}
|
||||
}
|
||||
|
||||
typedef GeoXMap = Map<String, String>;
|
||||
|
||||
@JsonSerializable()
|
||||
class ClashConfig extends ChangeNotifier {
|
||||
int _mixedPort;
|
||||
@@ -120,6 +123,7 @@ class ClashConfig extends ChangeNotifier {
|
||||
bool _tcpConcurrent;
|
||||
Tun _tun;
|
||||
Dns _dns;
|
||||
GeoXMap _geoXUrl;
|
||||
List<String> _rules;
|
||||
String? _globalRealUa;
|
||||
|
||||
@@ -136,6 +140,7 @@ class ClashConfig extends ChangeNotifier {
|
||||
_geodataLoader = geodataLoaderMemconservative,
|
||||
_externalController = '',
|
||||
_dns = Dns(),
|
||||
_geoXUrl = defaultGeoXMap,
|
||||
_rules = [];
|
||||
|
||||
@JsonKey(name: "mixed-port", defaultValue: 7890)
|
||||
@@ -289,6 +294,16 @@ class ClashConfig extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
@JsonKey(name: "geox-url", defaultValue: defaultGeoXMap)
|
||||
GeoXMap get geoXUrl => _geoXUrl;
|
||||
|
||||
set geoXUrl(GeoXMap value) {
|
||||
if (!const MapEquality<String, String>().equals(value, _geoXUrl)) {
|
||||
_geoXUrl = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
update([ClashConfig? clashConfig]) {
|
||||
if (clashConfig != null) {
|
||||
_mixedPort = clashConfig._mixedPort;
|
||||
|
||||
@@ -56,6 +56,7 @@ class Config extends ChangeNotifier {
|
||||
bool _autoCheckUpdate;
|
||||
bool _allowBypass;
|
||||
bool _systemProxy;
|
||||
bool _isExclude;
|
||||
DAV? _dav;
|
||||
ProxiesType _proxiesType;
|
||||
ProxyCardType _proxyCardType;
|
||||
@@ -80,6 +81,7 @@ class Config extends ChangeNotifier {
|
||||
_accessControl = const AccessControl(),
|
||||
_isAnimateToPage = true,
|
||||
_allowBypass = true,
|
||||
_isExclude = false,
|
||||
_proxyCardType = ProxyCardType.expand,
|
||||
_proxiesType = ProxiesType.tab,
|
||||
_proxiesColumns = 2;
|
||||
@@ -416,7 +418,6 @@ class Config extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JsonKey(name: "test-url", defaultValue: defaultTestUrl)
|
||||
String get testUrl => _testUrl;
|
||||
|
||||
@@ -427,6 +428,16 @@ class Config extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
@JsonKey(defaultValue: false)
|
||||
bool get isExclude => _isExclude;
|
||||
|
||||
set isExclude(bool value) {
|
||||
if (_isExclude != value) {
|
||||
_isExclude = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
update([
|
||||
Config? config,
|
||||
RecoveryOption recoveryOptions = RecoveryOption.all,
|
||||
|
||||
@@ -47,14 +47,25 @@ class ChangeProxyParams with _$ChangeProxyParams {
|
||||
}
|
||||
|
||||
@freezed
|
||||
class Message with _$Message {
|
||||
const factory Message({
|
||||
required MessageType type,
|
||||
class AppMessage with _$AppMessage {
|
||||
const factory AppMessage({
|
||||
required AppMessageType type,
|
||||
dynamic data,
|
||||
}) = _Message;
|
||||
}) = _AppMessage;
|
||||
|
||||
factory Message.fromJson(Map<String, Object?> json) =>
|
||||
_$MessageFromJson(json);
|
||||
factory AppMessage.fromJson(Map<String, Object?> json) =>
|
||||
_$AppMessageFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class ServiceMessage with _$ServiceMessage {
|
||||
const factory ServiceMessage({
|
||||
required ServiceMessageType type,
|
||||
dynamic data,
|
||||
}) = _ServiceMessage;
|
||||
|
||||
factory ServiceMessage.fromJson(Map<String, Object?> json) =>
|
||||
_$ServiceMessageFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -121,3 +132,27 @@ class ExternalProvider with _$ExternalProvider {
|
||||
factory ExternalProvider.fromJson(Map<String, Object?> json) =>
|
||||
_$ExternalProviderFromJson(json);
|
||||
}
|
||||
|
||||
abstract mixin class AppMessageListener {
|
||||
void onLog(Log log) {}
|
||||
|
||||
void onDelay(Delay delay) {}
|
||||
|
||||
void onRequest(Connection connection) {}
|
||||
|
||||
void onStarted(String runTime) {}
|
||||
|
||||
void onLoaded(String groupName) {}
|
||||
}
|
||||
|
||||
abstract mixin class ServiceMessageListener {
|
||||
onProtect(Fd fd) {}
|
||||
|
||||
onProcess(Process process) {}
|
||||
|
||||
onStarted(String runTime) {}
|
||||
|
||||
onLoaded(String groupName) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,20 @@ ClashConfig _$ClashConfigFromJson(Map<String, dynamic> json) => ClashConfig()
|
||||
..tun = Tun.fromJson(json['tun'] as Map<String, dynamic>)
|
||||
..dns = Dns.fromJson(json['dns'] as Map<String, dynamic>)
|
||||
..rules = (json['rules'] as List<dynamic>).map((e) => e as String).toList()
|
||||
..globalRealUa = json['global-real-ua'] as String?;
|
||||
..globalRealUa = json['global-real-ua'] as String?
|
||||
..geoXUrl = (json['geox-url'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
) ??
|
||||
{
|
||||
'mmdb':
|
||||
'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb',
|
||||
'asn':
|
||||
'https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb',
|
||||
'geoip':
|
||||
'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoIP.dat',
|
||||
'geosite':
|
||||
'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat'
|
||||
};
|
||||
|
||||
Map<String, dynamic> _$ClashConfigToJson(ClashConfig instance) =>
|
||||
<String, dynamic>{
|
||||
@@ -70,6 +83,7 @@ Map<String, dynamic> _$ClashConfigToJson(ClashConfig instance) =>
|
||||
'dns': instance.dns,
|
||||
'rules': instance.rules,
|
||||
'global-real-ua': instance.globalRealUa,
|
||||
'geox-url': instance.geoXUrl,
|
||||
};
|
||||
|
||||
const _$ModeEnumMap = {
|
||||
|
||||
@@ -43,7 +43,8 @@ Config _$ConfigFromJson(Map<String, dynamic> json) => Config()
|
||||
ProxyCardType.expand
|
||||
..proxiesColumns = (json['proxiesColumns'] as num?)?.toInt() ?? 2
|
||||
..testUrl =
|
||||
json['test-url'] as String? ?? 'https://www.gstatic.com/generate_204';
|
||||
json['test-url'] as String? ?? 'https://www.gstatic.com/generate_204'
|
||||
..isExclude = json['isExclude'] as bool? ?? false;
|
||||
|
||||
Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
|
||||
'profiles': instance.profiles,
|
||||
@@ -69,6 +70,7 @@ Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
|
||||
'proxyCardType': _$ProxyCardTypeEnumMap[instance.proxyCardType]!,
|
||||
'proxiesColumns': instance.proxiesColumns,
|
||||
'test-url': instance.testUrl,
|
||||
'isExclude': instance.isExclude,
|
||||
};
|
||||
|
||||
const _$ThemeModeEnumMap = {
|
||||
|
||||
@@ -610,32 +610,34 @@ abstract class _ChangeProxyParams implements ChangeProxyParams {
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
return _Message.fromJson(json);
|
||||
AppMessage _$AppMessageFromJson(Map<String, dynamic> json) {
|
||||
return _AppMessage.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$Message {
|
||||
MessageType get type => throw _privateConstructorUsedError;
|
||||
mixin _$AppMessage {
|
||||
AppMessageType get type => throw _privateConstructorUsedError;
|
||||
dynamic get data => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$MessageCopyWith<Message> get copyWith => throw _privateConstructorUsedError;
|
||||
$AppMessageCopyWith<AppMessage> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $MessageCopyWith<$Res> {
|
||||
factory $MessageCopyWith(Message value, $Res Function(Message) then) =
|
||||
_$MessageCopyWithImpl<$Res, Message>;
|
||||
abstract class $AppMessageCopyWith<$Res> {
|
||||
factory $AppMessageCopyWith(
|
||||
AppMessage value, $Res Function(AppMessage) then) =
|
||||
_$AppMessageCopyWithImpl<$Res, AppMessage>;
|
||||
@useResult
|
||||
$Res call({MessageType type, dynamic data});
|
||||
$Res call({AppMessageType type, dynamic data});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$MessageCopyWithImpl<$Res, $Val extends Message>
|
||||
implements $MessageCopyWith<$Res> {
|
||||
_$MessageCopyWithImpl(this._value, this._then);
|
||||
class _$AppMessageCopyWithImpl<$Res, $Val extends AppMessage>
|
||||
implements $AppMessageCopyWith<$Res> {
|
||||
_$AppMessageCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
@@ -652,7 +654,7 @@ class _$MessageCopyWithImpl<$Res, $Val extends Message>
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as MessageType,
|
||||
as AppMessageType,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
@@ -662,21 +664,22 @@ class _$MessageCopyWithImpl<$Res, $Val extends Message>
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$MessageImplCopyWith<$Res> implements $MessageCopyWith<$Res> {
|
||||
factory _$$MessageImplCopyWith(
|
||||
_$MessageImpl value, $Res Function(_$MessageImpl) then) =
|
||||
__$$MessageImplCopyWithImpl<$Res>;
|
||||
abstract class _$$AppMessageImplCopyWith<$Res>
|
||||
implements $AppMessageCopyWith<$Res> {
|
||||
factory _$$AppMessageImplCopyWith(
|
||||
_$AppMessageImpl value, $Res Function(_$AppMessageImpl) then) =
|
||||
__$$AppMessageImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({MessageType type, dynamic data});
|
||||
$Res call({AppMessageType type, dynamic data});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$MessageImplCopyWithImpl<$Res>
|
||||
extends _$MessageCopyWithImpl<$Res, _$MessageImpl>
|
||||
implements _$$MessageImplCopyWith<$Res> {
|
||||
__$$MessageImplCopyWithImpl(
|
||||
_$MessageImpl _value, $Res Function(_$MessageImpl) _then)
|
||||
class __$$AppMessageImplCopyWithImpl<$Res>
|
||||
extends _$AppMessageCopyWithImpl<$Res, _$AppMessageImpl>
|
||||
implements _$$AppMessageImplCopyWith<$Res> {
|
||||
__$$AppMessageImplCopyWithImpl(
|
||||
_$AppMessageImpl _value, $Res Function(_$AppMessageImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@@ -685,11 +688,11 @@ class __$$MessageImplCopyWithImpl<$Res>
|
||||
Object? type = null,
|
||||
Object? data = freezed,
|
||||
}) {
|
||||
return _then(_$MessageImpl(
|
||||
return _then(_$AppMessageImpl(
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as MessageType,
|
||||
as AppMessageType,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
@@ -700,27 +703,27 @@ class __$$MessageImplCopyWithImpl<$Res>
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$MessageImpl implements _Message {
|
||||
const _$MessageImpl({required this.type, this.data});
|
||||
class _$AppMessageImpl implements _AppMessage {
|
||||
const _$AppMessageImpl({required this.type, this.data});
|
||||
|
||||
factory _$MessageImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$MessageImplFromJson(json);
|
||||
factory _$AppMessageImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$AppMessageImplFromJson(json);
|
||||
|
||||
@override
|
||||
final MessageType type;
|
||||
final AppMessageType type;
|
||||
@override
|
||||
final dynamic data;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Message(type: $type, data: $data)';
|
||||
return 'AppMessage(type: $type, data: $data)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$MessageImpl &&
|
||||
other is _$AppMessageImpl &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
const DeepCollectionEquality().equals(other.data, data));
|
||||
}
|
||||
@@ -733,30 +736,188 @@ class _$MessageImpl implements _Message {
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$MessageImplCopyWith<_$MessageImpl> get copyWith =>
|
||||
__$$MessageImplCopyWithImpl<_$MessageImpl>(this, _$identity);
|
||||
_$$AppMessageImplCopyWith<_$AppMessageImpl> get copyWith =>
|
||||
__$$AppMessageImplCopyWithImpl<_$AppMessageImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$MessageImplToJson(
|
||||
return _$$AppMessageImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Message implements Message {
|
||||
const factory _Message(
|
||||
{required final MessageType type, final dynamic data}) = _$MessageImpl;
|
||||
abstract class _AppMessage implements AppMessage {
|
||||
const factory _AppMessage(
|
||||
{required final AppMessageType type,
|
||||
final dynamic data}) = _$AppMessageImpl;
|
||||
|
||||
factory _Message.fromJson(Map<String, dynamic> json) = _$MessageImpl.fromJson;
|
||||
factory _AppMessage.fromJson(Map<String, dynamic> json) =
|
||||
_$AppMessageImpl.fromJson;
|
||||
|
||||
@override
|
||||
MessageType get type;
|
||||
AppMessageType get type;
|
||||
@override
|
||||
dynamic get data;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$MessageImplCopyWith<_$MessageImpl> get copyWith =>
|
||||
_$$AppMessageImplCopyWith<_$AppMessageImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
ServiceMessage _$ServiceMessageFromJson(Map<String, dynamic> json) {
|
||||
return _ServiceMessage.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ServiceMessage {
|
||||
ServiceMessageType get type => throw _privateConstructorUsedError;
|
||||
dynamic get data => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$ServiceMessageCopyWith<ServiceMessage> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ServiceMessageCopyWith<$Res> {
|
||||
factory $ServiceMessageCopyWith(
|
||||
ServiceMessage value, $Res Function(ServiceMessage) then) =
|
||||
_$ServiceMessageCopyWithImpl<$Res, ServiceMessage>;
|
||||
@useResult
|
||||
$Res call({ServiceMessageType type, dynamic data});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ServiceMessageCopyWithImpl<$Res, $Val extends ServiceMessage>
|
||||
implements $ServiceMessageCopyWith<$Res> {
|
||||
_$ServiceMessageCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? type = null,
|
||||
Object? data = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as ServiceMessageType,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as dynamic,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ServiceMessageImplCopyWith<$Res>
|
||||
implements $ServiceMessageCopyWith<$Res> {
|
||||
factory _$$ServiceMessageImplCopyWith(_$ServiceMessageImpl value,
|
||||
$Res Function(_$ServiceMessageImpl) then) =
|
||||
__$$ServiceMessageImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({ServiceMessageType type, dynamic data});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ServiceMessageImplCopyWithImpl<$Res>
|
||||
extends _$ServiceMessageCopyWithImpl<$Res, _$ServiceMessageImpl>
|
||||
implements _$$ServiceMessageImplCopyWith<$Res> {
|
||||
__$$ServiceMessageImplCopyWithImpl(
|
||||
_$ServiceMessageImpl _value, $Res Function(_$ServiceMessageImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? type = null,
|
||||
Object? data = freezed,
|
||||
}) {
|
||||
return _then(_$ServiceMessageImpl(
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as ServiceMessageType,
|
||||
data: freezed == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as dynamic,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$ServiceMessageImpl implements _ServiceMessage {
|
||||
const _$ServiceMessageImpl({required this.type, this.data});
|
||||
|
||||
factory _$ServiceMessageImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$ServiceMessageImplFromJson(json);
|
||||
|
||||
@override
|
||||
final ServiceMessageType type;
|
||||
@override
|
||||
final dynamic data;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ServiceMessage(type: $type, data: $data)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ServiceMessageImpl &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
const DeepCollectionEquality().equals(other.data, data));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, type, const DeepCollectionEquality().hash(data));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ServiceMessageImplCopyWith<_$ServiceMessageImpl> get copyWith =>
|
||||
__$$ServiceMessageImplCopyWithImpl<_$ServiceMessageImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$ServiceMessageImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ServiceMessage implements ServiceMessage {
|
||||
const factory _ServiceMessage(
|
||||
{required final ServiceMessageType type,
|
||||
final dynamic data}) = _$ServiceMessageImpl;
|
||||
|
||||
factory _ServiceMessage.fromJson(Map<String, dynamic> json) =
|
||||
_$ServiceMessageImpl.fromJson;
|
||||
|
||||
@override
|
||||
ServiceMessageType get type;
|
||||
@override
|
||||
dynamic get data;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$ServiceMessageImplCopyWith<_$ServiceMessageImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,27 +55,44 @@ Map<String, dynamic> _$$ChangeProxyParamsImplToJson(
|
||||
'proxy-name': instance.proxyName,
|
||||
};
|
||||
|
||||
_$MessageImpl _$$MessageImplFromJson(Map<String, dynamic> json) =>
|
||||
_$MessageImpl(
|
||||
type: $enumDecode(_$MessageTypeEnumMap, json['type']),
|
||||
_$AppMessageImpl _$$AppMessageImplFromJson(Map<String, dynamic> json) =>
|
||||
_$AppMessageImpl(
|
||||
type: $enumDecode(_$AppMessageTypeEnumMap, json['type']),
|
||||
data: json['data'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$MessageImplToJson(_$MessageImpl instance) =>
|
||||
Map<String, dynamic> _$$AppMessageImplToJson(_$AppMessageImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$MessageTypeEnumMap[instance.type]!,
|
||||
'type': _$AppMessageTypeEnumMap[instance.type]!,
|
||||
'data': instance.data,
|
||||
};
|
||||
|
||||
const _$MessageTypeEnumMap = {
|
||||
MessageType.log: 'log',
|
||||
MessageType.tun: 'tun',
|
||||
MessageType.delay: 'delay',
|
||||
MessageType.process: 'process',
|
||||
MessageType.now: 'now',
|
||||
MessageType.request: 'request',
|
||||
MessageType.run: 'run',
|
||||
MessageType.loaded: 'loaded',
|
||||
const _$AppMessageTypeEnumMap = {
|
||||
AppMessageType.log: 'log',
|
||||
AppMessageType.delay: 'delay',
|
||||
AppMessageType.request: 'request',
|
||||
AppMessageType.started: 'started',
|
||||
AppMessageType.loaded: 'loaded',
|
||||
};
|
||||
|
||||
_$ServiceMessageImpl _$$ServiceMessageImplFromJson(Map<String, dynamic> json) =>
|
||||
_$ServiceMessageImpl(
|
||||
type: $enumDecode(_$ServiceMessageTypeEnumMap, json['type']),
|
||||
data: json['data'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ServiceMessageImplToJson(
|
||||
_$ServiceMessageImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'type': _$ServiceMessageTypeEnumMap[instance.type]!,
|
||||
'data': instance.data,
|
||||
};
|
||||
|
||||
const _$ServiceMessageTypeEnumMap = {
|
||||
ServiceMessageType.protect: 'protect',
|
||||
ServiceMessageType.process: 'process',
|
||||
ServiceMessageType.started: 'started',
|
||||
ServiceMessageType.loaded: 'loaded',
|
||||
};
|
||||
|
||||
_$DelayImpl _$$DelayImplFromJson(Map<String, dynamic> json) => _$DelayImpl(
|
||||
|
||||
@@ -5,32 +5,30 @@ import 'dart:isolate';
|
||||
|
||||
import 'package:fl_clash/clash/clash.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class App {
|
||||
static App? _instance;
|
||||
MethodChannel? methodChannel;
|
||||
late MethodChannel methodChannel;
|
||||
Function()? onExit;
|
||||
|
||||
App._internal() {
|
||||
if (Platform.isAndroid) {
|
||||
methodChannel = const MethodChannel("app");
|
||||
methodChannel!.setMethodCallHandler((call) async {
|
||||
switch (call.method) {
|
||||
case "exit":
|
||||
if (onExit != null) {
|
||||
await onExit!();
|
||||
}
|
||||
break;
|
||||
case "gc":
|
||||
clashCore.requestGc();
|
||||
break;
|
||||
default:
|
||||
throw MissingPluginException();
|
||||
}
|
||||
});
|
||||
}
|
||||
methodChannel = const MethodChannel("app");
|
||||
methodChannel.setMethodCallHandler((call) async {
|
||||
switch (call.method) {
|
||||
case "exit":
|
||||
if (onExit != null) {
|
||||
await onExit!();
|
||||
}
|
||||
case "gc":
|
||||
clashCore.requestGc();
|
||||
default:
|
||||
throw MissingPluginException();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
factory App() {
|
||||
@@ -39,12 +37,12 @@ class App {
|
||||
}
|
||||
|
||||
Future<bool?> moveTaskToBack() async {
|
||||
return await methodChannel?.invokeMethod<bool>("moveTaskToBack");
|
||||
return await methodChannel.invokeMethod<bool>("moveTaskToBack");
|
||||
}
|
||||
|
||||
Future<List<Package>> getPackages() async {
|
||||
final packagesString =
|
||||
await methodChannel?.invokeMethod<String>("getPackages");
|
||||
await methodChannel.invokeMethod<String>("getPackages");
|
||||
return Isolate.run<List<Package>>(() {
|
||||
final List<dynamic> packagesRaw =
|
||||
packagesString != null ? json.decode(packagesString) : [];
|
||||
@@ -53,7 +51,7 @@ class App {
|
||||
}
|
||||
|
||||
Future<ImageProvider?> getPackageIcon(String packageName) async {
|
||||
final base64 = await methodChannel?.invokeMethod<String>("getPackageIcon", {
|
||||
final base64 = await methodChannel.invokeMethod<String>("getPackageIcon", {
|
||||
"packageName": packageName,
|
||||
});
|
||||
if (base64 == null) {
|
||||
@@ -63,13 +61,19 @@ class App {
|
||||
}
|
||||
|
||||
Future<bool?> tip(String? message) async {
|
||||
return await methodChannel?.invokeMethod<bool>("tip", {
|
||||
return await methodChannel.invokeMethod<bool>("tip", {
|
||||
"message": "$message",
|
||||
});
|
||||
}
|
||||
|
||||
Future<bool?> updateExcludeFromRecents(bool value) async {
|
||||
return await methodChannel.invokeMethod<bool>("updateExcludeFromRecents", {
|
||||
"value": value,
|
||||
});
|
||||
}
|
||||
|
||||
Future<String?> resolverProcess(Process process) async {
|
||||
return await methodChannel?.invokeMethod<String>("resolverProcess", {
|
||||
return await methodChannel.invokeMethod<String>("resolverProcess", {
|
||||
"data": json.encode(process),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'package:fl_clash/clash/core.dart';
|
||||
import 'package:fl_clash/clash/clash.dart';
|
||||
import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/enum/enum.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:proxy/proxy_platform_interface.dart';
|
||||
|
||||
class Proxy extends ProxyPlatform {
|
||||
static Proxy? _instance;
|
||||
late MethodChannel methodChannel;
|
||||
late ReceivePort receiver;
|
||||
ReceivePort? receiver;
|
||||
ServiceMessageListener? _serviceMessageHandler;
|
||||
|
||||
Proxy._internal() {
|
||||
methodChannel = const MethodChannel("proxy");
|
||||
receiver = ReceivePort()
|
||||
..listen(
|
||||
(message) {
|
||||
setProtect(int.parse(message));
|
||||
},
|
||||
);
|
||||
methodChannel.setMethodCallHandler((call) async {
|
||||
switch (call.method) {
|
||||
case "startAfter":
|
||||
int fd = call.arguments;
|
||||
startAfterHook(fd);
|
||||
case "started":
|
||||
final fd = call.arguments;
|
||||
onStarted(fd);
|
||||
break;
|
||||
default:
|
||||
throw MissingPluginException();
|
||||
@@ -36,16 +36,27 @@ class Proxy extends ProxyPlatform {
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<bool?> _initService() async {
|
||||
return await methodChannel.invokeMethod<bool>("initService");
|
||||
}
|
||||
|
||||
handleStop() {
|
||||
globalState.stopSystemProxy();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> startProxy(int port, String? args) async {
|
||||
Future<bool?> startProxy(port, args) async {
|
||||
if (!globalState.isVpnService) {
|
||||
return await _initService();
|
||||
}
|
||||
return await methodChannel
|
||||
.invokeMethod<bool>("StartProxy", {'port': port, 'args': args});
|
||||
.invokeMethod<bool>("startProxy", {'port': port, 'args': args});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> stopProxy() async {
|
||||
clashCore.stopTun();
|
||||
final isStop = await methodChannel.invokeMethod<bool>("StopProxy");
|
||||
final isStop = await methodChannel.invokeMethod<bool>("stopProxy");
|
||||
if (isStop == true) {
|
||||
startTime = null;
|
||||
}
|
||||
@@ -53,11 +64,7 @@ class Proxy extends ProxyPlatform {
|
||||
}
|
||||
|
||||
Future<bool?> setProtect(int fd) async {
|
||||
return await methodChannel.invokeMethod<bool?>("SetProtect", {'fd': fd});
|
||||
}
|
||||
|
||||
Future<int?> getRunTimeStamp() async {
|
||||
return await methodChannel.invokeMethod<int?>("GetRunTimeStamp");
|
||||
return await methodChannel.invokeMethod<bool?>("setProtect", {'fd': fd});
|
||||
}
|
||||
|
||||
Future<bool?> startForeground({
|
||||
@@ -72,26 +79,39 @@ class Proxy extends ProxyPlatform {
|
||||
|
||||
bool get isStart => startTime != null && startTime!.isBeforeNow;
|
||||
|
||||
startAfterHook(int? fd) {
|
||||
if (!isStart && fd != null) {
|
||||
clashCore.startTun(fd);
|
||||
updateStartTime();
|
||||
onStarted(int? fd) {
|
||||
if (fd == null) return;
|
||||
if (receiver != null) {
|
||||
receiver!.close();
|
||||
receiver == null;
|
||||
}
|
||||
receiver = ReceivePort();
|
||||
receiver!.listen((message) {
|
||||
_handleServiceMessage(message);
|
||||
});
|
||||
clashCore.startTun(fd, receiver!.sendPort.nativePort);
|
||||
}
|
||||
|
||||
// updateStartTime() async {
|
||||
// startTime = clashCore.getRunTime();
|
||||
// }
|
||||
|
||||
updateStartTime() async {
|
||||
startTime = await getRunTime();
|
||||
updateStartTime() {
|
||||
startTime = clashCore.getRunTime();
|
||||
}
|
||||
|
||||
Future<DateTime?> getRunTime() async {
|
||||
final runTimeStamp = await getRunTimeStamp();
|
||||
return runTimeStamp != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(runTimeStamp)
|
||||
: null;
|
||||
setServiceMessageHandler(ServiceMessageListener serviceMessageListener) {
|
||||
_serviceMessageHandler = serviceMessageListener;
|
||||
}
|
||||
|
||||
_handleServiceMessage(String message) {
|
||||
final m = ServiceMessage.fromJson(json.decode(message));
|
||||
switch (m.type) {
|
||||
case ServiceMessageType.protect:
|
||||
_serviceMessageHandler?.onProtect(Fd.fromJson(m.data));
|
||||
case ServiceMessageType.process:
|
||||
_serviceMessageHandler?.onProcess(Process.fromJson(m.data));
|
||||
case ServiceMessageType.started:
|
||||
_serviceMessageHandler?.onStarted(m.data);
|
||||
case ServiceMessageType.loaded:
|
||||
_serviceMessageHandler?.onLoaded(m.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,20 @@ 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/plugins/proxy.dart';
|
||||
import 'package:fl_clash/widgets/scaffold.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
|
||||
import 'models/models.dart';
|
||||
import 'common/common.dart';
|
||||
|
||||
class GlobalState {
|
||||
Timer? timer;
|
||||
Timer? groupsUpdateTimer;
|
||||
var isVpnService = false;
|
||||
late PackageInfo packageInfo;
|
||||
Function? updateCurrentDelayDebounce;
|
||||
PageController? pageController;
|
||||
@@ -82,12 +85,15 @@ class GlobalState {
|
||||
args: args,
|
||||
);
|
||||
startListenUpdate();
|
||||
if (Platform.isAndroid) {
|
||||
return;
|
||||
}
|
||||
applyProfile(
|
||||
appState: appState,
|
||||
config: config,
|
||||
clashConfig: clashConfig,
|
||||
).then((_){
|
||||
appController.addCheckIpNumDebounce();
|
||||
globalState.appController.addCheckIpNumDebounce();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,6 +112,7 @@ class GlobalState {
|
||||
config: config,
|
||||
isPatch: false,
|
||||
);
|
||||
clashCore.setProfileName(config.currentProfile?.label ?? '');
|
||||
await updateGroups(appState);
|
||||
}
|
||||
|
||||
@@ -182,20 +189,18 @@ class GlobalState {
|
||||
|
||||
updateTraffic({
|
||||
AppState? appState,
|
||||
required Config config,
|
||||
}) {
|
||||
final traffic = clashCore.getTraffic();
|
||||
if (appState != null) {
|
||||
appState.addTraffic(traffic);
|
||||
appState.totalTraffic = clashCore.getTotalTraffic();
|
||||
}
|
||||
if (Platform.isAndroid) {
|
||||
final currentProfile = config.currentProfile;
|
||||
if (currentProfile == null) return;
|
||||
proxyManager.startForeground(
|
||||
title: currentProfile.label ?? currentProfile.id,
|
||||
if (Platform.isAndroid && isVpnService == true) {
|
||||
proxy?.startForeground(
|
||||
title: clashCore.getProfileName(),
|
||||
content: "$traffic",
|
||||
);
|
||||
} else {
|
||||
if (appState != null) {
|
||||
appState.addTraffic(traffic);
|
||||
appState.totalTraffic = clashCore.getTotalTraffic();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,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>(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/plugins/app.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class AndroidContainer extends StatefulWidget {
|
||||
final Widget child;
|
||||
@@ -17,6 +20,17 @@ class AndroidContainer extends StatefulWidget {
|
||||
class _AndroidContainerState extends State<AndroidContainer>
|
||||
with WidgetsBindingObserver {
|
||||
|
||||
_excludeContainer(Widget child) {
|
||||
return Selector<Config, bool>(
|
||||
selector: (_, config) => config.isExclude,
|
||||
builder: (_, isExclude, child) {
|
||||
app?.updateExcludeFromRecents(isExclude);
|
||||
return child!;
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -34,7 +48,7 @@ class _AndroidContainerState extends State<AndroidContainer>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
return _excludeContainer(widget.child);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -42,5 +56,4 @@ class _AndroidContainerState extends State<AndroidContainer>
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,17 +12,6 @@ class AppStateContainer extends StatelessWidget {
|
||||
required this.child,
|
||||
});
|
||||
|
||||
_autoLaunchContainer(Widget child) {
|
||||
return Selector<Config, bool>(
|
||||
selector: (_, config) => config.autoLaunch,
|
||||
builder: (_, isAutoLaunch, child) {
|
||||
autoLaunch?.updateStatus(isAutoLaunch);
|
||||
return child!;
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
_updateNavigationsContainer(Widget child) {
|
||||
return Selector2<AppState, Config, UpdateNavigationsSelector>(
|
||||
selector: (_, appState, config) {
|
||||
@@ -51,10 +40,8 @@ class AppStateContainer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _autoLaunchContainer(
|
||||
_updateNavigationsContainer(
|
||||
child,
|
||||
),
|
||||
return _updateNavigationsContainer(
|
||||
child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,43 +6,70 @@ import 'text.dart';
|
||||
|
||||
class Info {
|
||||
final String label;
|
||||
final IconData iconData;
|
||||
final IconData? iconData;
|
||||
|
||||
const Info({
|
||||
required this.label,
|
||||
required this.iconData,
|
||||
this.iconData,
|
||||
});
|
||||
}
|
||||
|
||||
class InfoHeader extends StatelessWidget {
|
||||
final Info info;
|
||||
final List<Widget> actions;
|
||||
|
||||
const InfoHeader({
|
||||
super.key,
|
||||
required this.info,
|
||||
});
|
||||
List<Widget>? actions,
|
||||
}) : actions = actions ?? const [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(
|
||||
info.iconData,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
Flexible(
|
||||
child: TooltipText(
|
||||
text: Text(
|
||||
info.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (info.iconData != null) ...[
|
||||
Icon(
|
||||
info.iconData,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
],
|
||||
Flexible(
|
||||
child: TooltipText(
|
||||
text: Text(
|
||||
info.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.titleMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
...actions,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -70,10 +97,12 @@ class CommonCard extends StatelessWidget {
|
||||
final CommonCardType type;
|
||||
|
||||
BorderSide getBorderSide(BuildContext context, Set<WidgetState> states) {
|
||||
if(type == CommonCardType.filled){
|
||||
if (type == CommonCardType.filled) {
|
||||
return BorderSide.none;
|
||||
}
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final colorScheme = Theme
|
||||
.of(context)
|
||||
.colorScheme;
|
||||
final hoverColor = isSelected
|
||||
? colorScheme.primary.toLight()
|
||||
: colorScheme.primary.toLighter();
|
||||
@@ -85,14 +114,15 @@ class CommonCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
return BorderSide(
|
||||
color:
|
||||
isSelected ? colorScheme.primary : colorScheme.onSurface.toSoft(),
|
||||
color: isSelected ? colorScheme.primary : colorScheme.onSurface.toSoft(),
|
||||
);
|
||||
}
|
||||
|
||||
Color? getBackgroundColor(BuildContext context, Set<WidgetState> states) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
switch(type){
|
||||
final colorScheme = Theme
|
||||
.of(context)
|
||||
.colorScheme;
|
||||
switch (type) {
|
||||
case CommonCardType.plain:
|
||||
if (isSelected) {
|
||||
return colorScheme.secondaryContainer;
|
||||
@@ -100,7 +130,8 @@ class CommonCard extends StatelessWidget {
|
||||
if (states.isEmpty) {
|
||||
return colorScheme.secondaryContainer.toLittle();
|
||||
}
|
||||
return Theme.of(context)
|
||||
return Theme
|
||||
.of(context)
|
||||
.outlinedButtonTheme
|
||||
.style
|
||||
?.backgroundColor
|
||||
@@ -147,10 +178,10 @@ class CommonCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
backgroundColor: WidgetStateProperty.resolveWith(
|
||||
(states) => getBackgroundColor(context, states),
|
||||
(states) => getBackgroundColor(context, states),
|
||||
),
|
||||
side: WidgetStateProperty.resolveWith(
|
||||
(states) => getBorderSide(context, states),
|
||||
(states) => getBorderSide(context, states),
|
||||
),
|
||||
),
|
||||
onPressed: onPressed,
|
||||
@@ -180,7 +211,10 @@ class SelectIcon extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Theme.of(context).colorScheme.inversePrimary,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.colorScheme
|
||||
.inversePrimary,
|
||||
shape: const CircleBorder(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:fl_clash/clash/clash.dart';
|
||||
import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/plugins/proxy.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_clash/plugins/app.dart';
|
||||
@@ -18,7 +18,7 @@ class ClashMessageContainer extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ClashMessageContainerState extends State<ClashMessageContainer>
|
||||
with ClashMessageListener {
|
||||
with AppMessageListener {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
@@ -49,25 +49,6 @@ class _ClashMessageContainerState extends State<ClashMessageContainer>
|
||||
super.onLog(log);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onTun(Fd fd) async {
|
||||
await proxyManager.setProtect(fd.value);
|
||||
clashCore.setFdMap(fd.id);
|
||||
super.onTun(fd);
|
||||
}
|
||||
|
||||
@override
|
||||
void onProcess(Process process) async {
|
||||
var packageName = await app?.resolverProcess(process);
|
||||
clashCore.setProcessMap(
|
||||
ProcessMapItem(
|
||||
id: process.id,
|
||||
value: packageName ?? "",
|
||||
),
|
||||
);
|
||||
super.onProcess(process);
|
||||
}
|
||||
|
||||
@override
|
||||
void onRequest(Connection connection) async {
|
||||
globalState.appController.appState.addRequest(connection);
|
||||
@@ -89,4 +70,14 @@ class _ClashMessageContainerState extends State<ClashMessageContainer>
|
||||
appController.addCheckIpNumDebounce();
|
||||
super.onLoaded(proxyName);
|
||||
}
|
||||
|
||||
@override
|
||||
void onStarted(String runTime) {
|
||||
super.onStarted(runTime);
|
||||
proxy?.updateStartTime();
|
||||
final appController = globalState.appController;
|
||||
appController.rawApplyProfile().then((_) {
|
||||
appController.addCheckIpNumDebounce();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:fl_clash/state.dart';
|
||||
import 'package:fl_clash/widgets/open_container.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'card.dart';
|
||||
import 'extend_page.dart';
|
||||
import 'scaffold.dart';
|
||||
|
||||
@@ -390,6 +391,30 @@ List<Widget> generateSection({
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> generateInfoSection({
|
||||
required Info info,
|
||||
required Iterable<Widget> items,
|
||||
List<Widget>? actions,
|
||||
bool separated = true,
|
||||
}) {
|
||||
final genItems = separated
|
||||
? items.separated(
|
||||
const Divider(
|
||||
height: 0,
|
||||
),
|
||||
)
|
||||
: items;
|
||||
return [
|
||||
if (items.isNotEmpty)
|
||||
InfoHeader(
|
||||
info: info,
|
||||
actions: actions,
|
||||
),
|
||||
...genItems,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Widget generateListView(List<Widget> items) {
|
||||
return ListView.builder(
|
||||
itemCount: items.length,
|
||||
|
||||
@@ -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;
|
||||
@@ -20,7 +19,6 @@ class CommonScaffold extends StatefulWidget {
|
||||
this.leading,
|
||||
required this.title,
|
||||
this.actions,
|
||||
this.floatingActionButton,
|
||||
this.automaticallyImplyLeading = true,
|
||||
});
|
||||
|
||||
@@ -51,8 +49,6 @@ class CommonScaffold extends StatefulWidget {
|
||||
|
||||
class CommonScaffoldState extends State<CommonScaffold> {
|
||||
final ValueNotifier<List<Widget>> _actions = ValueNotifier([]);
|
||||
final ValueNotifier<Widget?> _floatingActionButton = ValueNotifier(null);
|
||||
|
||||
final ValueNotifier<bool> _loading = ValueNotifier(false);
|
||||
|
||||
set actions(List<Widget> actions) {
|
||||
@@ -61,12 +57,6 @@ class CommonScaffoldState extends State<CommonScaffold> {
|
||||
}
|
||||
}
|
||||
|
||||
set floatingActionButton(Widget? actions) {
|
||||
if (_floatingActionButton.value != actions) {
|
||||
_floatingActionButton.value = actions;
|
||||
}
|
||||
}
|
||||
|
||||
Future<T?> loadingRun<T>(
|
||||
Future<T> Function() futureFunction, {
|
||||
String? title,
|
||||
@@ -91,7 +81,6 @@ class CommonScaffoldState extends State<CommonScaffold> {
|
||||
@override
|
||||
void dispose() {
|
||||
_actions.dispose();
|
||||
_floatingActionButton.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -100,7 +89,6 @@ class CommonScaffoldState extends State<CommonScaffold> {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.title != widget.title) {
|
||||
_actions.value = [];
|
||||
_floatingActionButton.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,13 +113,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),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:fl_clash/common/common.dart';
|
||||
import 'package:fl_clash/models/models.dart';
|
||||
import 'package:fl_clash/state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowContainer extends StatefulWidget {
|
||||
@@ -14,11 +17,22 @@ class WindowContainer extends StatefulWidget {
|
||||
State<WindowContainer> createState() => _WindowContainerState();
|
||||
}
|
||||
|
||||
class _WindowContainerState extends State<WindowContainer>
|
||||
with WindowListener {
|
||||
class _WindowContainerState extends State<WindowContainer> with WindowListener {
|
||||
|
||||
_autoLaunchContainer(Widget child) {
|
||||
return Selector<Config, bool>(
|
||||
selector: (_, config) => config.autoLaunch,
|
||||
builder: (_, isAutoLaunch, child) {
|
||||
autoLaunch?.updateStatus(isAutoLaunch);
|
||||
return child!;
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
return _autoLaunchContainer(widget.child);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -33,7 +47,6 @@ class _WindowContainerState extends State<WindowContainer>
|
||||
super.onWindowClose();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void onWindowMinimize() async {
|
||||
await globalState.appController.savePreferences();
|
||||
|
||||
@@ -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.35+202407071
|
||||
version: 0.8.38+202407142
|
||||
environment:
|
||||
sdk: '>=3.1.0 <4.0.0'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user