fix: active tunnel bug
This commit is contained in:
parent
48adaae0a0
commit
2c04b9d69c
|
@ -266,7 +266,7 @@ class AutoTunnelService : LifecycleService() {
|
|||
false,
|
||||
wifi.name,
|
||||
)
|
||||
}.distinctUntilChanged().filterNot { it.isWifiConnected && it.wifiName == null }.debounce(500L)
|
||||
}.distinctUntilChanged().filterNot { it.isWifiConnected && it.wifiName == null }
|
||||
}
|
||||
|
||||
private fun combineSettings(): Flow<Pair<Settings, TunnelConfigs>> {
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.os.Build
|
|||
import com.wireguard.android.util.RootShell
|
||||
import com.zaneschepke.wireguardautotunnel.data.repository.SettingsRepository
|
||||
import com.zaneschepke.wireguardautotunnel.module.AppShell
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getCurrentWifiName
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
|
@ -110,7 +111,7 @@ constructor(
|
|||
available = true
|
||||
}
|
||||
is NetworkStatus.CapabilitiesChanged -> mutex.withLock {
|
||||
if (available) {
|
||||
if (available || ssid == null || ssid == Constants.UNREADABLE_SSID) {
|
||||
available = false
|
||||
Timber.d("Getting SSID from capabilities")
|
||||
ssid = getNetworkName(it.networkCapabilities)
|
||||
|
|
|
@ -108,7 +108,7 @@ constructor(
|
|||
}
|
||||
|
||||
private fun isTunnelAlreadyRunning(tunnelConfig: TunnelConfig): Boolean {
|
||||
val isRunning = tunnelConfig == _vpnState.value.tunnelConfig && _vpnState.value.status.isUp()
|
||||
val isRunning = tunnelConfig.id == _vpnState.value.tunnelConfig?.id && _vpnState.value.status.isUp()
|
||||
if (isRunning) Timber.w("Tunnel already running")
|
||||
return isRunning
|
||||
}
|
||||
|
@ -116,16 +116,12 @@ constructor(
|
|||
override suspend fun startTunnel(tunnelConfig: TunnelConfig?, background: Boolean) {
|
||||
withContext(ioDispatcher) {
|
||||
if (tunnelConfig == null || isTunnelAlreadyRunning(tunnelConfig)) return@withContext
|
||||
onBeforeStart(background)
|
||||
updateTunnelConfig(tunnelConfig) // need to update this here
|
||||
withServiceActive {
|
||||
onBeforeStart(background)
|
||||
tunnelControlMutex.withLock {
|
||||
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
||||
updateTunnelState(it, tunnelConfig)
|
||||
onTunnelStart(tunnelConfig, background)
|
||||
}
|
||||
}.onFailure {
|
||||
Timber.e(it)
|
||||
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
||||
updateTunnelState(it, tunnelConfig)
|
||||
onTunnelStart(tunnelConfig, background)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,13 +132,11 @@ constructor(
|
|||
if (_vpnState.value.status.isDown()) return@withContext
|
||||
with(_vpnState.value) {
|
||||
if (tunnelConfig == null) return@withContext
|
||||
tunnelControlMutex.withLock {
|
||||
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
||||
onTunnelStop(tunnelConfig)
|
||||
updateTunnelState(it, null)
|
||||
}.onFailure {
|
||||
Timber.e(it)
|
||||
}
|
||||
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
||||
onTunnelStop(tunnelConfig)
|
||||
updateTunnelState(it, null)
|
||||
}.onFailure {
|
||||
Timber.e(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ class MainActivity : AppCompatActivity() {
|
|||
composable<Route.SplitTunnel> {
|
||||
val args = it.toRoute<Route.SplitTunnel>()
|
||||
val config = appUiState.tunnels.first { it.id == args.id }
|
||||
SplitTunnelScreen(config,viewModel)
|
||||
SplitTunnelScreen(config, viewModel)
|
||||
}
|
||||
composable<Route.TunnelAutoTunnel> {
|
||||
val args = it.toRoute<Route.TunnelOptions>()
|
||||
|
|
|
@ -59,7 +59,6 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
|
||||
import com.zaneschepke.wireguardautotunnel.ui.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.config.ConfigurationTextBox
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel
|
||||
|
@ -72,7 +71,6 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.autotunnel.advanc
|
|||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.InterfaceProxy
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.PeerProxy
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.scaledHeight
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.scaledWidth
|
||||
import org.amnezia.awg.crypto.KeyPair
|
||||
|
|
|
@ -50,7 +50,6 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.scaledWidth
|
|||
|
||||
@Composable
|
||||
fun TunnelAutoTunnelScreen(tunnelConfig: TunnelConfig, settings: Settings, tunnelAutoTunnelViewModel: TunnelAutoTunnelViewModel = hiltViewModel()) {
|
||||
|
||||
var currentText by remember { mutableStateOf("") }
|
||||
|
||||
LaunchedEffect(tunnelConfig.tunnelNetworks) {
|
||||
|
|
Loading…
Reference in New Issue