Skip to content

Commit

Permalink
Update popup menu
Browse files Browse the repository at this point in the history
Add file editor

Fix android service issues

Optimize desktop background performance

Optimize android main process performance

Optimize delay test

Optimize vpn protect
  • Loading branch information
chen08209 committed Feb 2, 2025
1 parent 6a39b7e commit b340fee
Show file tree
Hide file tree
Showing 92 changed files with 3,941 additions and 3,022 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
tools:ignore="QueryAllPackagesPermission" />

<application
android:name="${applicationName}"
android:name=".FlClashApplication"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="FlClash">
Expand Down
18 changes: 18 additions & 0 deletions android/app/src/main/kotlin/com/follow/clash/FlClashApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.follow.clash;

import android.app.Application
import android.content.Context;

class FlClashApplication : Application() {
companion object {
private lateinit var instance: FlClashApplication
fun getAppContext(): Context {
return instance.applicationContext
}
}

override fun onCreate() {
super.onCreate()
instance = this
}
}
26 changes: 16 additions & 10 deletions android/app/src/main/kotlin/com/follow/clash/GlobalState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object GlobalState {
return currentEngine?.plugins?.get(AppPlugin::class.java) as AppPlugin?
}

fun getText(text: String): String {
suspend fun getText(text: String): String {
return getCurrentAppPlugin()?.getText(text) ?: ""
}

Expand All @@ -44,22 +44,22 @@ object GlobalState {
return serviceEngine?.plugins?.get(VpnPlugin::class.java) as VpnPlugin?
}

fun handleToggle(context: Context) {
val starting = handleStart(context)
fun handleToggle() {
val starting = handleStart()
if (!starting) {
handleStop()
}
}

fun handleStart(context: Context): Boolean {
fun handleStart(): Boolean {
if (runState.value == RunState.STOP) {
runState.value = RunState.PENDING
runLock.lock()
val tilePlugin = getCurrentTilePlugin()
if (tilePlugin != null) {
tilePlugin.handleStart()
} else {
initServiceEngine(context)
initServiceEngine()
}
return true
}
Expand All @@ -74,28 +74,34 @@ object GlobalState {
}
}

fun handleTryDestroy() {
if (flutterEngine == null) {
destroyServiceEngine()
}
}

fun destroyServiceEngine() {
runLock.withLock {
serviceEngine?.destroy()
serviceEngine = null
}
}

fun initServiceEngine(context: Context) {
fun initServiceEngine() {
if (serviceEngine != null) return
destroyServiceEngine()
runLock.withLock {
serviceEngine = FlutterEngine(context)
serviceEngine?.plugins?.add(VpnPlugin())
serviceEngine = FlutterEngine(FlClashApplication.getAppContext())
serviceEngine?.plugins?.add(VpnPlugin)
serviceEngine?.plugins?.add(AppPlugin())
serviceEngine?.plugins?.add(TilePlugin())
serviceEngine?.plugins?.add(ServicePlugin())
val vpnService = DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
"vpnService"
"_service"
)
serviceEngine?.dartExecutor?.executeDartEntrypoint(
vpnService,
if (flutterEngine == null) listOf("quick") else null
)
}
}
Expand Down
5 changes: 1 addition & 4 deletions android/app/src/main/kotlin/com/follow/clash/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.follow.clash


import com.follow.clash.plugins.AppPlugin
import com.follow.clash.plugins.ServicePlugin
import com.follow.clash.plugins.TilePlugin
import com.follow.clash.plugins.VpnPlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine

class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
flutterEngine.plugins.add(AppPlugin())
flutterEngine.plugins.add(VpnPlugin())
flutterEngine.plugins.add(ServicePlugin())
flutterEngine.plugins.add(ServicePlugin)
flutterEngine.plugins.add(TilePlugin())
GlobalState.flutterEngine = flutterEngine
}
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/kotlin/com/follow/clash/TempActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class TempActivity : Activity() {
super.onCreate(savedInstanceState)
when (intent.action) {
wrapAction("START") -> {
GlobalState.handleStart(applicationContext)
GlobalState.handleStart()
}

wrapAction("STOP") -> {
GlobalState.handleStop()
}

wrapAction("CHANGE") -> {
GlobalState.handleToggle(applicationContext)
GlobalState.handleToggle()
}
}
finishAndRemoveTask()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ fun String.toCIDR(): CIDR {
return CIDR(address, prefixLength)
}


fun ConnectivityManager.resolveDns(network: Network?): List<String> {
val properties = getLinkProperties(network) ?: return listOf()
return properties.dnsServers.map { it.asSocketAddressText(53) }
Expand Down Expand Up @@ -143,7 +142,6 @@ fun Context.getActionPendingIntent(action: String): PendingIntent {
}
}


private fun numericToTextFormat(src: ByteArray): String {
val sb = StringBuilder(39)
for (i in 0 until 8) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.follow.clash.models

data class Process(
val id: Int,
val id: String,
val metadata: Metadata,
)

Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/kotlin/com/follow/clash/models/Props.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ data class VpnOptions(
val ipv4Address: String,
val ipv6Address: String,
val dnsServerAddress: String,
)

data class StartForegroundParams(
val title: String,
val content: String,
)
Loading

0 comments on commit b340fee

Please sign in to comment.