use default dispatcher instead of main
This commit is contained in:
7 files changed
+13
-17
No files matched your search
@@ -5,10 +5,10 @@ import android.content.Context
|
||||
import com.github.kr328.clash.common.utils.createLanguageConfigurationContext
|
||||
import com.github.kr328.clash.service.settings.ServiceSettings
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
|
||||
abstract class BaseService : Service(), CoroutineScope by MainScope() {
|
||||
abstract class BaseService : Service(), CoroutineScope by CoroutineScope(Dispatchers.Default) {
|
||||
lateinit var settings: ServiceSettings
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
|
||||
@@ -8,12 +8,9 @@ import com.github.kr328.clash.service.data.SelectedProxyDao
|
||||
import com.github.kr328.clash.service.data.SelectedProxyEntity
|
||||
import com.github.kr328.clash.service.transact.IStreamCallback
|
||||
import com.github.kr328.clash.service.transact.ParcelableContainer
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ClashManager(parent: CoroutineScope) :
|
||||
IClashManager.Stub(), CoroutineScope by parent {
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class ClashManager: IClashManager.Stub() {
|
||||
override fun setProxyMode(mode: String?) {
|
||||
Clash.setProxyMode(requireNotNull(mode))
|
||||
}
|
||||
@@ -29,8 +26,8 @@ class ClashManager(parent: CoroutineScope) :
|
||||
override fun setSelector(proxy: String?, selected: String?) {
|
||||
require(proxy != null && selected != null)
|
||||
|
||||
launch {
|
||||
val current = ProfileDao.queryActive() ?: return@launch
|
||||
runBlocking {
|
||||
val current = ProfileDao.queryActive() ?: return@runBlocking
|
||||
|
||||
SelectedProxyDao.setSelectedForProfile(SelectedProxyEntity(current.id, proxy, selected))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@ import android.os.IBinder
|
||||
|
||||
class ClashManagerService : BaseService() {
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return ClashManager(this)
|
||||
return ClashManager()
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import com.github.kr328.clash.service.clash.ClashRuntime
|
||||
import com.github.kr328.clash.service.clash.module.*
|
||||
import com.github.kr328.clash.service.clash.module.CloseModule
|
||||
import com.github.kr328.clash.service.clash.module.DynamicNotificationModule
|
||||
import com.github.kr328.clash.service.clash.module.ReloadModule
|
||||
import com.github.kr328.clash.service.clash.module.StaticNotificationModule
|
||||
import com.github.kr328.clash.service.settings.ServiceSettings
|
||||
import com.github.kr328.clash.service.util.broadcastClashStarted
|
||||
import com.github.kr328.clash.service.util.broadcastClashStopped
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.webkit.URLUtil
|
||||
import com.github.kr328.clash.common.utils.Log
|
||||
import com.github.kr328.clash.core.Clash
|
||||
import com.github.kr328.clash.service.data.ProfileDao
|
||||
import com.github.kr328.clash.service.model.Profile
|
||||
@@ -17,8 +16,6 @@ import kotlinx.coroutines.future.await
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.lang.Exception
|
||||
import java.lang.NullPointerException
|
||||
import java.util.*
|
||||
|
||||
object ProfileProcessor {
|
||||
|
||||
@@ -7,11 +7,11 @@ import com.github.kr328.clash.service.clash.module.*
|
||||
import com.github.kr328.clash.service.settings.ServiceSettings
|
||||
import com.github.kr328.clash.service.util.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class TunService : VpnService(), CoroutineScope by MainScope() {
|
||||
class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.Default) {
|
||||
companion object {
|
||||
// from https://github.com/shadowsocks/shadowsocks-android/blob/master/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
|
||||
private const val VPN_MTU = 9000
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.github.kr328.clash.core.Clash
|
||||
import com.github.kr328.clash.service.util.parseCIDR
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.lang.NullPointerException
|
||||
|
||||
class TunModule(private val service: VpnService) : Module() {
|
||||
interface Configure {
|
||||
|
||||
Reference in new issue
Block a user