Update API usage

This commit is contained in:
世界
2023-08-24 23:25:35 +08:00
parent 1d578acb74
commit 065c62118e
4 changed files with 95 additions and 35 deletions

View File

@@ -8,20 +8,22 @@ import io.nekohasekai.libbox.Libbox
import io.nekohasekai.libbox.OutboundGroup
import io.nekohasekai.libbox.OutboundGroupIterator
import io.nekohasekai.libbox.StatusMessage
import io.nekohasekai.libbox.StringIterator
import io.nekohasekai.sfa.ktx.toList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
class CommandClient(
open class CommandClient(
private val scope: CoroutineScope,
private val connectionType: ConnectionType,
private val handler: Handler
) {
enum class ConnectionType {
Status, Groups, Log
Status, Groups, Log, ClashMode
}
interface Handler {
@@ -31,6 +33,8 @@ class CommandClient(
fun updateStatus(status: StatusMessage) {}
fun updateGroups(groups: List<OutboundGroup>) {}
fun appendLog(message: String) {}
fun initializeClashMode(modeList: List<String>, currentMode: String) {}
fun updateClashMode(newMode: String) {}
}
@@ -44,6 +48,7 @@ class CommandClient(
ConnectionType.Status -> Libbox.CommandStatus
ConnectionType.Groups -> Libbox.CommandGroup
ConnectionType.Log -> Libbox.CommandLog
ConnectionType.ClashMode -> Libbox.CommandClashMode
}
options.statusInterval = 2 * 1000 * 1000 * 1000
val commandClient = CommandClient(clientHandler, options)
@@ -115,6 +120,14 @@ class CommandClient(
handler.updateStatus(message)
}
override fun initializeClashMode(modeList: StringIterator, currentMode: String) {
handler.initializeClashMode(modeList.toList(), currentMode)
}
override fun updateClashMode(newMode: String) {
handler.updateClashMode(newMode)
}
}
}