parent
63d46c1817
commit
b15cdbce7c
|
@ -94,7 +94,7 @@ constructor(
|
||||||
|
|
||||||
override suspend fun startTunnel(tunnelConfig: TunnelConfig, background: Boolean): Result<TunnelState> {
|
override suspend fun startTunnel(tunnelConfig: TunnelConfig, background: Boolean): Result<TunnelState> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
if (runningHandle.get() == true && tunnelConfig == vpnState.value.tunnelConfig) {
|
if (runningHandle.get() && tunnelConfig == vpnState.value.tunnelConfig) {
|
||||||
Timber.w("Tunnel already running")
|
Timber.w("Tunnel already running")
|
||||||
return@withContext Result.success(vpnState.value.status)
|
return@withContext Result.success(vpnState.value.status)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ constructor(
|
||||||
val settings = appDataRepository.settings.getSettings()
|
val settings = appDataRepository.settings.getSettings()
|
||||||
if (background || settings.isKernelEnabled) startBackgroundService()
|
if (background || settings.isKernelEnabled) startBackgroundService()
|
||||||
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
||||||
emitTunnelState(it)
|
updateTunnelState(it)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
onStartFailed()
|
onStartFailed()
|
||||||
|
@ -115,7 +115,7 @@ constructor(
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
onBeforeStop(tunnelConfig)
|
onBeforeStop(tunnelConfig)
|
||||||
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
setState(tunnelConfig, TunnelState.DOWN).onSuccess {
|
||||||
emitTunnelState(it)
|
updateTunnelState(it)
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
onStopFailed()
|
onStopFailed()
|
||||||
|
@ -136,7 +136,7 @@ constructor(
|
||||||
private suspend fun toggleTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
private suspend fun toggleTunnel(tunnelConfig: TunnelConfig): Result<TunnelState> {
|
||||||
return withContext(ioDispatcher) {
|
return withContext(ioDispatcher) {
|
||||||
setState(tunnelConfig, TunnelState.TOGGLE).onSuccess {
|
setState(tunnelConfig, TunnelState.TOGGLE).onSuccess {
|
||||||
emitTunnelState(it)
|
updateTunnelState(it)
|
||||||
resetBackendStatistics()
|
resetBackendStatistics()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
|
@ -191,12 +191,13 @@ constructor(
|
||||||
resetBackendStatistics()
|
resetBackendStatistics()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitTunnelState(state: TunnelState) {
|
private fun updateTunnelState(state: TunnelState) {
|
||||||
_vpnState.tryEmit(
|
_vpnState.tryEmit(
|
||||||
_vpnState.value.copy(
|
_vpnState.value.copy(
|
||||||
status = state,
|
status = state,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
serviceManager.requestTunnelTileUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitBackendStatistics(statistics: TunnelStatistics) {
|
private fun emitBackendStatistics(statistics: TunnelStatistics) {
|
||||||
|
@ -264,11 +265,11 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStateChange(newState: Tunnel.State) {
|
override fun onStateChange(newState: Tunnel.State) {
|
||||||
emitTunnelState(TunnelState.from(newState))
|
updateTunnelState(TunnelState.from(newState))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStateChange(state: State) {
|
override fun onStateChange(state: State) {
|
||||||
emitTunnelState(TunnelState.from(state))
|
updateTunnelState(TunnelState.from(state))
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -74,7 +74,7 @@ constructor(
|
||||||
val configurationChange = _configurationChange.asStateFlow()
|
val configurationChange = _configurationChange.asStateFlow()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch(ioDispatcher) {
|
viewModelScope.launch {
|
||||||
initPin()
|
initPin()
|
||||||
initAutoTunnel()
|
initAutoTunnel()
|
||||||
initTunnel()
|
initTunnel()
|
||||||
|
|
|
@ -61,7 +61,6 @@ import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
import com.zaneschepke.wireguardautotunnel.util.extensions.requestAutoTunnelTileServiceUpdate
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.requestTunnelTileServiceStateUpdate
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
@ -97,10 +96,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
val configurationChange by viewModel.configurationChange.collectAsStateWithLifecycle()
|
val configurationChange by viewModel.configurationChange.collectAsStateWithLifecycle()
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
|
||||||
LaunchedEffect(appUiState.tunnels) {
|
|
||||||
requestTunnelTileServiceStateUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
LaunchedEffect(configurationChange) {
|
LaunchedEffect(configurationChange) {
|
||||||
if (configurationChange) {
|
if (configurationChange) {
|
||||||
Intent(this@MainActivity, MainActivity::class.java).also {
|
Intent(this@MainActivity, MainActivity::class.java).also {
|
||||||
|
|
Loading…
Reference in New Issue