fix: restart tunnel on boot with aovpn
closes #292 also fixed bug where pausing auto tunnel did not pause pinger
This commit is contained in:
parent
a9d7648425
commit
911ed140e0
|
@ -228,8 +228,7 @@ val incrementVersionCode by tasks.registering {
|
|||
}
|
||||
|
||||
tasks.whenTaskAdded {
|
||||
if (name.startsWith("assemble")) {
|
||||
if (name.contains("debug")) return@whenTaskAdded
|
||||
if (name.startsWith("assemble") && !name.lowercase().contains("debug")) {
|
||||
dependsOn(incrementVersionCode)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
|||
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.startTunnelBackground
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
@ -33,7 +34,9 @@ class BootReceiver : BroadcastReceiver() {
|
|||
with(appDataRepository.settings.getSettings()) {
|
||||
if (isRestoreOnBootEnabled) {
|
||||
val activeTunnels = appDataRepository.tunnels.getActive()
|
||||
if (activeTunnels.isNotEmpty()) {
|
||||
val tunState = tunnelService.get().vpnState.value.status
|
||||
if (activeTunnels.isNotEmpty() && tunState != TunnelState.UP) {
|
||||
Timber.i("Starting previously active tunnel")
|
||||
context.startTunnelBackground(activeTunnels.first().id)
|
||||
}
|
||||
if (isAutoTunnelEnabled) {
|
||||
|
|
|
@ -253,7 +253,8 @@ class AutoTunnelService : LifecycleService() {
|
|||
runCatching {
|
||||
do {
|
||||
val vpnState = tunnelService.get().vpnState.value
|
||||
if (vpnState.status == TunnelState.UP) {
|
||||
val settings = appDataRepository.settings.getSettings()
|
||||
if (vpnState.status == TunnelState.UP && !settings.isAutoTunnelPaused) {
|
||||
if (vpnState.tunnelConfig != null) {
|
||||
val config = TunnelConfig.configFromWgQuick(vpnState.tunnelConfig.wgQuick)
|
||||
val results = if (vpnState.tunnelConfig.pingIp != null) {
|
||||
|
|
|
@ -4,15 +4,18 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.NavHostController
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.module.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.plus
|
||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -21,8 +24,9 @@ class AppViewModel
|
|||
@Inject
|
||||
constructor(
|
||||
private val appDataRepository: AppDataRepository,
|
||||
private val tunnelService: TunnelService,
|
||||
tunnelService: TunnelService,
|
||||
val navHostController: NavHostController,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : ViewModel() {
|
||||
|
||||
private val _appUiState = MutableStateFlow(AppUiState())
|
||||
|
@ -42,12 +46,12 @@ constructor(
|
|||
)
|
||||
}
|
||||
.stateIn(
|
||||
viewModelScope,
|
||||
viewModelScope + ioDispatcher,
|
||||
SharingStarted.WhileSubscribed(Constants.SUBSCRIPTION_TIMEOUT),
|
||||
_appUiState.value,
|
||||
)
|
||||
|
||||
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch {
|
||||
fun setTunnels(tunnels: TunnelConfigs) = viewModelScope.launch(ioDispatcher) {
|
||||
_appUiState.emit(
|
||||
_appUiState.value.copy(
|
||||
tunnels = tunnels,
|
||||
|
@ -55,7 +59,7 @@ constructor(
|
|||
)
|
||||
}
|
||||
|
||||
fun onPinLockDisabled() = viewModelScope.launch {
|
||||
fun onPinLockDisabled() = viewModelScope.launch(ioDispatcher) {
|
||||
PinManager.clearPin()
|
||||
appDataRepository.appState.setPinLockEnabled(false)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue