@@ -54,12 +54,12 @@ class ServiceManager @Inject constructor(
54
54
applicationScope.launch(ioDispatcher) {
55
55
val settings = appDataRepository.settings.get()
56
56
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = true ))
57
- if (autoTunnelService.isCompleted && autoTunnelService.isActive ) {
57
+ if (autoTunnelService.isCompleted) {
58
58
_autoTunnelActive .update { true }
59
59
return @launch
60
60
}
61
61
runCatching {
62
- autoTunnelService = CompletableDeferred () // Reset
62
+ autoTunnelService = CompletableDeferred ()
63
63
startService(AutoTunnelService ::class .java, background)
64
64
val service = withTimeoutOrNull(SERVICE_START_TIMEOUT ) { autoTunnelService.await() }
65
65
? : throw IllegalStateException (" AutoTunnelService start timed out" )
@@ -75,7 +75,7 @@ class ServiceManager @Inject constructor(
75
75
76
76
fun startBackgroundService (tunnelConf : TunnelConf ) {
77
77
applicationScope.launch(ioDispatcher) {
78
- if (backgroundService.isCompleted && backgroundService.isActive ) return @launch
78
+ if (backgroundService.isCompleted) return @launch
79
79
runCatching {
80
80
backgroundService = CompletableDeferred ()
81
81
startService(TunnelForegroundService ::class .java, true )
@@ -90,7 +90,7 @@ class ServiceManager @Inject constructor(
90
90
91
91
fun stopBackgroundService () {
92
92
applicationScope.launch(ioDispatcher) {
93
- if (! backgroundService.isCompleted || ! backgroundService.isActive ) return @launch
93
+ if (! backgroundService.isCompleted) return @launch
94
94
runCatching {
95
95
val service = backgroundService.await()
96
96
service.stop()
@@ -141,7 +141,7 @@ class ServiceManager @Inject constructor(
141
141
applicationScope.launch(ioDispatcher) {
142
142
val settings = appDataRepository.settings.get()
143
143
appDataRepository.settings.save(settings.copy(isAutoTunnelEnabled = false ))
144
- if (! autoTunnelService.isCompleted || ! autoTunnelService.isActive ) return @launch
144
+ if (! autoTunnelService.isCompleted) return @launch
145
145
runCatching {
146
146
val service = autoTunnelService.await()
147
147
service.stop()
0 commit comments