diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/OverviewFragment.kt b/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/OverviewFragment.kt index 75ac88c..45c12db 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/OverviewFragment.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/dashboard/OverviewFragment.kt @@ -25,6 +25,7 @@ import io.nekohasekai.sfa.databinding.ViewClashModeButtonBinding import io.nekohasekai.sfa.databinding.ViewProfileItemBinding import io.nekohasekai.sfa.ktx.errorDialogBuilder import io.nekohasekai.sfa.ktx.getAttrColor +import io.nekohasekai.sfa.ktx.launchCustomTab import io.nekohasekai.sfa.ui.MainActivity import io.nekohasekai.sfa.utils.CommandClient import kotlinx.coroutines.CoroutineScope @@ -40,7 +41,7 @@ class OverviewFragment : Fragment() { private val activity: MainActivity? get() = super.getActivity() as MainActivity? private var binding: FragmentDashboardOverviewBinding? = null private val statusClient = - CommandClient(lifecycleScope, CommandClient.ConnectionType.Status, StatusClient()) + CommandClient(lifecycleScope, CommandClient.ConnectionType.Status, StatusClient(), true) private val clashModeClient = CommandClient(lifecycleScope, CommandClient.ConnectionType.ClashMode, ClashModeClient()) @@ -171,6 +172,10 @@ class OverviewFragment : Fragment() { } } + override fun openURL(url: String) { + requireContext().launchCustomTab(url) + } + } inner class ClashModeClient : CommandClient.Handler { diff --git a/app/src/main/java/io/nekohasekai/sfa/utils/CommandClient.kt b/app/src/main/java/io/nekohasekai/sfa/utils/CommandClient.kt index 6b9582f..2e75c5b 100644 --- a/app/src/main/java/io/nekohasekai/sfa/utils/CommandClient.kt +++ b/app/src/main/java/io/nekohasekai/sfa/utils/CommandClient.kt @@ -20,7 +20,8 @@ import kotlinx.coroutines.launch open class CommandClient( private val scope: CoroutineScope, private val connectionType: ConnectionType, - private val handler: Handler + private val handler: Handler, + private val isMainClient: Boolean = false ) { enum class ConnectionType { @@ -31,16 +32,20 @@ open class CommandClient( fun onConnected() {} fun onDisconnected() {} + fun updateStatus(status: StatusMessage) {} - fun updateGroups(newGroups: MutableList) {} + fun openURL(url: String) {} + fun clearLogs() {} fun appendLogs(message: List) {} + + fun updateGroups(newGroups: MutableList) {} + fun initializeClashMode(modeList: List, currentMode: String) {} fun updateClashMode(newMode: String) {} } - private var commandClient: CommandClient? = null private val clientHandler = ClientHandler() fun connect() { @@ -52,7 +57,8 @@ open class CommandClient( ConnectionType.Log -> Libbox.CommandLog ConnectionType.ClashMode -> Libbox.CommandClashMode } - options.statusInterval = 2 * 1000 * 1000 * 1000 + options.isMainClient = isMainClient + options.statusInterval = 1 * 1000 * 1000 * 1000 val commandClient = CommandClient(clientHandler, options) scope.launch(Dispatchers.IO) { for (i in 1..10) { @@ -119,13 +125,14 @@ open class CommandClient( handler.appendLogs(messageList.toList()) } - override fun writeStatus(message: StatusMessage?) { - if (message == null) { - return - } + override fun writeStatus(message: StatusMessage) { handler.updateStatus(message) } + override fun openURL(url: String) { + handler.openURL(url) + } + override fun initializeClashMode(modeList: StringIterator, currentMode: String) { handler.initializeClashMode(modeList.toList(), currentMode) }