service refactored

This commit is contained in:
Kr328 committed 2020-01-21 20:27:05 +08:00
1 parent e9e59f6026
commit cca7ec81e1
2 files changed
+17

No files matched your search

@@ -1,6 +1,7 @@
package com.github.kr328.clash.service
import android.content.Context
import android.content.Intent
import android.net.Uri
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.service.data.ClashDatabase
@@ -8,6 +9,7 @@ import com.github.kr328.clash.service.data.ClashProfileEntity
import com.github.kr328.clash.service.ipc.ParcelableCompletedFuture
import com.github.kr328.clash.service.util.DefaultThreadPool
import com.github.kr328.clash.service.util.FileUtils
import com.github.kr328.clash.service.util.sendBroadcastSelf
class ClashProfileManager(private val context: Context, private val database: ClashDatabase) :
IClashProfileManager.Stub() {
@@ -29,6 +31,8 @@ class ClashProfileManager(private val context: Context, private val database: Cl
result.complete(null)
database.openClashProfileDao().touchProfile(id)
sendChangedBroadcast()
},
onFailure = {
result.completeExceptionally(it)
@@ -62,6 +66,8 @@ class ClashProfileManager(private val context: Context, private val database: Cl
)
)
sendChangedBroadcast()
result.complete(null)
},
onFailure = {
@@ -113,4 +119,13 @@ class ClashProfileManager(private val context: Context, private val database: Cl
}
}
}
private fun sendChangedBroadcast() {
val active = database.openClashProfileDao().queryActiveProfile()
context.sendBroadcastSelf(
Intent(Intents.INTENT_ACTION_PROFILE_CHANGED)
.putExtra(Intents.INTENT_ACTION_PROFILE_ACTIVE_NAME, active?.name)
)
}
}
@@ -12,4 +12,6 @@ object Intents {
const val INTENT_ACTION_CLASH_STOP_REASON =
"${BuildConfig.LIBRARY_PACKAGE_NAME}.intent.extra.clash.stop.reason"
const val INTENT_ACTION_PROFILE_ACTIVE_NAME =
"${BuildConfig.LIBRARY_PACKAGE_NAME}.intent.extra.profile.active.name"
}