Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions app/src/main/java/com/github/kr328/clash/ExternalControlActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.github.kr328.clash.common.util.intent
import com.github.kr328.clash.common.util.setUUID
import com.github.kr328.clash.design.MainDesign
import com.github.kr328.clash.design.ui.ToastDuration
import com.github.kr328.clash.remote.Remote
import com.github.kr328.clash.remote.StatusClient
import com.github.kr328.clash.service.model.Profile
import com.github.kr328.clash.util.startClashService
Expand Down Expand Up @@ -56,30 +55,33 @@ class ExternalControlActivity : Activity(), CoroutineScope by MainScope() {
return
}

Intents.ACTION_TOGGLE_CLASH -> if(Remote.broadcasts.clashRunning) {
stopClash()
}
else {
startClash()
}

Intents.ACTION_START_CLASH -> if(!Remote.broadcasts.clashRunning) {
startClash()
Intents.ACTION_TOGGLE_CLASH -> {
if (isClashRunning()) {
stopClash()
} else {
startClash()
}
}
else {
Toast.makeText(this, R.string.external_control_started, Toast.LENGTH_LONG).show()

Intents.ACTION_START_CLASH -> {
if (isClashRunning()) {
Toast.makeText(this, R.string.external_control_started, Toast.LENGTH_LONG).show()
} else {
startClash()
}
}

Intents.ACTION_STOP_CLASH -> if(Remote.broadcasts.clashRunning) {
Intents.ACTION_STOP_CLASH -> {
stopClash()
}
else {
Toast.makeText(this, R.string.external_control_stopped, Toast.LENGTH_LONG).show()
}
}
return finish()
}

private fun isClashRunning(): Boolean {
return StatusClient(this).currentProfile() != null
}

private fun startClash() {
// if (currentProfile == null) {
// Toast.makeText(this, R.string.no_profile_selected, Toast.LENGTH_LONG).show()
Expand Down
Loading