fix(ui,update): remove refresh button, rely on pull-to-refresh, sync update check in background worker (v1.1.9)
Build & Release Android APK / Build & Publish Release APK (push) Successful in 32m10s

This commit is contained in:
Vaishno Singh
2026-11-19 10:50:47 +05:30
parent d8eaceb314
commit bba5caf79d
4 changed files with 166 additions and 184 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ android {
applicationId = "com.expapp.trigger"
minSdk = 24
targetSdk = 34
versionCode = 12
versionName = "1.1.8"
versionCode = 13
versionName = "1.1.9"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
@@ -38,7 +38,6 @@ import androidx.compose.material.icons.filled.DeleteOutline
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.PowerOff
import androidx.compose.material.icons.filled.PowerSettingsNew
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.RestartAlt
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material.icons.filled.Terminal
@@ -262,15 +261,8 @@ fun DevicePage(
)
}
// Spin animation for refresh icon
val infiniteTransition = rememberInfiniteTransition(label = "refresh_spin")
val spinAngle by infiniteTransition.animateFloat(
initialValue = 0f, targetValue = 360f,
animationSpec = infiniteRepeatable(tween(900, easing = LinearEasing)),
label = "spin"
)
// Pulse for online dot
val infiniteTransition = rememberInfiniteTransition(label = "pulse_transition")
val pulseScale by infiniteTransition.animateFloat(
initialValue = 0.8f, targetValue = 1.5f,
animationSpec = infiniteRepeatable(
@@ -394,44 +386,7 @@ fun DevicePage(
)
}
// Compact, non-overlapping actions: Single Refresh + Overflow Menu
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
// Refresh button (syncs status & R2 endpoints)
IconButton(
onClick = {
if (!isCheckingStatus) {
onRefreshStatus()
onSyncConfig()
}
},
modifier = Modifier
.size(34.dp)
.clip(RoundedCornerShape(9.dp))
.background(
if (isCheckingStatus) GreenVibrant.copy(alpha = 0.15f)
else BorderSubtle.copy(alpha = 0.25f)
)
.border(
1.dp,
if (isCheckingStatus) GreenVibrant.copy(alpha = 0.4f)
else BorderSubtle,
RoundedCornerShape(9.dp)
)
) {
Icon(
imageVector = Icons.Default.Refresh,
contentDescription = "Refresh server",
tint = if (isCheckingStatus) GreenVibrant else TextSecondary,
modifier = Modifier
.size(17.dp)
.rotate(if (isCheckingStatus) spinAngle else 0f)
)
}
// More Options Overflow (Edit / Delete)
// Device options menu (Edit / Delete)
Box {
IconButton(
onClick = { showMenu = true },
@@ -489,7 +444,6 @@ fun DevicePage(
}
}
}
}
Spacer(modifier = Modifier.height(14.dp))
@@ -44,15 +44,11 @@ class UpdateManager(
}
/**
* Checks GitHub Releases API for the latest published release.
* Synchronously checks GitHub Releases API for the latest published release.
* Suitable for use inside background workers (e.g. WorkManager CoroutineWorker).
*/
fun checkForUpdate(
currentVersionName: String,
callback: (UpdateCheckResult) -> Unit
) {
// Query releases list so we always inspect the highest semantic version
fun checkForUpdateSync(currentVersionName: String): UpdateCheckResult {
val url = "https://api.github.com/repos/$githubRepo/releases"
val request = Request.Builder()
.url(url)
.addHeader("Accept", "application/vnd.github.v3+json")
@@ -60,33 +56,29 @@ class UpdateManager(
.get()
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
runOnMain {
callback(UpdateCheckResult.Error("Network error: ${e.localizedMessage}"))
}
}
override fun onResponse(call: Call, response: Response) {
return try {
val response = okHttpClient.newCall(request).execute()
response.use { res ->
if (res.code == 404) {
runOnMain { callback(UpdateCheckResult.UpToDate) }
return
return UpdateCheckResult.UpToDate
}
if (!res.isSuccessful) {
runOnMain {
callback(UpdateCheckResult.Error("HTTP ${res.code}: Unable to check updates"))
return UpdateCheckResult.Error("HTTP ${res.code}: Unable to check updates")
}
val body = res.body?.string().orEmpty()
parseReleases(body, currentVersionName)
}
} catch (e: Exception) {
UpdateCheckResult.Error("Network error: ${e.localizedMessage}")
}
return
}
val body = res.body?.string().orEmpty()
try {
private fun parseReleases(body: String, currentVersionName: String): UpdateCheckResult {
return try {
val jsonElement = JsonParser.parseString(body)
val releasesArray = if (jsonElement.isJsonArray) {
jsonElement.asJsonArray
} else {
// In case a single release object was returned
val arr = com.google.gson.JsonArray()
if (jsonElement.isJsonObject) arr.add(jsonElement.asJsonObject)
arr
@@ -143,24 +135,61 @@ class UpdateManager(
}
if (highestRelease == null) {
runOnMain { callback(UpdateCheckResult.UpToDate) }
return
return UpdateCheckResult.UpToDate
}
val cleanLocalVersion = currentVersionName.removePrefix("v").removePrefix("V").trim()
if (isNewerVersion(highestRelease.versionName, cleanLocalVersion)) {
runOnMain {
callback(UpdateCheckResult.UpdateAvailable(highestRelease))
}
UpdateCheckResult.UpdateAvailable(highestRelease)
} else {
runOnMain { callback(UpdateCheckResult.UpToDate) }
UpdateCheckResult.UpToDate
}
} catch (e: Exception) {
UpdateCheckResult.Error("Failed to parse update info: ${e.message}")
}
}
/**
* Checks GitHub Releases API for the latest published release.
*/
fun checkForUpdate(
currentVersionName: String,
callback: (UpdateCheckResult) -> Unit
) {
// Query releases list so we always inspect the highest semantic version
val url = "https://api.github.com/repos/$githubRepo/releases"
val request = Request.Builder()
.url(url)
.addHeader("Accept", "application/vnd.github.v3+json")
.addHeader("User-Agent", "ServerControlApp")
.get()
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
runOnMain {
callback(UpdateCheckResult.Error("Failed to parse update info: ${e.message}"))
callback(UpdateCheckResult.Error("Network error: ${e.localizedMessage}"))
}
}
override fun onResponse(call: Call, response: Response) {
response.use { res ->
if (res.code == 404) {
runOnMain { callback(UpdateCheckResult.UpToDate) }
return
}
if (!res.isSuccessful) {
runOnMain {
callback(UpdateCheckResult.Error("HTTP ${res.code}: Unable to check updates"))
}
return
}
val body = res.body?.string().orEmpty()
val result = parseReleases(body, currentVersionName)
runOnMain { callback(result) }
}
}
})
@@ -120,11 +120,11 @@ class ServerMonitorWorker(
}
}
// Check for app updates in the background and notify if a new update is found
// Check for app updates in the background synchronously and notify if a new update is found
try {
val updateManager = com.expapp.trigger.update.UpdateManager(appContext)
val currentVersion = com.expapp.trigger.BuildConfig.VERSION_NAME
updateManager.checkForUpdate(currentVersion) { result ->
val result = updateManager.checkForUpdateSync(currentVersion)
if (result is com.expapp.trigger.update.UpdateCheckResult.UpdateAvailable) {
val newVer = result.info.versionName
val lastNotified = appSettings.lastNotifiedUpdateVersion
@@ -133,7 +133,6 @@ class ServerMonitorWorker(
NotificationHelper.sendUpdateAvailableNotification(appContext, newVer)
}
}
}
} catch (_: Exception) {
// Ignore background check failure
}