From a89c545507125fbfbc741a5703fe413ac0a2d9e9 Mon Sep 17 00:00:00 2001 From: bg443 Date: Wed, 9 Jul 2025 22:22:40 +0100 Subject: [PATCH] Add error handling to commit -> tag lookup --- .idea/deviceManager.xml | 13 +++++++++++++ app/build.gradle.kts | 18 ++++++++++++------ .../ui/screens/settings/SettingsScreen.kt | 15 +++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .idea/deviceManager.xml diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml new file mode 100644 index 0000000..91f9558 --- /dev/null +++ b/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b21dd7d..ed4e50b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -172,10 +172,16 @@ fun getShortNetbirdCommit(): String { } fun getNetbirdVersionFromCommit(): String { -// val stdout = ByteArrayOutputStream() -// exec { -// commandLine("git", "-C", "../netbird", "describe", "--tags", "--abbrev=0", getNetbirdCommit()) -// standardOutput = stdout -// } - return "\"v0.49.0\"" + val stdout = ByteArrayOutputStream() + val commit = getNetbirdCommit() + return try { + exec { + commandLine("git", "-C", "../netbird", "describe", "--tags", "--abbrev=0", getNetbirdCommit()) + standardOutput = stdout + } + return "\"${stdout.toString().trim()}${if (commit.startsWith('+')) "+" else ""}\"" + } catch (e: Exception) { + println("Failed to get NetBird submodule tag from commit ${commit}: $e") + "null" + } } diff --git a/app/src/main/java/dev/bg/jetbird/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/dev/bg/jetbird/ui/screens/settings/SettingsScreen.kt index 9a0d2b1..4bf336d 100644 --- a/app/src/main/java/dev/bg/jetbird/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/java/dev/bg/jetbird/ui/screens/settings/SettingsScreen.kt @@ -3,7 +3,6 @@ package dev.bg.jetbird.ui.screens.settings import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageManager -import android.net.Uri import android.provider.Settings import androidx.appcompat.app.AppCompatDelegate import androidx.compose.animation.AnimatedVisibility @@ -52,6 +51,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.graphics.drawable.toBitmap +import androidx.core.net.toUri import androidx.core.os.LocaleListCompat import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -78,6 +78,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import timber.log.Timber import java.io.File +import java.io.FileNotFoundException import java.io.IOException @Composable @@ -424,7 +425,7 @@ fun SettingsScreen( onClick = { ctx.startActivity( Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply { - data = Uri.parse("package:${ctx.packageName}") + data = "package:${ctx.packageName}".toUri() } ) } @@ -438,7 +439,7 @@ fun SettingsScreen( ) SettingsTile( title = stringResource(R.string.about_netbird_version), - description = "${BuildConfig.NETBIRD_COMMIT} (${BuildConfig.NETBIRD_VERSION})" + description = "${BuildConfig.NETBIRD_COMMIT} ${if (BuildConfig.NETBIRD_VERSION != null) "(${BuildConfig.NETBIRD_VERSION})" else ""}" ) SettingsTile( title = stringResource(R.string.credits), @@ -500,7 +501,13 @@ private fun ConfigViewDialog( val ctx = LocalContext.current val clipboardManager = LocalClipboardManager.current - val config = remember(state) { File(ctx.getConfigPath()).readText() } + val config = remember(state) { + try { + File(ctx.getConfigPath()).readText() + } catch (e: FileNotFoundException) { + "NetBird config not found" + } + } if (open) { AlertDialog(