diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 79edb9e..b509f5d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) } } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/receiver/BootReceiver.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/receiver/BootReceiver.kt index 9a12b63..eb03f3e 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/receiver/BootReceiver.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/receiver/BootReceiver.kt @@ -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) { diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/AutoTunnelService.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/AutoTunnelService.kt index 10e0432..a863ef4 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/AutoTunnelService.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/foreground/AutoTunnelService.kt @@ -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) { diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt index a4ffafe..22e33e6 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt @@ -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) }