Skip to content

Commit 8860b45

Browse files
committed
fix: service manager bug
1 parent e220b26 commit 8860b45

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

app/src/main/java/com/zaneschepke/wireguardautotunnel/core/service/ServiceManager.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class ServiceManager @Inject constructor(
5454
applicationScope.launch(ioDispatcher) {
5555
val settings = appDataRepository.settings.get()
5656
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true))
57-
if (autoTunnelService.isCompleted && autoTunnelService.isActive) {
57+
if (autoTunnelService.isCompleted) {
5858
_autoTunnelActive.update { true }
5959
return@launch
6060
}
6161
runCatching {
62-
autoTunnelService = CompletableDeferred() // Reset
62+
autoTunnelService = CompletableDeferred()
6363
startService(AutoTunnelService::class.java, background)
6464
val service = withTimeoutOrNull(SERVICE_START_TIMEOUT) { autoTunnelService.await() }
6565
?: throw IllegalStateException("AutoTunnelService start timed out")
@@ -75,7 +75,7 @@ class ServiceManager @Inject constructor(
7575

7676
fun startBackgroundService(tunnelConf: TunnelConf) {
7777
applicationScope.launch(ioDispatcher) {
78-
if (backgroundService.isCompleted && backgroundService.isActive) return@launch
78+
if (backgroundService.isCompleted) return@launch
7979
runCatching {
8080
backgroundService = CompletableDeferred()
8181
startService(TunnelForegroundService::class.java, true)
@@ -90,7 +90,7 @@ class ServiceManager @Inject constructor(
9090

9191
fun stopBackgroundService() {
9292
applicationScope.launch(ioDispatcher) {
93-
if (!backgroundService.isCompleted || !backgroundService.isActive) return@launch
93+
if (!backgroundService.isCompleted) return@launch
9494
runCatching {
9595
val service = backgroundService.await()
9696
service.stop()
@@ -141,7 +141,7 @@ class ServiceManager @Inject constructor(
141141
applicationScope.launch(ioDispatcher) {
142142
val settings = appDataRepository.settings.get()
143143
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false))
144-
if (!autoTunnelService.isCompleted || !autoTunnelService.isActive) return@launch
144+
if (!autoTunnelService.isCompleted) return@launch
145145
runCatching {
146146
val service = autoTunnelService.await()
147147
service.stop()

0 commit comments

Comments
 (0)