Optimization (#3842)

* Update PluginUtil.kt

fix kotlin.UninitializedProertyAcessException:lateinit property procService has not been initalized.

* Update ProcessService.kt
This commit is contained in:
886963226
2024-11-04 09:42:17 +08:00
committed by GitHub
parent 0b3c106c6f
commit 8549b5ea46
2 changed files with 7 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ import kotlinx.coroutines.launch
class ProcessService {
private val TAG = ANG_PACKAGE
private lateinit var process: Process
private var process: Process? = null
fun runProcess(context: Context, cmd: MutableList<String>) {
Log.d(TAG, cmd.toString())
@@ -24,7 +24,7 @@ class ProcessService {
CoroutineScope(Dispatchers.IO).launch {
Thread.sleep(50L)
Log.d(TAG, "runProcess check")
process.waitFor()
process?.waitFor()
Log.d(TAG, "runProcess exited")
}
Log.d(TAG, process.toString())
@@ -42,4 +42,4 @@ class ProcessService {
Log.d(TAG, e.toString())
}
}
}
}

View File

@@ -14,7 +14,9 @@ object PluginUtil {
//private const val HYSTERIA2 = "hysteria2-plugin"
private const val HYSTERIA2 = "libhysteria2.so"
private const val TAG = ANG_PACKAGE
private lateinit var procService: ProcessService
private val procService: ProcessService by lazy {
ProcessService()
}
// fun initPlugin(name: String): PluginManager.InitResult {
// return PluginManager.init(name)!!
@@ -27,7 +29,6 @@ object PluginUtil {
val configFile = genConfigHy2(context, config, domainPort) ?: return
val cmd = genCmdHy2(context, configFile)
procService = ProcessService()
procService.runProcess(context, cmd)
}
}
@@ -94,4 +95,4 @@ object PluginUtil {
Log.d(TAG, e.toString())
}
}
}
}