diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2a6f719..9f3b9c6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,12 +17,12 @@ android { val versionMajor = 2 val versionMinor = 4 - val versionPatch = 4 + val versionPatch = 5 val versionBuild = 0 defaultConfig { applicationId = "com.zaneschepke.wireguardautotunnel" - minSdk = 28 + minSdk = 26 targetSdk = 34 versionCode = versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild versionName = "${versionMajor}.${versionMinor}.${versionPatch}" @@ -64,8 +64,8 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.10.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") implementation("androidx.activity:activity-compose:1.7.2") implementation(platform("androidx.compose:compose-bom:2023.03.00")) implementation("androidx.compose.ui:ui") @@ -89,7 +89,7 @@ dependencies { implementation("com.jakewharton.timber:timber:5.0.1") // compose navigation - implementation("androidx.navigation:navigation-compose:2.7.1") + implementation("androidx.navigation:navigation-compose:2.7.2") implementation("androidx.hilt:hilt-navigation-compose:1.0.0") // hilt @@ -107,10 +107,10 @@ dependencies { implementation("io.objectbox:objectbox-kotlin:${rExtra.get("objectBoxVersion")}") //lifecycle - implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1") + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2") //icons - implementation("androidx.compose.material:material-icons-extended:1.5.0") + implementation("androidx.compose.material:material-icons-extended:1.5.1") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/shortcut/ShortcutsActivity.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/shortcut/ShortcutsActivity.kt index 91c0940..2ebb866 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/shortcut/ShortcutsActivity.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/shortcut/ShortcutsActivity.kt @@ -3,19 +3,44 @@ package com.zaneschepke.wireguardautotunnel.service.shortcut import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.zaneschepke.wireguardautotunnel.R +import com.zaneschepke.wireguardautotunnel.repository.Repository import com.zaneschepke.wireguardautotunnel.service.foreground.Action import com.zaneschepke.wireguardautotunnel.service.foreground.ServiceManager import com.zaneschepke.wireguardautotunnel.service.foreground.WireGuardTunnelService +import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import javax.inject.Inject @AndroidEntryPoint class ShortcutsActivity : AppCompatActivity() { + + @Inject + lateinit var settingsRepo : Repository + + private val scope = CoroutineScope(Dispatchers.Main); + + private fun attemptWatcherServiceToggle(tunnelConfig : String) { + scope.launch { + val settings = settingsRepo.getAll() + if (!settings.isNullOrEmpty()) { + val setting = settings.first() + if(setting.isAutoTunnelEnabled) { + ServiceManager.toggleWatcherServiceForeground(this@ShortcutsActivity, tunnelConfig) + } + } + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if(intent.getStringExtra(ShortcutsManager.CLASS_NAME_EXTRA_KEY) .equals(WireGuardTunnelService::class.java.name)) { + intent.getStringExtra(getString(R.string.tunnel_extras_key))?.let { - ServiceManager.toggleWatcherService(this, it) + attemptWatcherServiceToggle(it) } when(intent.action){ Action.STOP.name -> ServiceManager.stopVpnService(this) diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigViewModel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigViewModel.kt index ce57f4b..25a0c07 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigViewModel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigViewModel.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.toMutableStateList import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.zaneschepke.wireguardautotunnel.repository.Repository +import com.zaneschepke.wireguardautotunnel.service.shortcut.ShortcutsManager import com.zaneschepke.wireguardautotunnel.service.tunnel.model.Settings import com.zaneschepke.wireguardautotunnel.service.tunnel.model.TunnelConfig import dagger.hilt.android.lifecycle.HiltViewModel @@ -114,12 +115,14 @@ class ConfigViewModel @Inject constructor(private val application : Application, return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { packageManager.getPackagesHoldingPermissions(permissions, PackageManager.PackageInfoFlags.of(0L)) } else { - @Suppress("DEPRECATION") packageManager.getPackagesHoldingPermissions(permissions, 0) } } suspend fun onSaveAllChanges() { + if(_tunnel.value != null) { + ShortcutsManager.removeTunnelShortcuts(application, _tunnel.value!!) + } var wgQuick = _tunnel.value?.wgQuick if(wgQuick != null) { wgQuick = if(_include.value) { @@ -135,6 +138,7 @@ class ConfigViewModel @Inject constructor(private val application : Application, wgQuick = wgQuick )?.let { tunnelRepo.save(it) + ShortcutsManager.createTunnelShortcuts(application, it) val settings = settingsRepo.getAll() if(settings != null) { val setting = settings[0] diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt index 39df472..42f085b 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt @@ -249,7 +249,7 @@ fun MainScreen( .fillMaxSize() .nestedScroll(nestedScrollConnection), ) { - itemsIndexed(tunnels.toList()) { index, tunnel -> + itemsIndexed(tunnels.toList()) { _, tunnel -> val focusRequester = FocusRequester(); RowListItem(leadingIcon = Icons.Rounded.Circle, leadingIconColor = if (tunnelName == tunnel.name) when (handshakeStatus) { diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt index 45e665f..753244e 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt @@ -96,8 +96,6 @@ fun SettingsScreen( val settings by viewModel.settings.collectAsStateWithLifecycle() val trustedSSIDs by viewModel.trustedSSIDs.collectAsStateWithLifecycle() val tunnels by viewModel.tunnels.collectAsStateWithLifecycle(mutableListOf()) - val backgroundLocationState = - rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION) val fineLocationState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION) var currentText by remember { mutableStateOf("") } val scrollState = rememberScrollState() @@ -135,41 +133,44 @@ fun SettingsScreen( context.startActivity(intentSettings) } } - - if(!backgroundLocationState.status.isGranted && Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - Column(horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Top, - modifier = Modifier - .fillMaxSize() - .verticalScroll(scrollState) - .padding(padding)) { - Icon(Icons.Rounded.LocationOff, contentDescription = stringResource(id = R.string.map), modifier = Modifier - .padding(30.dp) - .size(128.dp)) - Text(stringResource(R.string.prominent_background_location_title), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 20.sp) - Text(stringResource(R.string.prominent_background_location_message), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp) - Row( - modifier = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier - .fillMaxWidth() - .padding(10.dp) else Modifier - .fillMaxWidth() - .padding(30.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceEvenly - ) { - Button(onClick = { - navController.navigate(Routes.Main.name) - }) { - Text(stringResource(id = R.string.no_thanks)) - } - Button(modifier = Modifier.focusRequester(focusRequester), onClick = { - openSettings() - }) { - Text(stringResource(id = R.string.turn_on)) + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val backgroundLocationState = + rememberPermissionState(Manifest.permission.ACCESS_BACKGROUND_LOCATION) + if(!backgroundLocationState.status.isGranted) { + Column(horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Top, + modifier = Modifier + .fillMaxSize() + .verticalScroll(scrollState) + .padding(padding)) { + Icon(Icons.Rounded.LocationOff, contentDescription = stringResource(id = R.string.map), modifier = Modifier + .padding(30.dp) + .size(128.dp)) + Text(stringResource(R.string.prominent_background_location_title), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 20.sp) + Text(stringResource(R.string.prominent_background_location_message), textAlign = TextAlign.Center, modifier = Modifier.padding(30.dp), fontSize = 15.sp) + Row( + modifier = if(WireGuardAutoTunnel.isRunningOnAndroidTv(context)) Modifier + .fillMaxWidth() + .padding(10.dp) else Modifier + .fillMaxWidth() + .padding(30.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceEvenly + ) { + Button(onClick = { + navController.navigate(Routes.Main.name) + }) { + Text(stringResource(id = R.string.no_thanks)) + } + Button(modifier = Modifier.focusRequester(focusRequester), onClick = { + openSettings() + }) { + Text(stringResource(id = R.string.turn_on)) + } } } + return } - return } if(!fineLocationState.status.isGranted) { diff --git a/build.gradle.kts b/build.gradle.kts index f2df859..95714b7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,20 +1,20 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - val objectBoxVersion by extra("3.5.1") - val hiltVersion by extra("2.47") + val objectBoxVersion by extra("3.7.0") + val hiltVersion by extra("2.48") val accompanistVersion by extra("0.31.2-alpha") dependencies { classpath("io.objectbox:objectbox-gradle-plugin:$objectBoxVersion") classpath("com.google.gms:google-services:4.3.15") - classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.7") + classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9") } } plugins { id("com.android.application") version "8.2.0-beta03" apply false id("org.jetbrains.kotlin.android") version "1.8.22" apply false - id("com.google.dagger.hilt.android") version "2.44" apply false + id("com.google.dagger.hilt.android") version "2.48" apply false kotlin("plugin.serialization") version "1.8.22" apply false }