mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
fix reload logic
This commit is contained in:
@@ -159,7 +159,7 @@ class ProfileBackgroundService : BaseService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshStatusNotification(queueSize: Int) {
|
private fun refreshStatusNotification(queueSize: Int) {
|
||||||
val content = if ( queueSize != 0 )
|
val content = if (queueSize != 0)
|
||||||
getString(R.string.format_in_queue, queueSize)
|
getString(R.string.format_in_queue, queueSize)
|
||||||
else
|
else
|
||||||
getString(R.string.waiting)
|
getString(R.string.waiting)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import android.net.Uri
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.RemoteException
|
import android.os.RemoteException
|
||||||
import com.github.kr328.clash.service.data.ProfileDao
|
import com.github.kr328.clash.service.data.ProfileDao
|
||||||
import com.github.kr328.clash.service.transact.IStreamCallback
|
|
||||||
import com.github.kr328.clash.service.model.ProfileMetadata
|
import com.github.kr328.clash.service.model.ProfileMetadata
|
||||||
import com.github.kr328.clash.service.model.toProfileMetadata
|
import com.github.kr328.clash.service.model.toProfileMetadata
|
||||||
|
import com.github.kr328.clash.service.transact.IStreamCallback
|
||||||
import com.github.kr328.clash.service.util.broadcastProfileChanged
|
import com.github.kr328.clash.service.util.broadcastProfileChanged
|
||||||
import com.github.kr328.clash.service.util.resolveBaseDir
|
import com.github.kr328.clash.service.util.resolveBaseDir
|
||||||
import com.github.kr328.clash.service.util.resolveProfileFile
|
import com.github.kr328.clash.service.util.resolveProfileFile
|
||||||
@@ -150,8 +150,6 @@ class ProfileService : BaseService() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
ProfileReceiver.tryInitialize(this)
|
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
process()
|
process()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
|
|||||||
val settings = ServiceSettings(service)
|
val settings = ServiceSettings(service)
|
||||||
val dnsInject = DnsInjectModule()
|
val dnsInject = DnsInjectModule()
|
||||||
|
|
||||||
|
runtime.install(TunModule(service)) {
|
||||||
|
configure = TunConfigure(settings)
|
||||||
|
}
|
||||||
|
|
||||||
runtime.install(ReloadModule(service)) {
|
runtime.install(ReloadModule(service)) {
|
||||||
onLoaded {
|
onLoaded {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
@@ -70,10 +74,6 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
|
|||||||
else
|
else
|
||||||
runtime.install(StaticNotificationModule(service))
|
runtime.install(StaticNotificationModule(service))
|
||||||
|
|
||||||
runtime.install(TunModule(service)) {
|
|
||||||
configure = TunConfigure(settings)
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.install(dnsInject) {
|
runtime.install(dnsInject) {
|
||||||
dnsOverride = settings.get(ServiceSettings.OVERRIDE_DNS)
|
dnsOverride = settings.get(ServiceSettings.OVERRIDE_DNS)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,4 +95,4 @@ class ClashRuntime(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.github.kr328.clash.service.clash.module
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.*
|
import android.net.*
|
||||||
|
import com.github.kr328.clash.common.utils.Log
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
|
||||||
@@ -50,11 +51,19 @@ class NetworkObserveModule(context: Context) : Module() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onStart() {
|
override suspend fun onStart() {
|
||||||
connectivity.registerNetworkCallback(NetworkRequest.Builder().build(), callback)
|
try {
|
||||||
|
connectivity.registerNetworkCallback(NetworkRequest.Builder().build(), callback)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("Register NetworkCallback failure", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onStop() {
|
override suspend fun onStop() {
|
||||||
connectivity.unregisterNetworkCallback(callback)
|
try {
|
||||||
|
connectivity.unregisterNetworkCallback(callback)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("Unregister NetworkCallback failure", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onNetworkChanged(callback: (Network?, List<InetAddress>) -> Unit) {
|
fun onNetworkChanged(callback: (Network?, List<InetAddress>) -> Unit) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class ReloadModule(private val context: Context) : Module() {
|
|||||||
|
|
||||||
Clash.loadProfile(
|
Clash.loadProfile(
|
||||||
context.resolveProfileFile(active.id),
|
context.resolveProfileFile(active.id),
|
||||||
context.resolveBaseDir(active.id)
|
context.resolveBaseDir(active.id).apply { mkdirs() }
|
||||||
).await()
|
).await()
|
||||||
|
|
||||||
val remove = SelectedProxyDao.querySelectedForProfile(active.id)
|
val remove = SelectedProxyDao.querySelectedForProfile(active.id)
|
||||||
|
|||||||
@@ -153,11 +153,6 @@ object DatabaseMigrations {
|
|||||||
|
|
||||||
database.query("SELECT name, type, uri, source, active, update_interval, id FROM _profiles")
|
database.query("SELECT name, type, uri, source, active, update_interval, id FROM _profiles")
|
||||||
.use { cursor ->
|
.use { cursor ->
|
||||||
Global.application.filesDir.resolve(Constants.CLASH_DIR).listFiles()
|
|
||||||
?.forEach {
|
|
||||||
it.deleteRecursively()
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.moveToFirst()
|
cursor.moveToFirst()
|
||||||
while (!cursor.isAfterLast) {
|
while (!cursor.isAfterLast) {
|
||||||
// old
|
// old
|
||||||
|
|||||||
Reference in New Issue
Block a user