fix: auto tunnel tile bug

Fixes bug where auto tunnel tile was the opposite state

Closes #241
This commit is contained in:
Zane Schepke 2024-07-27 07:21:27 -04:00
parent b8c36ac192
commit 737524831b
4 changed files with 32 additions and 15 deletions

View File

@ -3,10 +3,15 @@ package com.zaneschepke.wireguardautotunnel.service.tile
import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ServiceLifecycleDispatcher
import androidx.lifecycle.lifecycleScope
import com.zaneschepke.wireguardautotunnel.R
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
import com.zaneschepke.wireguardautotunnel.module.ServiceScope
import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
@ -16,7 +21,7 @@ import timber.log.Timber
import javax.inject.Inject
@AndroidEntryPoint
class AutoTunnelControlTile : TileService() {
class AutoTunnelControlTile : TileService(), LifecycleOwner {
@Inject
lateinit var appDataRepository: AppDataRepository
@ -24,15 +29,13 @@ class AutoTunnelControlTile : TileService() {
@Inject
lateinit var serviceManager: ServiceManager
@Inject
@ApplicationScope
lateinit var applicationScope: CoroutineScope
private val dispatcher = ServiceLifecycleDispatcher(this)
private var manualStartConfig: TunnelConfig? = null
override fun onStartListening() {
super.onStartListening()
applicationScope.launch {
lifecycleScope.launch {
val settings = appDataRepository.settings.getSettings()
when (settings.isAutoTunnelEnabled) {
true -> {
@ -44,7 +47,6 @@ class AutoTunnelControlTile : TileService() {
setTileDescription(this@AutoTunnelControlTile.getString(R.string.active))
}
}
false -> {
setTileDescription(this@AutoTunnelControlTile.getString(R.string.disabled))
setUnavailable()
@ -61,9 +63,10 @@ class AutoTunnelControlTile : TileService() {
override fun onClick() {
super.onClick()
unlockAndRun {
applicationScope.launch {
lifecycleScope.launch {
try {
appDataRepository.toggleWatcherServicePause()
onStartListening()
} catch (e: Exception) {
Timber.e(e.message)
} finally {
@ -98,4 +101,7 @@ class AutoTunnelControlTile : TileService() {
}
qsTile.updateTile()
}
override val lifecycle: Lifecycle
get() = dispatcher.lifecycle
}

View File

@ -3,6 +3,11 @@ package com.zaneschepke.wireguardautotunnel.service.tile
import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.ServiceLifecycleDispatcher
import androidx.lifecycle.lifecycleScope
import com.zaneschepke.wireguardautotunnel.data.domain.TunnelConfig
import com.zaneschepke.wireguardautotunnel.data.repository.AppDataRepository
import com.zaneschepke.wireguardautotunnel.module.ApplicationScope
@ -17,7 +22,7 @@ import timber.log.Timber
import javax.inject.Inject
@AndroidEntryPoint
class TunnelControlTile : TileService() {
class TunnelControlTile : TileService(), LifecycleOwner {
@Inject
lateinit var appDataRepository: AppDataRepository
@ -28,16 +33,14 @@ class TunnelControlTile : TileService() {
@Inject
lateinit var serviceManager: ServiceManager
@Inject
@ApplicationScope
lateinit var applicationScope: CoroutineScope
private val dispatcher = ServiceLifecycleDispatcher(this)
private var manualStartConfig: TunnelConfig? = null
override fun onStartListening() {
super.onStartListening()
Timber.d("On start listening called")
applicationScope.launch {
lifecycleScope.launch {
when (vpnService.getState()) {
TunnelState.UP -> {
setActive()
@ -67,7 +70,7 @@ class TunnelControlTile : TileService() {
override fun onClick() {
super.onClick()
unlockAndRun {
applicationScope.launch {
lifecycleScope.launch {
try {
if (vpnService.getState() == TunnelState.UP) {
serviceManager.stopVpnServiceForeground(
@ -113,4 +116,7 @@ class TunnelControlTile : TileService() {
}
qsTile.updateTile()
}
override val lifecycle: Lifecycle
get() = dispatcher.lifecycle
}

View File

@ -1,7 +1,7 @@
object Constants {
const val VERSION_NAME = "3.4.7"
const val VERSION_NAME = "3.4.8"
const val JVM_TARGET = "17"
const val VERSION_CODE = 34700
const val VERSION_CODE = 34800
const val TARGET_SDK = 34
const val MIN_SDK = 26
const val APP_ID = "com.zaneschepke.wireguardautotunnel"

View File

@ -0,0 +1,5 @@
What's new:
- Fixes for AndroidTV UI tunnel control
- Fixes portrait lock bug
- Fixes pin lock bypass bug
- Fixes auto tunnel tile bug