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
Build & Release Android APK / Build & Publish Release APK (push) Successful in 32m10s
This commit is contained in:
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "com.expapp.trigger"
|
applicationId = "com.expapp.trigger"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 12
|
versionCode = 13
|
||||||
versionName = "1.1.8"
|
versionName = "1.1.9"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
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.Edit
|
||||||
import androidx.compose.material.icons.filled.PowerOff
|
import androidx.compose.material.icons.filled.PowerOff
|
||||||
import androidx.compose.material.icons.filled.PowerSettingsNew
|
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.RestartAlt
|
||||||
import androidx.compose.material.icons.filled.Schedule
|
import androidx.compose.material.icons.filled.Schedule
|
||||||
import androidx.compose.material.icons.filled.Terminal
|
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
|
// Pulse for online dot
|
||||||
|
val infiniteTransition = rememberInfiniteTransition(label = "pulse_transition")
|
||||||
val pulseScale by infiniteTransition.animateFloat(
|
val pulseScale by infiniteTransition.animateFloat(
|
||||||
initialValue = 0.8f, targetValue = 1.5f,
|
initialValue = 0.8f, targetValue = 1.5f,
|
||||||
animationSpec = infiniteRepeatable(
|
animationSpec = infiniteRepeatable(
|
||||||
@@ -394,99 +386,61 @@ fun DevicePage(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compact, non-overlapping actions: Single Refresh + Overflow Menu
|
// Device options menu (Edit / Delete)
|
||||||
Row(
|
Box {
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
|
||||||
) {
|
|
||||||
// Refresh button (syncs status & R2 endpoints)
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = { showMenu = true },
|
||||||
if (!isCheckingStatus) {
|
|
||||||
onRefreshStatus()
|
|
||||||
onSyncConfig()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(34.dp)
|
.size(34.dp)
|
||||||
.clip(RoundedCornerShape(9.dp))
|
.clip(RoundedCornerShape(9.dp))
|
||||||
.background(
|
.background(BorderSubtle.copy(alpha = 0.25f))
|
||||||
if (isCheckingStatus) GreenVibrant.copy(alpha = 0.15f)
|
.border(1.dp, BorderSubtle, RoundedCornerShape(9.dp))
|
||||||
else BorderSubtle.copy(alpha = 0.25f)
|
|
||||||
)
|
|
||||||
.border(
|
|
||||||
1.dp,
|
|
||||||
if (isCheckingStatus) GreenVibrant.copy(alpha = 0.4f)
|
|
||||||
else BorderSubtle,
|
|
||||||
RoundedCornerShape(9.dp)
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Refresh,
|
imageVector = Icons.Default.MoreVert,
|
||||||
contentDescription = "Refresh server",
|
contentDescription = "Device options",
|
||||||
tint = if (isCheckingStatus) GreenVibrant else TextSecondary,
|
tint = TextSecondary,
|
||||||
modifier = Modifier
|
modifier = Modifier.size(18.dp)
|
||||||
.size(17.dp)
|
|
||||||
.rotate(if (isCheckingStatus) spinAngle else 0f)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// More Options Overflow (Edit / Delete)
|
DropdownMenu(
|
||||||
Box {
|
expanded = showMenu,
|
||||||
IconButton(
|
onDismissRequest = { showMenu = false },
|
||||||
onClick = { showMenu = true },
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.background(BgElevated)
|
||||||
.size(34.dp)
|
.border(1.dp, BorderSubtle, RoundedCornerShape(12.dp))
|
||||||
.clip(RoundedCornerShape(9.dp))
|
) {
|
||||||
.background(BorderSubtle.copy(alpha = 0.25f))
|
DropdownMenuItem(
|
||||||
.border(1.dp, BorderSubtle, RoundedCornerShape(9.dp))
|
text = { Text("Edit Device", color = TextPrimary) },
|
||||||
) {
|
leadingIcon = {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.MoreVert,
|
Icons.Default.Edit,
|
||||||
contentDescription = "Device options",
|
contentDescription = null,
|
||||||
tint = TextSecondary,
|
tint = TextSecondary,
|
||||||
modifier = Modifier.size(18.dp)
|
modifier = Modifier.size(18.dp)
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
onClick = {
|
||||||
DropdownMenu(
|
showMenu = false
|
||||||
expanded = showMenu,
|
showEditDialog = true
|
||||||
onDismissRequest = { showMenu = false },
|
}
|
||||||
modifier = Modifier
|
)
|
||||||
.background(BgElevated)
|
DropdownMenuItem(
|
||||||
.border(1.dp, BorderSubtle, RoundedCornerShape(12.dp))
|
text = { Text("Remove Device", color = RedVibrant) },
|
||||||
) {
|
leadingIcon = {
|
||||||
DropdownMenuItem(
|
Icon(
|
||||||
text = { Text("Edit Device", color = TextPrimary) },
|
Icons.Default.DeleteOutline,
|
||||||
leadingIcon = {
|
contentDescription = null,
|
||||||
Icon(
|
tint = RedVibrant,
|
||||||
Icons.Default.Edit,
|
modifier = Modifier.size(18.dp)
|
||||||
contentDescription = null,
|
)
|
||||||
tint = TextSecondary,
|
},
|
||||||
modifier = Modifier.size(18.dp)
|
onClick = {
|
||||||
)
|
showMenu = false
|
||||||
},
|
showDeleteConfirm = true
|
||||||
onClick = {
|
}
|
||||||
showMenu = false
|
)
|
||||||
showEditDialog = true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
DropdownMenuItem(
|
|
||||||
text = { Text("Remove Device", color = RedVibrant) },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.DeleteOutline,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = RedVibrant,
|
|
||||||
modifier = Modifier.size(18.dp)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onClick = {
|
|
||||||
showMenu = false
|
|
||||||
showDeleteConfirm = true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,113 @@ class UpdateManager(
|
|||||||
mainHandler?.post(block) ?: block()
|
mainHandler?.post(block) ?: block()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously checks GitHub Releases API for the latest published release.
|
||||||
|
* Suitable for use inside background workers (e.g. WorkManager CoroutineWorker).
|
||||||
|
*/
|
||||||
|
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")
|
||||||
|
.addHeader("User-Agent", "ServerControlApp")
|
||||||
|
.get()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
return try {
|
||||||
|
val response = okHttpClient.newCall(request).execute()
|
||||||
|
response.use { res ->
|
||||||
|
if (res.code == 404) {
|
||||||
|
return UpdateCheckResult.UpToDate
|
||||||
|
}
|
||||||
|
if (!res.isSuccessful) {
|
||||||
|
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}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseReleases(body: String, currentVersionName: String): UpdateCheckResult {
|
||||||
|
return try {
|
||||||
|
val jsonElement = JsonParser.parseString(body)
|
||||||
|
val releasesArray = if (jsonElement.isJsonArray) {
|
||||||
|
jsonElement.asJsonArray
|
||||||
|
} else {
|
||||||
|
val arr = com.google.gson.JsonArray()
|
||||||
|
if (jsonElement.isJsonObject) arr.add(jsonElement.asJsonObject)
|
||||||
|
arr
|
||||||
|
}
|
||||||
|
|
||||||
|
var highestRelease: ReleaseInfo? = null
|
||||||
|
|
||||||
|
for (item in releasesArray) {
|
||||||
|
if (!item.isJsonObject) continue
|
||||||
|
val json = item.asJsonObject
|
||||||
|
if (json.has("draft") && json.get("draft").asBoolean) continue
|
||||||
|
|
||||||
|
val tagName = json.get("tag_name")?.asString.orEmpty()
|
||||||
|
val cleanVer = tagName.removePrefix("v").removePrefix("V").trim()
|
||||||
|
val title = json.get("name")?.asString?.ifBlank { tagName } ?: tagName
|
||||||
|
val changelog = json.get("body")?.asString.orEmpty()
|
||||||
|
|
||||||
|
val assets = json.getAsJsonArray("assets")
|
||||||
|
var apkUrl: String? = null
|
||||||
|
var apkApiUrl: String? = null
|
||||||
|
var apkName = "app-release.apk"
|
||||||
|
var apkSize = 0L
|
||||||
|
|
||||||
|
if (assets != null) {
|
||||||
|
for (element in assets) {
|
||||||
|
val assetObj = element.asJsonObject
|
||||||
|
val name = assetObj.get("name")?.asString.orEmpty()
|
||||||
|
if (name.endsWith(".apk", ignoreCase = true)) {
|
||||||
|
apkUrl = assetObj.get("browser_download_url")?.asString
|
||||||
|
apkApiUrl = assetObj.get("url")?.asString
|
||||||
|
apkName = name
|
||||||
|
apkSize = assetObj.get("size")?.asLong ?: 0L
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!apkUrl.isNullOrBlank()) {
|
||||||
|
val releaseInfo = ReleaseInfo(
|
||||||
|
tagName = tagName,
|
||||||
|
versionName = cleanVer,
|
||||||
|
title = title,
|
||||||
|
changelog = changelog,
|
||||||
|
downloadUrl = apkUrl,
|
||||||
|
assetApiUrl = apkApiUrl,
|
||||||
|
apkFileName = apkName,
|
||||||
|
sizeBytes = apkSize
|
||||||
|
)
|
||||||
|
|
||||||
|
if (highestRelease == null || isNewerVersion(cleanVer, highestRelease.versionName)) {
|
||||||
|
highestRelease = releaseInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highestRelease == null) {
|
||||||
|
return UpdateCheckResult.UpToDate
|
||||||
|
}
|
||||||
|
|
||||||
|
val cleanLocalVersion = currentVersionName.removePrefix("v").removePrefix("V").trim()
|
||||||
|
|
||||||
|
if (isNewerVersion(highestRelease.versionName, cleanLocalVersion)) {
|
||||||
|
UpdateCheckResult.UpdateAvailable(highestRelease)
|
||||||
|
} else {
|
||||||
|
UpdateCheckResult.UpToDate
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
UpdateCheckResult.Error("Failed to parse update info: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks GitHub Releases API for the latest published release.
|
* Checks GitHub Releases API for the latest published release.
|
||||||
*/
|
*/
|
||||||
@@ -81,86 +188,8 @@ class UpdateManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val body = res.body?.string().orEmpty()
|
val body = res.body?.string().orEmpty()
|
||||||
try {
|
val result = parseReleases(body, currentVersionName)
|
||||||
val jsonElement = JsonParser.parseString(body)
|
runOnMain { callback(result) }
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
var highestRelease: ReleaseInfo? = null
|
|
||||||
|
|
||||||
for (item in releasesArray) {
|
|
||||||
if (!item.isJsonObject) continue
|
|
||||||
val json = item.asJsonObject
|
|
||||||
if (json.has("draft") && json.get("draft").asBoolean) continue
|
|
||||||
|
|
||||||
val tagName = json.get("tag_name")?.asString.orEmpty()
|
|
||||||
val cleanVer = tagName.removePrefix("v").removePrefix("V").trim()
|
|
||||||
val title = json.get("name")?.asString?.ifBlank { tagName } ?: tagName
|
|
||||||
val changelog = json.get("body")?.asString.orEmpty()
|
|
||||||
|
|
||||||
val assets = json.getAsJsonArray("assets")
|
|
||||||
var apkUrl: String? = null
|
|
||||||
var apkApiUrl: String? = null
|
|
||||||
var apkName = "app-release.apk"
|
|
||||||
var apkSize = 0L
|
|
||||||
|
|
||||||
if (assets != null) {
|
|
||||||
for (element in assets) {
|
|
||||||
val assetObj = element.asJsonObject
|
|
||||||
val name = assetObj.get("name")?.asString.orEmpty()
|
|
||||||
if (name.endsWith(".apk", ignoreCase = true)) {
|
|
||||||
apkUrl = assetObj.get("browser_download_url")?.asString
|
|
||||||
apkApiUrl = assetObj.get("url")?.asString
|
|
||||||
apkName = name
|
|
||||||
apkSize = assetObj.get("size")?.asLong ?: 0L
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apkUrl.isNullOrBlank()) {
|
|
||||||
val releaseInfo = ReleaseInfo(
|
|
||||||
tagName = tagName,
|
|
||||||
versionName = cleanVer,
|
|
||||||
title = title,
|
|
||||||
changelog = changelog,
|
|
||||||
downloadUrl = apkUrl,
|
|
||||||
assetApiUrl = apkApiUrl,
|
|
||||||
apkFileName = apkName,
|
|
||||||
sizeBytes = apkSize
|
|
||||||
)
|
|
||||||
|
|
||||||
if (highestRelease == null || isNewerVersion(cleanVer, highestRelease.versionName)) {
|
|
||||||
highestRelease = releaseInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (highestRelease == null) {
|
|
||||||
runOnMain { callback(UpdateCheckResult.UpToDate) }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val cleanLocalVersion = currentVersionName.removePrefix("v").removePrefix("V").trim()
|
|
||||||
|
|
||||||
if (isNewerVersion(highestRelease.versionName, cleanLocalVersion)) {
|
|
||||||
runOnMain {
|
|
||||||
callback(UpdateCheckResult.UpdateAvailable(highestRelease))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
runOnMain { callback(UpdateCheckResult.UpToDate) }
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
runOnMain {
|
|
||||||
callback(UpdateCheckResult.Error("Failed to parse update info: ${e.message}"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -120,18 +120,17 @@ 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 {
|
try {
|
||||||
val updateManager = com.expapp.trigger.update.UpdateManager(appContext)
|
val updateManager = com.expapp.trigger.update.UpdateManager(appContext)
|
||||||
val currentVersion = com.expapp.trigger.BuildConfig.VERSION_NAME
|
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) {
|
if (result is com.expapp.trigger.update.UpdateCheckResult.UpdateAvailable) {
|
||||||
val newVer = result.info.versionName
|
val newVer = result.info.versionName
|
||||||
val lastNotified = appSettings.lastNotifiedUpdateVersion
|
val lastNotified = appSettings.lastNotifiedUpdateVersion
|
||||||
if (lastNotified != newVer) {
|
if (lastNotified != newVer) {
|
||||||
appSettings.lastNotifiedUpdateVersion = newVer
|
appSettings.lastNotifiedUpdateVersion = newVer
|
||||||
NotificationHelper.sendUpdateAvailableNotification(appContext, newVer)
|
NotificationHelper.sendUpdateAvailableNotification(appContext, newVer)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user