mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
Show build identity on launcher
This commit is contained in:
1 parent
87c44c3218
commit
cfec8ab88a
4 files changed
+108
No files matched your search
@@ -4,6 +4,45 @@ plugins {
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
|
||||
|
||||
def gitValue = { List<String> arguments ->
|
||||
try {
|
||||
def output = providers.exec {
|
||||
commandLine(['git'] + arguments)
|
||||
workingDir rootProject.projectDir
|
||||
ignoreExitValue = true
|
||||
}
|
||||
output.result.get().exitValue == 0 ? output.standardOutput.asText.get().trim() : ''
|
||||
} catch (Exception ignored) {
|
||||
''
|
||||
}
|
||||
}
|
||||
|
||||
def buildLabel = providers.environmentVariable('DROIDDECK_BUILD_LABEL').getOrNull()
|
||||
if (buildLabel == null || buildLabel.trim().isEmpty()) {
|
||||
def eventName = providers.environmentVariable('GITHUB_EVENT_NAME').getOrNull()
|
||||
def eventPath = providers.environmentVariable('GITHUB_EVENT_PATH').getOrNull()
|
||||
if (eventName == 'pull_request_target' && eventPath) {
|
||||
try {
|
||||
def eventFile = layout.file(providers.provider { new File(eventPath) })
|
||||
def eventText = providers.fileContents(eventFile).asText.get()
|
||||
def pullRequest = new groovy.json.JsonSlurper().parseText(eventText).pull_request
|
||||
if (pullRequest?.number && pullRequest?.head?.sha) {
|
||||
buildLabel = "pr${pullRequest.number} at ${pullRequest.head.sha.take(7)}"
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Local builds and unusual CI events can omit the pull-request payload.
|
||||
}
|
||||
}
|
||||
if (buildLabel == null || buildLabel.trim().isEmpty()) {
|
||||
def branch = providers.environmentVariable('GITHUB_REF_NAME').getOrNull()
|
||||
?: gitValue(['branch', '--show-current']) ?: 'local'
|
||||
def commit = providers.environmentVariable('GITHUB_SHA').getOrNull()
|
||||
?.take(7) ?: gitValue(['rev-parse', '--short=7', 'HEAD']) ?: 'unknown'
|
||||
buildLabel = "${branch} at ${commit}"
|
||||
}
|
||||
}
|
||||
def escapedBuildLabel = buildLabel.replace('\\', '\\\\').replace('"', '\\"')
|
||||
|
||||
android {
|
||||
namespace 'com.droiddeck.launcher'
|
||||
compileSdk 34
|
||||
@@ -20,6 +59,7 @@ android {
|
||||
targetSdkVersion 28
|
||||
versionCode 7
|
||||
versionName "0.1.6"
|
||||
buildConfigField "String", "BUILD_LABEL", "\"${escapedBuildLabel}\""
|
||||
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a'
|
||||
@@ -87,6 +127,7 @@ android {
|
||||
|
||||
buildFeatures {
|
||||
compose true
|
||||
buildConfig true
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
|
||||
@@ -244,6 +244,7 @@ class MainActivity : ComponentActivity() {
|
||||
packagePercent = pkgPercent,
|
||||
sessionRunning = SessionState.running,
|
||||
backActionsInverted = backActionsInverted,
|
||||
buildLabel = BuildConfig.BUILD_LABEL,
|
||||
),
|
||||
FrontEndActions(
|
||||
onPlay = { startSession(Intent(this, SessionActivity::class.java)) },
|
||||
@@ -308,6 +309,9 @@ class MainActivity : ComponentActivity() {
|
||||
SessionPrefs.setBackActionsInverted(this, inverted)
|
||||
backActionsInverted = inverted
|
||||
},
|
||||
onCheckLatestBuild = {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/The412Banner/DroidDeck/actions/workflows/build.yml")))
|
||||
},
|
||||
),
|
||||
page = page,
|
||||
)
|
||||
|
||||
@@ -59,11 +59,13 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
@@ -98,6 +100,7 @@ import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
@@ -143,6 +146,7 @@ class FrontEndState(
|
||||
val packagePercent: Int = -1,
|
||||
val sessionRunning: Boolean = false,
|
||||
val backActionsInverted: Boolean = false,
|
||||
val buildLabel: String = "local",
|
||||
)
|
||||
|
||||
class FrontEndActions(
|
||||
@@ -172,6 +176,7 @@ class FrontEndActions(
|
||||
val onHomeApp: () -> Unit = {},
|
||||
val onAndroidApp: (com.droiddeck.launcher.HomeApp.LaunchableApp) -> Unit = {},
|
||||
val onBackActionsInverted: (Boolean) -> Unit = {},
|
||||
val onCheckLatestBuild: () -> Unit = {},
|
||||
)
|
||||
|
||||
|
||||
@@ -466,6 +471,45 @@ private fun Pane(s: FrontEndState, selected: String, a: FrontEndActions, page: (
|
||||
},
|
||||
label = "pane",
|
||||
) { key -> if (page != null && key == s.pageKey) page() else Content(s, key, a, Modifier.fillMaxSize(), onSelect) }
|
||||
if (page == null && s.pageKey == null && selected == "steam") {
|
||||
BuildStatus(
|
||||
label = s.buildLabel,
|
||||
onCheckLatest = a.onCheckLatestBuild,
|
||||
modifier = Modifier.align(Alignment.TopEnd).padding(12.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BuildStatus(label: String, onCheckLatest: () -> Unit, modifier: Modifier = Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val interaction = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(interaction)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(9.dp),
|
||||
modifier = modifier
|
||||
.widthIn(max = 360.dp)
|
||||
.clip(Shape12)
|
||||
.background(colors.surface.copy(alpha = 0.96f))
|
||||
.border(1.5.dp, if (hot) pal.signal else pal.line2, Shape12)
|
||||
.hoverable(interaction)
|
||||
.clickable(
|
||||
interactionSource = interaction,
|
||||
indication = LocalIndication.current,
|
||||
role = Role.Button,
|
||||
onClick = onCheckLatest,
|
||||
)
|
||||
.padding(horizontal = 11.dp, vertical = 7.dp),
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text("BUILD", fontSize = 9.sp, letterSpacing = 1.sp, color = colors.onSurfaceVariant)
|
||||
Text(label, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
Icon(Icons.Filled.Refresh, contentDescription = null, tint = if (hot) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(15.dp))
|
||||
Text("Check latest", fontSize = 11.sp, fontWeight = FontWeight.SemiBold, color = if (hot) pal.signal else colors.onBackground, maxLines = 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user