Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 7 additions & 31 deletions app/src/common/util/ProxyAutoStartHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import android.net.VpnService
import com.github.yumeyucca.yumebox.core.model.RunMode
import com.github.yumeyucca.yumebox.core.util.AutoStartSessionGate
import com.github.yumeyucca.yumebox.runtime.api.Profile
import com.github.yumeyucca.yumebox.runtime.service.StatusProvider
import com.github.yumeyucca.yumebox.runtime.service.RuntimeCoordinator
import com.github.yumeyucca.yumebox.runtime.service.util.AutoStartExecutionGate
import com.github.yumeyucca.yumebox.runtime.service.util.AutoStartUpdatePolicy
import kotlinx.coroutines.CancellationException
import timber.log.Timber

Expand Down Expand Up @@ -75,7 +74,7 @@ object ProxyAutoStartHelper {
return
}

if (deps.proxyFacade.runtimeSnapshot.value.running || StatusProvider.serviceRunning) {
if (deps.proxyFacade.runtimeSnapshot.value.running || RuntimeCoordinator.state.value.active) {
return
}

Expand Down Expand Up @@ -104,35 +103,12 @@ object ProxyAutoStartHelper {
context(deps: AutoStartDependencies)
@Suppress("TooGenericExceptionCaught")
private suspend fun tryUpdateActiveProfileOnStart(activeProfile: Profile?) {
when (
AutoStartUpdatePolicy.decide(
autoUpdateEnabled = deps.appSettingsStorage.autoUpdateCurrentProfileOnStart.value,
activeProfile = activeProfile,
skipForPostUpdateColdStart = false,
)
) {
AutoStartUpdatePolicy.Decision.Proceed -> Unit
AutoStartUpdatePolicy.Decision.AutoUpdateDisabled -> return
AutoStartUpdatePolicy.Decision.SkipPostUpdateColdStart -> {
Timber.tag(TAG).d("Skip auto update: post-update cold-start marker consumed")
return
}

AutoStartUpdatePolicy.Decision.NoActiveProfile -> {
Timber.tag(TAG).d("Skip auto update: no active profile")
return
}

AutoStartUpdatePolicy.Decision.UnsupportedProfileType -> {
Timber.tag(TAG)
.d("Skip auto update: unsupported profile type=${activeProfile?.type}")
return
}

AutoStartUpdatePolicy.Decision.SkipColdStartReason -> return
}

if (!deps.appSettingsStorage.autoUpdateCurrentProfileOnStart.value) return
val target = activeProfile ?: return
if (target.type != Profile.Type.Url) {
Timber.tag(TAG).d("Skip auto update: unsupported profile type=${target.type}")
return
}
try {
deps.profilesRepository.updateProfile(target.uuid)
Timber.tag(TAG).i("Auto update on start ok: ${target.uuid}")
Expand Down
23 changes: 9 additions & 14 deletions app/src/di/CoreDiModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import com.github.yumeyucca.yumebox.data.network.NetworkInfoService
import com.github.yumeyucca.yumebox.data.store.*
import com.github.yumeyucca.yumebox.data.store.room.createTrafficStatisticsDao
import com.github.yumeyucca.yumebox.domain.model.TrafficData
import com.github.yumeyucca.yumebox.runtime.api.RuntimeOwner
import com.github.yumeyucca.yumebox.runtime.client.ProfilesRepository
import com.github.yumeyucca.yumebox.runtime.client.ProxyFacade
import com.github.yumeyucca.yumebox.runtime.client.RuntimeStateMapper
import com.github.yumeyucca.yumebox.runtime.client.access.RuntimeAccess
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -89,8 +91,8 @@ val appDataRuntimeModule = module {
resolveActiveMode = {
proxyFacade.runtimeSnapshot.value.let { snapshot ->
snapshot.runMode.takeIf {
snapshot.owner != com.github.yumeyucca.yumebox.runtime.api.RuntimeOwner.None &&
snapshot.owner != com.github.yumeyucca.yumebox.runtime.api.RuntimeOwner.RemoteController
snapshot.owner != RuntimeOwner.None &&
snapshot.owner != RuntimeOwner.RemoteController
}
}
},
Expand All @@ -110,14 +112,12 @@ val appDataRuntimeModule = module {
ProvidersController(
context = appContext,
queryProvidersAction = {
com.github.yumeyucca.yumebox.runtime.client.access.RuntimeAccess.connect(appContext)
com.github.yumeyucca.yumebox.runtime.client.access.RuntimeAccess.core()
.queryProviders()
RuntimeAccess.connect(appContext)
RuntimeAccess.core().queryProviders()
},
updateProviderAction = { type, name ->
com.github.yumeyucca.yumebox.runtime.client.access.RuntimeAccess.connect(appContext)
com.github.yumeyucca.yumebox.runtime.client.access.RuntimeAccess.core()
.updateProvider(type, name)
RuntimeAccess.connect(appContext)
RuntimeAccess.core().updateProvider(type, name)
},
)
}
Expand All @@ -129,12 +129,7 @@ val appDataRuntimeModule = module {
single<OverrideConfigProvider> { get<OverrideConfigStore>() }

single { OverrideResolver(get(), get()) }
single {
val appContext = androidContext()
OverrideService(appContext, get()) {
// Override-change reload hook (RootTun removed; VPN reloads via the normal path).
}
}
single { OverrideService(androidContext(), get()) }
single {
val profilesRepository = get<ProfilesRepository>()
ActiveProfileOverrideReloader(
Expand Down
3 changes: 1 addition & 2 deletions app/src/screen/settings/NetworkSettingsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ class NetworkSettingsViewModel(
_activeKernelId.value = KernelManager.activeKernelId(getApplication())
viewModelScope.launch {
refreshInstalledKernelCommits()
val root = RootAccessSupport.evaluateAsync(getApplication()).canStartRoot
_rootAvailable.value = root
_rootAvailable.value = RootAccessSupport.isGranted()
refreshEbpfAvailability()
}
}
Expand Down
42 changes: 0 additions & 42 deletions core/src/core/model/UiConfiguration.kt

This file was deleted.

2 changes: 0 additions & 2 deletions data/src/data/controller/OverrideService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import timber.log.Timber
class OverrideService(
context: Context,
private val resolver: OverrideResolver,
private val onRuntimeOverrideChanged: () -> Unit = {},
) {
private val appContext = context.appContextOrSelf

Expand Down Expand Up @@ -74,6 +73,5 @@ class OverrideService(
Intent(Intents.actionOverrideChanged(appContext.packageName))
.setPackage(appContext.packageName)
)
onRuntimeOverrideChanged()
}
}
35 changes: 15 additions & 20 deletions runtime/api/src/runtime/api/CoreApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,35 @@

package com.github.yumeyucca.yumebox.runtime.api

import com.github.yumeyucca.yumebox.core.model.*
import com.github.yumeyucca.yumebox.core.model.ConnectionSnapshot
import com.github.yumeyucca.yumebox.core.model.Provider
import com.github.yumeyucca.yumebox.core.model.ProviderList
import com.github.yumeyucca.yumebox.core.model.ProxyGroup
import com.github.yumeyucca.yumebox.core.model.ProxySort
import com.github.yumeyucca.yumebox.core.model.RuntimeRule

interface CoreApi {
fun queryTunnelState(): TunnelState
suspend fun queryTrafficNow(): Long

fun queryTrafficNow(): Long
suspend fun queryTrafficTotal(): Long

fun queryTrafficTotal(): Long
suspend fun queryConnections(): ConnectionSnapshot

fun queryConnections(): ConnectionSnapshot
suspend fun queryAllProxyGroups(excludeNotSelectable: Boolean): List<ProxyGroup>

fun queryAllProxyGroups(excludeNotSelectable: Boolean): List<ProxyGroup>
suspend fun queryProxyGroup(name: String, proxySort: ProxySort): ProxyGroup

fun queryProxyGroupNames(excludeNotSelectable: Boolean): List<String>

fun queryProxyGroup(name: String, proxySort: ProxySort): ProxyGroup

fun queryConfiguration(): UiConfiguration

fun queryProviders(): ProviderList
suspend fun queryProviders(): ProviderList

/** Live rules from `GET /rules` (runtime rule list, not custom-routing editor). */
fun queryRules(): List<RuntimeRule>
suspend fun queryRules(): List<RuntimeRule>

/** Temporarily toggle [rule], then return the controller-confirmed runtime rule list. */
suspend fun setRuleDisabled(rule: RuntimeRule, disabled: Boolean): List<RuntimeRule>

fun patchSelector(group: String, name: String): Boolean
suspend fun patchSelector(group: String, name: String): Boolean

fun closeConnection(id: String): Boolean

fun closeAllConnections()
suspend fun closeConnection(id: String): Boolean

/** Tests every member of [group] and returns its directly measured delays by proxy name. */
suspend fun healthCheck(group: String): Map<String, Int>
Expand All @@ -60,7 +57,5 @@ interface CoreApi {

suspend fun updateProvider(type: Provider.Type, name: String)

fun requestStop()

fun subscribeLogs(observer: LogObserver): LogSubscription
}
55 changes: 0 additions & 55 deletions runtime/api/src/runtime/api/CoreAsyncQueries.kt

This file was deleted.

45 changes: 1 addition & 44 deletions runtime/api/src/runtime/api/Intents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,24 @@
*
*/

@file:Suppress("UnusedSymbol")

package com.github.yumeyucca.yumebox.runtime.api


object Intents {
private fun intentAction(packageName: String, actionName: String): String =
"$packageName.intent.action.$actionName"

fun actionStartRuntime(packageName: String): String = "$packageName.action.START_CLASH"

fun actionStopRuntime(packageName: String): String = "$packageName.action.STOP_CLASH"

fun actionServiceRecreated(packageName: String): String =
intentAction(packageName, "CLASH_RECREATED")

fun actionRuntimeStarted(packageName: String): String =
intentAction(packageName, "CLASH_STARTED")

fun actionRuntimeStopped(packageName: String): String =
intentAction(packageName, "CLASH_STOPPED")

fun actionRuntimeRequestStop(packageName: String): String =
intentAction(packageName, "CLASH_REQUEST_STOP")

fun actionProfileChanged(packageName: String): String =
intentAction(packageName, "PROFILE_CHANGED")

fun actionProfileLoaded(packageName: String): String =
intentAction(packageName, "PROFILE_LOADED")

fun actionOverrideChanged(packageName: String): String =
intentAction(packageName, "OVERRIDE_CHANGED")

fun actionRootRuntimeFailed(packageName: String): String =
intentAction(packageName, "ROOT_RUNTIME_FAILED")

val ACTION_SERVICE_RECREATED: String
get() = actionServiceRecreated(packageName)

val ACTION_RUNTIME_STARTED: String
get() = actionRuntimeStarted(packageName)

val ACTION_RUNTIME_STOPPED: String
get() = actionRuntimeStopped(packageName)

val ACTION_RUNTIME_REQUEST_STOP: String
get() = actionRuntimeRequestStop(packageName)

val ACTION_PROFILE_CHANGED: String
get() = actionProfileChanged(packageName)

val ACTION_PROFILE_LOADED: String
get() = actionProfileLoaded(packageName)

val ACTION_OVERRIDE_CHANGED: String
get() = actionOverrideChanged(packageName)

const val EXTRA_STOP_REASON = "stop_reason"
const val EXTRA_RESTART = "restart"
const val EXTRA_RUNTIME_MODE = "runtime_mode"
const val EXTRA_UUID = "uuid"
const val EXTRA_AFFECTS_RUNTIME = "affects_runtime"
}
}
Loading
Loading