Add error handling to commit -> tag lookup

This commit is contained in:
bg443
2025-07-09 22:22:40 +01:00
parent 0f0f1993f4
commit a89c545507
3 changed files with 36 additions and 10 deletions

13
.idea/deviceManager.xml generated Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DeviceTable">
<option name="columnSorters">
<list>
<ColumnSorterState>
<option name="column" value="Name" />
<option name="order" value="ASCENDING" />
</ColumnSorterState>
</list>
</option>
</component>
</project>

View File

@@ -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"
}
}

View File

@@ -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(