From d84d9df57d5eb030b5355bf1a9f453c29550b424 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Wed, 11 Dec 2024 00:03:39 -0500 Subject: [PATCH] fix: notification channel creation bug Fixes a crash that is caused by a typo when creating a new notification channel. Also makes VPN kill switch visible on TVs --- .../notification/WireGuardNotification.kt | 4 +- .../ui/screens/settings/SettingsScreen.kt | 83 ++++++++++--------- .../settings/killswitch/KillSwitchScreen.kt | 35 ++++---- 3 files changed, 63 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/notification/WireGuardNotification.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/notification/WireGuardNotification.kt index 2b431c2..6d2e88b 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/notification/WireGuardNotification.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/notification/WireGuardNotification.kt @@ -86,13 +86,13 @@ constructor( fun NotificationChannels.asBuilder(): NotificationCompat.Builder { return when (this) { - NotificationChannels.VPN -> { + NotificationChannels.AUTO_TUNNEL -> { NotificationCompat.Builder( context, context.getString(R.string.auto_tunnel_channel_id), ) } - NotificationChannels.AUTO_TUNNEL -> { + NotificationChannels.VPN -> { NotificationCompat.Builder( context, context.getString(R.string.vpn_channel_id), 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 f58f5b6..91f95cb 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 @@ -151,50 +151,51 @@ fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel(), appViewModel: ), ) if (!isRunningOnTv) { - addAll( - listOf( - SelectionItem( - Icons.Outlined.VpnLock, - { - ScaledSwitch( - enabled = !( - ( - uiState.settings.isTunnelOnWifiEnabled || - uiState.settings.isTunnelOnEthernetEnabled || - uiState.settings.isTunnelOnMobileDataEnabled - ) && - uiState.settings.isAutoTunnelEnabled - ), - onClick = { appViewModel.onToggleAlwaysOnVPN() }, - checked = uiState.settings.isAlwaysOnVpnEnabled, - ) - }, - title = { - Text( - stringResource(R.string.always_on_vpn_support), - style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), - ) - }, - onClick = { appViewModel.onToggleAlwaysOnVPN() }, - ), - SelectionItem( - Icons.Outlined.VpnKeyOff, - title = { - Text( - stringResource(R.string.kill_switch_options), - style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), - ) - }, - onClick = { - navController.navigate(Route.KillSwitch) - }, - trailing = { - ForwardButton { navController.navigate(Route.KillSwitch) } - }, - ), + add( + SelectionItem( + Icons.Outlined.VpnLock, + { + ScaledSwitch( + enabled = !( + ( + uiState.settings.isTunnelOnWifiEnabled || + uiState.settings.isTunnelOnEthernetEnabled || + uiState.settings.isTunnelOnMobileDataEnabled + ) && + uiState.settings.isAutoTunnelEnabled + ), + onClick = { appViewModel.onToggleAlwaysOnVPN() }, + checked = uiState.settings.isAlwaysOnVpnEnabled, + ) + }, + title = { + Text( + stringResource(R.string.always_on_vpn_support), + style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), + ) + }, + onClick = { appViewModel.onToggleAlwaysOnVPN() }, ), ) } + add( + SelectionItem( + Icons.Outlined.VpnKeyOff, + title = { + Text( + stringResource(R.string.kill_switch_options), + style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), + ) + }, + onClick = { + navController.navigate(Route.KillSwitch) + }, + trailing = { + ForwardButton { navController.navigate(Route.KillSwitch) } + }, + ), + ) + add( SelectionItem( Icons.Outlined.Restore, diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/killswitch/KillSwitchScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/killswitch/KillSwitchScreen.kt index a5529db..a2dddf8 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/killswitch/KillSwitchScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/killswitch/KillSwitchScreen.kt @@ -26,6 +26,7 @@ import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelec import com.zaneschepke.wireguardautotunnel.ui.common.navigation.TopNavBar import com.zaneschepke.wireguardautotunnel.ui.common.permission.vpn.withVpnPermission import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ForwardButton +import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv import com.zaneschepke.wireguardautotunnel.util.extensions.launchVpnSettings import com.zaneschepke.wireguardautotunnel.util.extensions.scaledHeight import com.zaneschepke.wireguardautotunnel.util.extensions.scaledWidth @@ -66,23 +67,25 @@ fun KillSwitchScreen(uiState: AppUiState, appViewModel: AppViewModel) { .padding(top = 24.dp.scaledHeight()) .padding(horizontal = 24.dp.scaledWidth()), ) { - SurfaceSelectionGroupButton( - listOf( - SelectionItem( - Icons.Outlined.AdminPanelSettings, - title = { - Text( - stringResource(R.string.native_kill_switch), - style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), - ) - }, - onClick = { context.launchVpnSettings() }, - trailing = { - ForwardButton { context.launchVpnSettings() } - }, + if (!context.isRunningOnTv()) { + SurfaceSelectionGroupButton( + listOf( + SelectionItem( + Icons.Outlined.AdminPanelSettings, + title = { + Text( + stringResource(R.string.native_kill_switch), + style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurface), + ) + }, + onClick = { context.launchVpnSettings() }, + trailing = { + ForwardButton { context.launchVpnSettings() } + }, + ), ), - ), - ) + ) + } SurfaceSelectionGroupButton( buildList { add(