parent
246916ab0d
commit
a3eb53f90f
|
@ -118,11 +118,11 @@ constructor(
|
||||||
if (tunnelConfig == null || isTunnelAlreadyRunning(tunnelConfig)) return@withContext
|
if (tunnelConfig == null || isTunnelAlreadyRunning(tunnelConfig)) return@withContext
|
||||||
updateTunnelConfig(tunnelConfig) // need to update this here
|
updateTunnelConfig(tunnelConfig) // need to update this here
|
||||||
withServiceActive {
|
withServiceActive {
|
||||||
onBeforeStart()
|
onBeforeStart(background)
|
||||||
tunnelControlMutex.withLock {
|
tunnelControlMutex.withLock {
|
||||||
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
setState(tunnelConfig, TunnelState.UP).onSuccess {
|
||||||
updateTunnelState(it, tunnelConfig)
|
updateTunnelState(it, tunnelConfig)
|
||||||
onTunnelStart(tunnelConfig)
|
onTunnelStart(tunnelConfig, background)
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.e(it)
|
Timber.e(it)
|
||||||
|
@ -204,19 +204,19 @@ constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun onBeforeStart() {
|
private suspend fun onBeforeStart(background: Boolean) {
|
||||||
with(_vpnState.value) {
|
with(_vpnState.value) {
|
||||||
if (status.isUp()) stopTunnel() else clearJobsAndStats()
|
if (status.isUp()) stopTunnel() else clearJobsAndStats()
|
||||||
if (isKernelBackend == true) serviceManager.startBackgroundService(tunnelConfig)
|
if (isKernelBackend == true || background) serviceManager.startBackgroundService(tunnelConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun onTunnelStart(tunnelConfig: TunnelConfig) {
|
private suspend fun onTunnelStart(tunnelConfig: TunnelConfig, background: Boolean) {
|
||||||
startActiveTunnelJobs()
|
startActiveTunnelJobs()
|
||||||
if (_vpnState.value.status.isUp()) {
|
if (_vpnState.value.status.isUp()) {
|
||||||
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = true))
|
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = true))
|
||||||
}
|
}
|
||||||
if (isKernelBackend == false) launchUserspaceTunnelNotification()
|
if (isKernelBackend == false && !background) launchUserspaceTunnelNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchUserspaceTunnelNotification() {
|
private fun launchUserspaceTunnelNotification() {
|
||||||
|
@ -233,14 +233,13 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun onTunnelStop(tunnelConfig: TunnelConfig) {
|
private suspend fun onTunnelStop(tunnelConfig: TunnelConfig) {
|
||||||
|
runCatching {
|
||||||
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = false))
|
appDataRepository.tunnels.save(tunnelConfig.copy(isActive = false))
|
||||||
if (isKernelBackend == true) {
|
|
||||||
serviceManager.stopBackgroundService()
|
serviceManager.stopBackgroundService()
|
||||||
} else {
|
|
||||||
notificationService.remove(VPN_NOTIFICATION_ID)
|
notificationService.remove(VPN_NOTIFICATION_ID)
|
||||||
}
|
|
||||||
clearJobsAndStats()
|
clearJobsAndStats()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun clearJobsAndStats() {
|
private fun clearJobsAndStats() {
|
||||||
cancelActiveTunnelJobs()
|
cancelActiveTunnelJobs()
|
||||||
|
|
Loading…
Reference in New Issue