diff options
| author | 2024-01-13 20:23:12 -0500 | |
|---|---|---|
| committer | 2024-01-13 20:23:12 -0500 | |
| commit | 817c7c445dcad03756e484810445d1d3ebc2bde2 (patch) | |
| tree | f4f2c477231164d459237026598650a72d31dd0f /src | |
| parent | Merge pull request #12666 from t895/ktlint-yuzu-verify (diff) | |
| parent | android: Show version name instead of git hash in the about fragment (diff) | |
| download | yuzu-817c7c445dcad03756e484810445d1d3ebc2bde2.tar.gz yuzu-817c7c445dcad03756e484810445d1d3ebc2bde2.tar.xz yuzu-817c7c445dcad03756e484810445d1d3ebc2bde2.zip | |
Merge pull request #12667 from t895/version-info
android: Show version name instead of build hash in about fragment
Diffstat (limited to 'src')
4 files changed, 24 insertions, 62 deletions
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index d62254dd3..06e59d1ac 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts | |||
| @@ -235,71 +235,33 @@ dependencies { | |||
| 235 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") | 235 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | fun getGitVersion(): String { | 238 | fun runGitCommand(command: List<String>): String { |
| 239 | var versionName = "0.0" | 239 | return try { |
| 240 | 240 | ProcessBuilder(command) | |
| 241 | try { | ||
| 242 | versionName = ProcessBuilder("git", "describe", "--always", "--long") | ||
| 243 | .directory(project.rootDir) | 241 | .directory(project.rootDir) |
| 244 | .redirectOutput(ProcessBuilder.Redirect.PIPE) | 242 | .redirectOutput(ProcessBuilder.Redirect.PIPE) |
| 245 | .redirectError(ProcessBuilder.Redirect.PIPE) | 243 | .redirectError(ProcessBuilder.Redirect.PIPE) |
| 246 | .start().inputStream.bufferedReader().use { it.readText() } | 244 | .start().inputStream.bufferedReader().use { it.readText() } |
| 247 | .trim() | 245 | .trim() |
| 248 | .replace(Regex("(-0)?-[^-]+$"), "") | ||
| 249 | } catch (e: Exception) { | 246 | } catch (e: Exception) { |
| 250 | logger.error("Cannot find git, defaulting to dummy version number") | 247 | logger.error("Cannot find git") |
| 251 | } | 248 | "" |
| 252 | |||
| 253 | if (System.getenv("GITHUB_ACTIONS") != null) { | ||
| 254 | val gitTag = System.getenv("GIT_TAG_NAME") | ||
| 255 | versionName = gitTag ?: versionName | ||
| 256 | } | 249 | } |
| 257 | |||
| 258 | return versionName | ||
| 259 | } | 250 | } |
| 260 | 251 | ||
| 261 | fun getGitHash(): String { | 252 | fun getGitVersion(): String { |
| 262 | try { | 253 | val versionName = if (System.getenv("GITHUB_ACTIONS") != null) { |
| 263 | val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD") | 254 | val gitTag = System.getenv("GIT_TAG_NAME") ?: "" |
| 264 | processBuilder.directory(project.rootDir) | 255 | gitTag |
| 265 | val process = processBuilder.start() | 256 | } else { |
| 266 | val inputStream = process.inputStream | 257 | runGitCommand(listOf("git", "describe", "--always", "--long")) |
| 267 | val errorStream = process.errorStream | 258 | .replace(Regex("(-0)?-[^-]+$"), "") |
| 268 | process.waitFor() | ||
| 269 | |||
| 270 | return if (process.exitValue() == 0) { | ||
| 271 | inputStream.bufferedReader() | ||
| 272 | .use { it.readText().trim() } // return the value of gitHash | ||
| 273 | } else { | ||
| 274 | val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } | ||
| 275 | logger.error("Error running git command: $errorMessage") | ||
| 276 | "dummy-hash" // return a dummy hash value in case of an error | ||
| 277 | } | ||
| 278 | } catch (e: Exception) { | ||
| 279 | logger.error("$e: Cannot find git, defaulting to dummy build hash") | ||
| 280 | return "dummy-hash" // return a dummy hash value in case of an error | ||
| 281 | } | 259 | } |
| 260 | return versionName.ifEmpty { "0.0" } | ||
| 282 | } | 261 | } |
| 283 | 262 | ||
| 284 | fun getBranch(): String { | 263 | fun getGitHash(): String = |
| 285 | try { | 264 | runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" } |
| 286 | val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD") | 265 | |
| 287 | processBuilder.directory(project.rootDir) | 266 | fun getBranch(): String = |
| 288 | val process = processBuilder.start() | 267 | runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" } |
| 289 | val inputStream = process.inputStream | ||
| 290 | val errorStream = process.errorStream | ||
| 291 | process.waitFor() | ||
| 292 | |||
| 293 | return if (process.exitValue() == 0) { | ||
| 294 | inputStream.bufferedReader() | ||
| 295 | .use { it.readText().trim() } // return the value of gitHash | ||
| 296 | } else { | ||
| 297 | val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } | ||
| 298 | logger.error("Error running git command: $errorMessage") | ||
| 299 | "dummy-hash" // return a dummy hash value in case of an error | ||
| 300 | } | ||
| 301 | } catch (e: Exception) { | ||
| 302 | logger.error("$e: Cannot find git, defaulting to dummy build hash") | ||
| 303 | return "dummy-hash" // return a dummy hash value in case of an error | ||
| 304 | } | ||
| 305 | } | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt index a1620fbb7..5b5f800c1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt | |||
| @@ -76,8 +76,8 @@ class AboutFragment : Fragment() { | |||
| 76 | binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment) | 76 | binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment) |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | binding.textBuildHash.text = BuildConfig.GIT_HASH | 79 | binding.textVersionName.text = BuildConfig.VERSION_NAME |
| 80 | binding.buttonBuildHash.setOnClickListener { | 80 | binding.textVersionName.setOnClickListener { |
| 81 | val clipBoard = | 81 | val clipBoard = |
| 82 | requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager | 82 | requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager |
| 83 | val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH) | 83 | val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH) |
diff --git a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml index a26ffbc73..655e49219 100644 --- a/src/android/app/src/main/res/layout-w600dp/fragment_about.xml +++ b/src/android/app/src/main/res/layout-w600dp/fragment_about.xml | |||
| @@ -147,7 +147,7 @@ | |||
| 147 | android:layout_marginHorizontal="20dp" /> | 147 | android:layout_marginHorizontal="20dp" /> |
| 148 | 148 | ||
| 149 | <LinearLayout | 149 | <LinearLayout |
| 150 | android:id="@+id/button_build_hash" | 150 | android:id="@+id/button_version_name" |
| 151 | android:layout_width="match_parent" | 151 | android:layout_width="match_parent" |
| 152 | android:layout_height="wrap_content" | 152 | android:layout_height="wrap_content" |
| 153 | android:background="?attr/selectableItemBackground" | 153 | android:background="?attr/selectableItemBackground" |
| @@ -164,7 +164,7 @@ | |||
| 164 | android:textAlignment="viewStart" /> | 164 | android:textAlignment="viewStart" /> |
| 165 | 165 | ||
| 166 | <com.google.android.material.textview.MaterialTextView | 166 | <com.google.android.material.textview.MaterialTextView |
| 167 | android:id="@+id/text_build_hash" | 167 | android:id="@+id/text_version_name" |
| 168 | style="@style/TextAppearance.Material3.BodyMedium" | 168 | style="@style/TextAppearance.Material3.BodyMedium" |
| 169 | android:layout_width="match_parent" | 169 | android:layout_width="match_parent" |
| 170 | android:layout_height="wrap_content" | 170 | android:layout_height="wrap_content" |
diff --git a/src/android/app/src/main/res/layout/fragment_about.xml b/src/android/app/src/main/res/layout/fragment_about.xml index a24f5230e..38090fa50 100644 --- a/src/android/app/src/main/res/layout/fragment_about.xml +++ b/src/android/app/src/main/res/layout/fragment_about.xml | |||
| @@ -148,7 +148,7 @@ | |||
| 148 | android:layout_marginHorizontal="20dp" /> | 148 | android:layout_marginHorizontal="20dp" /> |
| 149 | 149 | ||
| 150 | <LinearLayout | 150 | <LinearLayout |
| 151 | android:id="@+id/button_build_hash" | 151 | android:id="@+id/button_version_name" |
| 152 | android:layout_width="match_parent" | 152 | android:layout_width="match_parent" |
| 153 | android:layout_height="wrap_content" | 153 | android:layout_height="wrap_content" |
| 154 | android:paddingVertical="16dp" | 154 | android:paddingVertical="16dp" |
| @@ -165,7 +165,7 @@ | |||
| 165 | android:text="@string/build" /> | 165 | android:text="@string/build" /> |
| 166 | 166 | ||
| 167 | <com.google.android.material.textview.MaterialTextView | 167 | <com.google.android.material.textview.MaterialTextView |
| 168 | android:id="@+id/text_build_hash" | 168 | android:id="@+id/text_version_name" |
| 169 | style="@style/TextAppearance.Material3.BodyMedium" | 169 | style="@style/TextAppearance.Material3.BodyMedium" |
| 170 | android:layout_width="match_parent" | 170 | android:layout_width="match_parent" |
| 171 | android:layout_height="wrap_content" | 171 | android:layout_height="wrap_content" |