diff options
| author | Albin <albin@mullvad.net> | 2022-07-29 10:57:11 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-07-29 13:31:13 +0200 |
| commit | 73b2be0568ff6a83ab6894e67308dcc6fdc6e53b (patch) | |
| tree | 720cfc5fb7ab70969f01f759a4774923b646ced5 | |
| parent | 73a41a82e94ae3bcc42df2f7141430c83d3af369 (diff) | |
| download | mullvadvpn-73b2be0568ff6a83ab6894e67308dcc6fdc6e53b.tar.xz mullvadvpn-73b2be0568ff6a83ab6894e67308dcc6fdc6e53b.zip | |
Fix scope usage in tile service
Reverts part of the changes in the following commit due to how scopes
are used: 9258a8825a9ffc5b30faad6700d71dde87680554
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt index 8b64face8f..ecbc117f63 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadTileService.kt @@ -6,9 +6,10 @@ import android.os.Build import android.service.quicksettings.Tile import android.service.quicksettings.TileService import android.util.Log +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.Job import kotlinx.coroutines.MainScope +import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.debounce @@ -23,8 +24,7 @@ import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.talpid.tunnel.ActionAfterDisconnect class MullvadTileService : TileService() { - private val scope = MainScope() - private var listenerJob: Job? = null + private var scope: CoroutineScope? = null private lateinit var securedIcon: Icon private lateinit var unsecuredIcon: Icon @@ -65,11 +65,11 @@ class MullvadTileService : TileService() { } override fun onStartListening() { - listenerJob = scope.launch { listenToTunnelState() } + scope = MainScope().apply { launchListenToTunnelState() } } override fun onStopListening() { - listenerJob?.cancel() + scope?.cancel() } private fun toggleTunnel() { @@ -86,8 +86,8 @@ class MullvadTileService : TileService() { } @OptIn(FlowPreview::class) - private suspend fun listenToTunnelState() { - ServiceConnection(this@MullvadTileService, scope) + private fun CoroutineScope.launchListenToTunnelState() = launch { + ServiceConnection(this@MullvadTileService, this) .tunnelState .debounce(300L) .map { (tunnelState, connectionState) -> mapToTileState(tunnelState, connectionState) } |
