Compare commits
1
Commits
583f421d7f
...
v1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57b96a21f2 |
@@ -0,0 +1,104 @@
|
|||||||
|
name: Build & Release Android APK
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
description: 'Custom release tag (e.g. v1.0.1)'
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
name: Build & Publish Release APK
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 17
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
|
||||||
|
- name: Setup Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v3
|
||||||
|
|
||||||
|
- name: Make Gradlew Executable
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
|
||||||
|
- name: Determine Version Tag
|
||||||
|
id: versioning
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.release_tag }}" ]; then
|
||||||
|
TAG="${{ inputs.release_tag }}"
|
||||||
|
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||||
|
TAG="${GITHUB_REF#refs/tags/}"
|
||||||
|
else
|
||||||
|
# On pushes to main, generate a version based on run number
|
||||||
|
TAG="v1.0.${{ github.run_number }}"
|
||||||
|
fi
|
||||||
|
echo "TAG=$TAG" >> $GITHUB_OUTPUT
|
||||||
|
echo "Release tag will be $TAG"
|
||||||
|
|
||||||
|
- name: Build Release APK
|
||||||
|
env:
|
||||||
|
KEYSTORE_PASSWORD: servercontrol123
|
||||||
|
KEY_ALIAS: servercontrol
|
||||||
|
KEY_PASSWORD: servercontrol123
|
||||||
|
run: |
|
||||||
|
./gradlew assembleRelease
|
||||||
|
|
||||||
|
- name: Find and Verify APK
|
||||||
|
id: apk
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find app/build/outputs/apk/release -name "*.apk" | head -n 1)
|
||||||
|
if [ -z "$APK_PATH" ]; then
|
||||||
|
echo "ERROR: Release APK not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Found APK at: $APK_PATH"
|
||||||
|
echo "APK_PATH=$APK_PATH" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Generate Changelog
|
||||||
|
id: changelog
|
||||||
|
run: |
|
||||||
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
||||||
|
if [ -n "$PREV_TAG" ]; then
|
||||||
|
CHANGES=$(git log ${PREV_TAG}..HEAD --oneline --no-merges)
|
||||||
|
else
|
||||||
|
CHANGES=$(git log -n 10 --oneline --no-merges)
|
||||||
|
fi
|
||||||
|
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "$CHANGES" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create GitHub Release & Upload APK
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ steps.versioning.outputs.TAG }}
|
||||||
|
name: Device Trigger ${{ steps.versioning.outputs.TAG }}
|
||||||
|
body: |
|
||||||
|
## 🚀 What's New in ${{ steps.versioning.outputs.TAG }}
|
||||||
|
|
||||||
|
${{ steps.changelog.outputs.CHANGELOG }}
|
||||||
|
|
||||||
|
---
|
||||||
|
*This release was built and signed automatically via GitHub Actions.*
|
||||||
|
files: ${{ steps.apk.outputs.APK_PATH }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -31,10 +31,13 @@ adb install -r app/build/outputs/apk/debug/app-debug.apk
|
|||||||
- **Massive Tactile Buttons**: High-contrast, large touch targets designed to prevent accidental mis-taps while remaining effortless to press.
|
- **Massive Tactile Buttons**: High-contrast, large touch targets designed to prevent accidental mis-taps while remaining effortless to press.
|
||||||
- **Horizontal Swipe Navigation**: Seamlessly swipe left and right between configured machines with an animated bottom page indicator.
|
- **Horizontal Swipe Navigation**: Seamlessly swipe left and right between configured machines with an animated bottom page indicator.
|
||||||
- **Dynamic Cloudflare R2 Configuration**: Simply supply your Cloudflare R2 JSON URL when adding a device; the app fetches and validates endpoint URLs automatically.
|
- **Dynamic Cloudflare R2 Configuration**: Simply supply your Cloudflare R2 JSON URL when adding a device; the app fetches and validates endpoint URLs automatically.
|
||||||
|
- **One-Tap R2 Config Re-fetch**: If you modify endpoint URLs in your Cloudflare R2 JSON, simply tap the **Re-fetch R2 JSON** button (or top-bar Sync) to update all URLs instantly without losing your device secretKey or configuration.
|
||||||
|
- **Device Configuration Editor**: Easily edit device names, node identifiers, secret keys, or R2 URLs anytime via the built-in edit dialog.
|
||||||
|
- **In-App Self-Updating (OTA)**: Automatically checks GitHub Releases on launch. When a newer version is pushed to GitHub, an in-app dialog displays the changelog with a one-tap "Update Now" installer that updates the APK in-place without wiping any saved data or credentials.
|
||||||
- **Multi-Device Support**: Manage any number of remote machines. The last swipe tab is always an **"+ Add Device"** configuration screen.
|
- **Multi-Device Support**: Manage any number of remote machines. The last swipe tab is always an **"+ Add Device"** configuration screen.
|
||||||
- **Persistent Local Storage**: Configured machines are safely saved to Android persistent storage (`SharedPreferences`) so they remain available whenever the app is reopened.
|
- **Persistent Local Storage**: Configured machines are safely saved to Android persistent storage (`SharedPreferences`) so they remain available whenever the app is reopened and preserved across app updates.
|
||||||
- **Mistake-Proof Safety Prompts**: Reboot and Power Off actions trigger a quick confirmation dialog before sending the request.
|
- **Mistake-Proof Safety Prompts**: Reboot, Power Off, and Power On actions trigger a quick confirmation dialog before sending the request.
|
||||||
- **Instant Visual Feedback**: On-screen status banners, in-button loading indicators, and Android Toast notifications display HTTP status codes (e.g., `200 OK`) and server responses.
|
- **Instant Visual Feedback**: On-screen status banners, in-button loading indicators, live uptime/last-seen telemetry, and Android Toast notifications display HTTP status codes (e.g., `200 OK`) and server responses.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,33 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signingConfigs {
|
||||||
|
create("release") {
|
||||||
|
val keystoreFile = file("release.keystore")
|
||||||
|
if (keystoreFile.exists()) {
|
||||||
|
storeFile = keystoreFile
|
||||||
|
storePassword = System.getenv("KEYSTORE_PASSWORD") ?: "servercontrol123"
|
||||||
|
keyAlias = System.getenv("KEY_ALIAS") ?: "servercontrol"
|
||||||
|
keyPassword = System.getenv("KEY_PASSWORD") ?: "servercontrol123"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = false
|
||||||
|
signingConfig = signingConfigs.getByName("release")
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
debug {
|
||||||
|
val relConfig = signingConfigs.findByName("release")
|
||||||
|
if (relConfig?.storeFile?.exists() == true) {
|
||||||
|
signingConfig = relConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
@@ -38,6 +57,7 @@ android {
|
|||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
|
buildConfig = true
|
||||||
}
|
}
|
||||||
composeOptions {
|
composeOptions {
|
||||||
kotlinCompilerExtensionVersion = "1.5.8"
|
kotlinCompilerExtensionVersion = "1.5.8"
|
||||||
|
|||||||
Binary file not shown.
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -20,6 +21,16 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -0,0 +1,320 @@
|
|||||||
|
package com.expapp.trigger.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
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.CloudDownload
|
||||||
|
import androidx.compose.material.icons.filled.Download
|
||||||
|
import androidx.compose.material.icons.filled.SystemUpdate
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import com.expapp.trigger.update.DownloadState
|
||||||
|
import com.expapp.trigger.update.ReleaseInfo
|
||||||
|
import com.expapp.trigger.ui.theme.BgElevated
|
||||||
|
import com.expapp.trigger.ui.theme.BgSurface
|
||||||
|
import com.expapp.trigger.ui.theme.BorderDefault
|
||||||
|
import com.expapp.trigger.ui.theme.BorderSubtle
|
||||||
|
import com.expapp.trigger.ui.theme.GreenVibrant
|
||||||
|
import com.expapp.trigger.ui.theme.RedVibrant
|
||||||
|
import com.expapp.trigger.ui.theme.TextMuted
|
||||||
|
import com.expapp.trigger.ui.theme.TextPrimary
|
||||||
|
import com.expapp.trigger.ui.theme.TextSecondary
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun UpdateDialog(
|
||||||
|
releaseInfo: ReleaseInfo,
|
||||||
|
currentVersion: String,
|
||||||
|
downloadState: DownloadState,
|
||||||
|
onDownload: () -> Unit,
|
||||||
|
onInstall: (File) -> Unit,
|
||||||
|
onDismiss: () -> Unit
|
||||||
|
) {
|
||||||
|
Dialog(onDismissRequest = {
|
||||||
|
if (downloadState !is DownloadState.Downloading) {
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(24.dp))
|
||||||
|
.background(
|
||||||
|
brush = Brush.verticalGradient(
|
||||||
|
listOf(Color(0xFF0C1420), Color(0xFF070B12))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.border(1.dp, GreenVibrant.copy(alpha = 0.35f), RoundedCornerShape(24.dp))
|
||||||
|
.padding(24.dp)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
// Header Icon
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(60.dp)
|
||||||
|
.background(
|
||||||
|
brush = Brush.radialGradient(
|
||||||
|
listOf(GreenVibrant.copy(alpha = 0.22f), Color.Transparent)
|
||||||
|
),
|
||||||
|
shape = CircleShape
|
||||||
|
)
|
||||||
|
.border(1.dp, GreenVibrant.copy(alpha = 0.45f), CircleShape),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.SystemUpdate,
|
||||||
|
contentDescription = "Update",
|
||||||
|
tint = GreenVibrant,
|
||||||
|
modifier = Modifier.size(28.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Update Available",
|
||||||
|
fontSize = 20.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = TextPrimary
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
|
||||||
|
// Version Badge row: v1.0 -> v1.1
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "v$currentVersion",
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = TextMuted,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(BgElevated)
|
||||||
|
.border(1.dp, BorderSubtle, RoundedCornerShape(8.dp))
|
||||||
|
.padding(horizontal = 8.dp, vertical = 3.dp)
|
||||||
|
)
|
||||||
|
Text("→", fontSize = 14.sp, color = GreenVibrant, fontWeight = FontWeight.Bold)
|
||||||
|
Text(
|
||||||
|
text = releaseInfo.tagName,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = GreenVibrant,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(GreenVibrant.copy(alpha = 0.12f))
|
||||||
|
.border(1.dp, GreenVibrant.copy(alpha = 0.4f), RoundedCornerShape(8.dp))
|
||||||
|
.padding(horizontal = 8.dp, vertical = 3.dp)
|
||||||
|
)
|
||||||
|
if (releaseInfo.sizeBytes > 0) {
|
||||||
|
val mb = String.format("%.1f MB", releaseInfo.sizeBytes / (1024.0 * 1024.0))
|
||||||
|
Text(
|
||||||
|
text = mb,
|
||||||
|
fontSize = 11.sp,
|
||||||
|
color = TextSecondary,
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(BgElevated)
|
||||||
|
.border(1.dp, BorderSubtle, RoundedCornerShape(8.dp))
|
||||||
|
.padding(horizontal = 6.dp, vertical = 3.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
// Changelog Card
|
||||||
|
Text(
|
||||||
|
text = "WHAT'S NEW",
|
||||||
|
fontSize = 11.sp,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
color = TextMuted,
|
||||||
|
letterSpacing = 1.sp,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.heightIn(max = 140.dp)
|
||||||
|
.clip(RoundedCornerShape(14.dp))
|
||||||
|
.background(BgElevated)
|
||||||
|
.border(1.dp, BorderDefault, RoundedCornerShape(14.dp))
|
||||||
|
.padding(14.dp)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
) {
|
||||||
|
val changelogText = if (releaseInfo.changelog.isNotBlank()) {
|
||||||
|
releaseInfo.changelog.trim()
|
||||||
|
} else {
|
||||||
|
"• Performance improvements & new features."
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = changelogText,
|
||||||
|
fontSize = 13.sp,
|
||||||
|
color = TextSecondary,
|
||||||
|
lineHeight = 18.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
// Download Progress / States
|
||||||
|
when (downloadState) {
|
||||||
|
is DownloadState.Downloading -> {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Downloading update…",
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = TextSecondary
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "${downloadState.progressPercent}%",
|
||||||
|
fontSize = 12.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = GreenVibrant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
LinearProgressIndicator(
|
||||||
|
progress = { downloadState.progressPercent / 100f },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(8.dp)
|
||||||
|
.clip(RoundedCornerShape(4.dp)),
|
||||||
|
color = GreenVibrant,
|
||||||
|
trackColor = GreenVibrant.copy(alpha = 0.15f)
|
||||||
|
)
|
||||||
|
if (downloadState.totalBytes > 0) {
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
val downloadedMb = String.format("%.1f", downloadState.bytesDownloaded / (1024.0 * 1024.0))
|
||||||
|
val totalMb = String.format("%.1f MB", downloadState.totalBytes / (1024.0 * 1024.0))
|
||||||
|
Text(
|
||||||
|
text = "$downloadedMb / $totalMb",
|
||||||
|
fontSize = 11.sp,
|
||||||
|
color = TextMuted
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is DownloadState.Failed -> {
|
||||||
|
Text(
|
||||||
|
text = downloadState.error,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
color = RedVibrant,
|
||||||
|
modifier = Modifier.padding(vertical = 4.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
|
// Actions row
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||||
|
) {
|
||||||
|
TextButton(
|
||||||
|
onClick = onDismiss,
|
||||||
|
enabled = downloadState !is DownloadState.Downloading,
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.clip(RoundedCornerShape(14.dp))
|
||||||
|
.background(BgElevated)
|
||||||
|
.border(1.dp, BorderDefault, RoundedCornerShape(14.dp))
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Later",
|
||||||
|
color = TextSecondary,
|
||||||
|
fontWeight = FontWeight.Medium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
when (downloadState) {
|
||||||
|
is DownloadState.ReadyToInstall -> onInstall(downloadState.apkFile)
|
||||||
|
is DownloadState.Downloading -> {}
|
||||||
|
else -> onDownload()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = downloadState !is DownloadState.Downloading,
|
||||||
|
shape = RoundedCornerShape(14.dp),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = GreenVibrant.copy(alpha = 0.2f),
|
||||||
|
contentColor = GreenVibrant
|
||||||
|
),
|
||||||
|
modifier = Modifier.weight(1.3f)
|
||||||
|
) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
val icon = when (downloadState) {
|
||||||
|
is DownloadState.ReadyToInstall -> Icons.Default.SystemUpdate
|
||||||
|
else -> Icons.Default.Download
|
||||||
|
}
|
||||||
|
val text = when (downloadState) {
|
||||||
|
is DownloadState.ReadyToInstall -> "Install Now"
|
||||||
|
is DownloadState.Failed -> "Retry"
|
||||||
|
is DownloadState.Downloading -> "Downloading…"
|
||||||
|
else -> "Update Now"
|
||||||
|
}
|
||||||
|
Icon(icon, contentDescription = null, modifier = Modifier.size(16.dp))
|
||||||
|
Spacer(modifier = Modifier.width(6.dp))
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
fontSize = 14.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,19 +29,25 @@ import androidx.compose.foundation.layout.width
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.CloudSync
|
||||||
import androidx.compose.material.icons.filled.DeleteOutline
|
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.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.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
|
||||||
|
import androidx.compose.material.icons.filled.Visibility
|
||||||
|
import androidx.compose.material.icons.filled.VisibilityOff
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -58,6 +64,8 @@ import androidx.compose.ui.graphics.Brush
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.expapp.trigger.data.model.DeviceConfig
|
import com.expapp.trigger.data.model.DeviceConfig
|
||||||
@@ -66,6 +74,7 @@ import com.expapp.trigger.network.TriggerAction
|
|||||||
import com.expapp.trigger.ui.components.ActionConfirmDialog
|
import com.expapp.trigger.ui.components.ActionConfirmDialog
|
||||||
import com.expapp.trigger.ui.components.HugeActionButton
|
import com.expapp.trigger.ui.components.HugeActionButton
|
||||||
import com.expapp.trigger.ui.components.StatusBanner
|
import com.expapp.trigger.ui.components.StatusBanner
|
||||||
|
import com.expapp.trigger.ui.theme.AmberVibrant
|
||||||
import com.expapp.trigger.ui.theme.BgElevated
|
import com.expapp.trigger.ui.theme.BgElevated
|
||||||
import com.expapp.trigger.ui.theme.BgSurface
|
import com.expapp.trigger.ui.theme.BgSurface
|
||||||
import com.expapp.trigger.ui.theme.BorderDefault
|
import com.expapp.trigger.ui.theme.BorderDefault
|
||||||
@@ -100,10 +109,111 @@ fun DevicePage(
|
|||||||
onRefreshStatus: () -> Unit,
|
onRefreshStatus: () -> Unit,
|
||||||
onTrigger: (TriggerAction) -> Unit,
|
onTrigger: (TriggerAction) -> Unit,
|
||||||
onDelete: (DeviceConfig) -> Unit,
|
onDelete: (DeviceConfig) -> Unit,
|
||||||
|
onSyncConfig: () -> Unit = {},
|
||||||
|
onUpdateDevice: (DeviceConfig) -> Unit = {},
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
var pendingAction by remember { mutableStateOf<TriggerAction?>(null) }
|
var pendingAction by remember { mutableStateOf<TriggerAction?>(null) }
|
||||||
var showDeleteConfirm by remember { mutableStateOf(false) }
|
var showDeleteConfirm by remember { mutableStateOf(false) }
|
||||||
|
var showEditDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showEditDialog) {
|
||||||
|
var editName by remember { mutableStateOf(device.name) }
|
||||||
|
var editNode by remember { mutableStateOf(device.node) }
|
||||||
|
var editR2Url by remember { mutableStateOf(device.r2Url) }
|
||||||
|
var editSecretKey by remember { mutableStateOf(device.secretKey) }
|
||||||
|
var showKey by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val editFieldColors = OutlinedTextFieldDefaults.colors(
|
||||||
|
focusedBorderColor = GreenVibrant,
|
||||||
|
unfocusedBorderColor = BorderDefault,
|
||||||
|
focusedLabelColor = GreenVibrant,
|
||||||
|
unfocusedLabelColor = TextSecondary,
|
||||||
|
cursorColor = GreenVibrant,
|
||||||
|
focusedTextColor = TextPrimary,
|
||||||
|
unfocusedTextColor = TextPrimary
|
||||||
|
)
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { showEditDialog = false },
|
||||||
|
containerColor = BgSurface,
|
||||||
|
shape = RoundedCornerShape(20.dp),
|
||||||
|
title = { Text("Edit Device", color = TextPrimary, fontWeight = FontWeight.Bold) },
|
||||||
|
text = {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = editName,
|
||||||
|
onValueChange = { editName = it },
|
||||||
|
label = { Text("Device Name") },
|
||||||
|
singleLine = true,
|
||||||
|
colors = editFieldColors,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = editNode,
|
||||||
|
onValueChange = { editNode = it },
|
||||||
|
label = { Text("Node Identifier") },
|
||||||
|
singleLine = true,
|
||||||
|
colors = editFieldColors,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = editR2Url,
|
||||||
|
onValueChange = { editR2Url = it },
|
||||||
|
label = { Text("Cloudflare R2 JSON URL") },
|
||||||
|
singleLine = true,
|
||||||
|
colors = editFieldColors,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = editSecretKey,
|
||||||
|
onValueChange = { editSecretKey = it },
|
||||||
|
label = { Text("Secret Key") },
|
||||||
|
trailingIcon = {
|
||||||
|
IconButton(onClick = { showKey = !showKey }) {
|
||||||
|
Icon(
|
||||||
|
if (showKey) Icons.Default.VisibilityOff else Icons.Default.Visibility,
|
||||||
|
null,
|
||||||
|
tint = TextSecondary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
visualTransformation = if (showKey) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
|
singleLine = true,
|
||||||
|
colors = editFieldColors,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
showEditDialog = false
|
||||||
|
val updated = device.copy(
|
||||||
|
name = editName.trim().ifBlank { device.name },
|
||||||
|
node = editNode.trim().ifBlank { device.node },
|
||||||
|
r2Url = editR2Url.trim(),
|
||||||
|
secretKey = editSecretKey.trim()
|
||||||
|
)
|
||||||
|
onUpdateDevice(updated)
|
||||||
|
},
|
||||||
|
colors = ButtonDefaults.buttonColors(containerColor = GreenVibrant.copy(alpha = 0.2f)),
|
||||||
|
shape = RoundedCornerShape(12.dp)
|
||||||
|
) {
|
||||||
|
Text("Save", color = GreenVibrant, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { showEditDialog = false }) {
|
||||||
|
Text("Cancel", color = TextSecondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (pendingAction != null) {
|
if (pendingAction != null) {
|
||||||
ActionConfirmDialog(
|
ActionConfirmDialog(
|
||||||
@@ -274,6 +384,44 @@ fun DevicePage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Re-fetch R2 JSON config button
|
||||||
|
IconButton(
|
||||||
|
onClick = onSyncConfig,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(36.dp)
|
||||||
|
.clip(RoundedCornerShape(10.dp))
|
||||||
|
.background(AmberVibrant.copy(alpha = 0.08f))
|
||||||
|
.border(1.dp, AmberVibrant.copy(alpha = 0.2f), RoundedCornerShape(10.dp))
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.CloudSync,
|
||||||
|
contentDescription = "Re-fetch R2 JSON",
|
||||||
|
tint = AmberVibrant,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(6.dp))
|
||||||
|
|
||||||
|
// Edit device button
|
||||||
|
IconButton(
|
||||||
|
onClick = { showEditDialog = true },
|
||||||
|
modifier = Modifier
|
||||||
|
.size(36.dp)
|
||||||
|
.clip(RoundedCornerShape(10.dp))
|
||||||
|
.background(BorderSubtle.copy(alpha = 0.3f))
|
||||||
|
.border(1.dp, BorderSubtle, RoundedCornerShape(10.dp))
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Edit,
|
||||||
|
contentDescription = "Edit device",
|
||||||
|
tint = TextSecondary,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(6.dp))
|
||||||
|
|
||||||
// Refresh button (spins while checking)
|
// Refresh button (spins while checking)
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { if (!isCheckingStatus) onRefreshStatus() },
|
onClick = { if (!isCheckingStatus) onRefreshStatus() },
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.animation.core.tween
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@@ -24,6 +25,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
import androidx.compose.material.icons.filled.Refresh
|
||||||
|
import androidx.compose.material.icons.filled.SystemUpdate
|
||||||
import androidx.compose.material.icons.filled.Terminal
|
import androidx.compose.material.icons.filled.Terminal
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -53,12 +55,15 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
|
import com.expapp.trigger.BuildConfig
|
||||||
import com.expapp.trigger.data.model.DeviceConfig
|
import com.expapp.trigger.data.model.DeviceConfig
|
||||||
import com.expapp.trigger.data.repository.DeviceRepository
|
import com.expapp.trigger.data.repository.DeviceRepository
|
||||||
import com.expapp.trigger.network.NodeStatus
|
import com.expapp.trigger.network.NodeStatus
|
||||||
import com.expapp.trigger.network.TriggerAction
|
import com.expapp.trigger.network.TriggerAction
|
||||||
import com.expapp.trigger.network.TriggerClient
|
import com.expapp.trigger.network.TriggerClient
|
||||||
|
import com.expapp.trigger.ui.components.UpdateDialog
|
||||||
import com.expapp.trigger.ui.theme.BgBase
|
import com.expapp.trigger.ui.theme.BgBase
|
||||||
|
import com.expapp.trigger.ui.theme.BgElevated
|
||||||
import com.expapp.trigger.ui.theme.BgSurface
|
import com.expapp.trigger.ui.theme.BgSurface
|
||||||
import com.expapp.trigger.ui.theme.BorderSubtle
|
import com.expapp.trigger.ui.theme.BorderSubtle
|
||||||
import com.expapp.trigger.ui.theme.GreenVibrant
|
import com.expapp.trigger.ui.theme.GreenVibrant
|
||||||
@@ -68,6 +73,10 @@ import com.expapp.trigger.ui.theme.OnlineText
|
|||||||
import com.expapp.trigger.ui.theme.TextMuted
|
import com.expapp.trigger.ui.theme.TextMuted
|
||||||
import com.expapp.trigger.ui.theme.TextPrimary
|
import com.expapp.trigger.ui.theme.TextPrimary
|
||||||
import com.expapp.trigger.ui.theme.TextSecondary
|
import com.expapp.trigger.ui.theme.TextSecondary
|
||||||
|
import com.expapp.trigger.update.DownloadState
|
||||||
|
import com.expapp.trigger.update.ReleaseInfo
|
||||||
|
import com.expapp.trigger.update.UpdateCheckResult
|
||||||
|
import com.expapp.trigger.update.UpdateManager
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -98,6 +107,35 @@ fun MainScreen(
|
|||||||
onDispose { lifecycleOwner.lifecycle.removeObserver(obs) }
|
onDispose { lifecycleOwner.lifecycle.removeObserver(obs) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val updateManager = remember { UpdateManager(context) }
|
||||||
|
var availableUpdate by remember { mutableStateOf<ReleaseInfo?>(null) }
|
||||||
|
var showUpdateDialog by remember { mutableStateOf(false) }
|
||||||
|
var downloadState by remember { mutableStateOf<DownloadState>(DownloadState.Idle) }
|
||||||
|
var isCheckingUpdate by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
fun checkAppUpdate(showToast: Boolean = false) {
|
||||||
|
isCheckingUpdate = true
|
||||||
|
updateManager.checkForUpdate(BuildConfig.VERSION_NAME) { result ->
|
||||||
|
isCheckingUpdate = false
|
||||||
|
when (result) {
|
||||||
|
is UpdateCheckResult.UpdateAvailable -> {
|
||||||
|
availableUpdate = result.info
|
||||||
|
showUpdateDialog = true
|
||||||
|
}
|
||||||
|
is UpdateCheckResult.UpToDate -> {
|
||||||
|
if (showToast) {
|
||||||
|
Toast.makeText(context, "App is up to date (v${BuildConfig.VERSION_NAME})", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is UpdateCheckResult.Error -> {
|
||||||
|
if (showToast) {
|
||||||
|
Toast.makeText(context, "Update check failed: ${result.message}", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val loadingStates = remember { mutableStateMapOf<String, Boolean>() }
|
val loadingStates = remember { mutableStateMapOf<String, Boolean>() }
|
||||||
val statusStates = remember { mutableStateMapOf<String, Pair<String, Boolean>>() }
|
val statusStates = remember { mutableStateMapOf<String, Pair<String, Boolean>>() }
|
||||||
val nodeStatuses = remember { mutableStateMapOf<String, NodeStatus>() }
|
val nodeStatuses = remember { mutableStateMapOf<String, NodeStatus>() }
|
||||||
@@ -116,11 +154,18 @@ fun MainScreen(
|
|||||||
|
|
||||||
fun syncEndpoints(showToast: Boolean = false) {
|
fun syncEndpoints(showToast: Boolean = false) {
|
||||||
val current = repository.getDevices()
|
val current = repository.getDevices()
|
||||||
if (current.isEmpty()) return
|
if (current.isEmpty()) {
|
||||||
|
checkAppUpdate(showToast)
|
||||||
|
return
|
||||||
|
}
|
||||||
isSyncing = true
|
isSyncing = true
|
||||||
var updated = 0; var completed = 0
|
var updated = 0; var completed = 0
|
||||||
val total = current.count { it.r2Url.isNotBlank() }
|
val total = current.count { it.r2Url.isNotBlank() }
|
||||||
if (total == 0) { isSyncing = false; return }
|
if (total == 0) {
|
||||||
|
isSyncing = false
|
||||||
|
checkAppUpdate(showToast)
|
||||||
|
return
|
||||||
|
}
|
||||||
current.filter { it.r2Url.isNotBlank() }.forEach { device ->
|
current.filter { it.r2Url.isNotBlank() }.forEach { device ->
|
||||||
triggerClient.fetchR2Config(device.r2Url) { result ->
|
triggerClient.fetchR2Config(device.r2Url) { result ->
|
||||||
completed++
|
completed++
|
||||||
@@ -135,13 +180,17 @@ fun MainScreen(
|
|||||||
if (updated > 0) "Endpoints updated" else "Already up to date",
|
if (updated > 0) "Endpoints updated" else "Already up to date",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
checkAppUpdate(showToast)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial R2 sync on launch
|
// Initial R2 sync and update check on launch
|
||||||
LaunchedEffect(Unit) { syncEndpoints(false) }
|
LaunchedEffect(Unit) {
|
||||||
|
syncEndpoints(false)
|
||||||
|
checkAppUpdate(false)
|
||||||
|
}
|
||||||
|
|
||||||
// Active 5-second polling — only while in foreground on a device page
|
// Active 5-second polling — only while in foreground on a device page
|
||||||
LaunchedEffect(pagerState.currentPage, isAppInForeground, devices.size) {
|
LaunchedEffect(pagerState.currentPage, isAppInForeground, devices.size) {
|
||||||
@@ -232,6 +281,27 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
|
if (availableUpdate != null) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(GreenVibrant.copy(alpha = 0.15f))
|
||||||
|
.border(1.dp, GreenVibrant.copy(alpha = 0.4f), RoundedCornerShape(8.dp))
|
||||||
|
.clickable { showUpdateDialog = true }
|
||||||
|
.padding(horizontal = 8.dp, vertical = 5.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.SystemUpdate, null, tint = GreenVibrant, modifier = Modifier.size(13.dp))
|
||||||
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
|
Text(
|
||||||
|
"v${availableUpdate!!.versionName}",
|
||||||
|
color = GreenVibrant,
|
||||||
|
fontSize = 11.sp,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
|
}
|
||||||
IconButton(onClick = { syncEndpoints(true) }, enabled = !isSyncing) {
|
IconButton(onClick = { syncEndpoints(true) }, enabled = !isSyncing) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Refresh,
|
Icons.Default.Refresh,
|
||||||
@@ -299,7 +369,36 @@ fun MainScreen(
|
|||||||
onDismissStatus = { statusStates.remove(dev.id) },
|
onDismissStatus = { statusStates.remove(dev.id) },
|
||||||
onRefreshStatus = { refreshStatus(dev, showIndicator = true) },
|
onRefreshStatus = { refreshStatus(dev, showIndicator = true) },
|
||||||
onTrigger = { action -> executeAction(dev, action) },
|
onTrigger = { action -> executeAction(dev, action) },
|
||||||
onDelete = { d -> repository.deleteDevice(d.id); devices = repository.getDevices() }
|
onDelete = { d -> repository.deleteDevice(d.id); devices = repository.getDevices() },
|
||||||
|
onSyncConfig = {
|
||||||
|
triggerClient.fetchR2Config(dev.r2Url) { result ->
|
||||||
|
result.onSuccess { ep ->
|
||||||
|
val changed = repository.updateEndpoints(dev.id, ep.powerOn, ep.powerOff, ep.reboot, ep.status)
|
||||||
|
devices = repository.getDevices()
|
||||||
|
val msg = if (changed) "Endpoints updated from R2" else "Endpoints already up to date"
|
||||||
|
statusStates[dev.id] = msg to true
|
||||||
|
refreshStatus(dev, showIndicator = true)
|
||||||
|
}.onFailure { ex ->
|
||||||
|
statusStates[dev.id] = "Failed to fetch R2: ${ex.message}" to false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onUpdateDevice = { updated ->
|
||||||
|
repository.updateDevice(updated)
|
||||||
|
devices = repository.getDevices()
|
||||||
|
if (updated.r2Url.isNotBlank() && updated.r2Url != dev.r2Url) {
|
||||||
|
triggerClient.fetchR2Config(updated.r2Url) { result ->
|
||||||
|
result.onSuccess { ep ->
|
||||||
|
repository.updateEndpoints(updated.id, ep.powerOn, ep.powerOff, ep.reboot, ep.status)
|
||||||
|
devices = repository.getDevices()
|
||||||
|
statusStates[updated.id] = "Device & endpoints updated" to true
|
||||||
|
refreshStatus(updated, showIndicator = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusStates[updated.id] = "Device updated" to true
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
AddDevicePage(
|
AddDevicePage(
|
||||||
@@ -317,4 +416,24 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showUpdateDialog && availableUpdate != null) {
|
||||||
|
UpdateDialog(
|
||||||
|
releaseInfo = availableUpdate!!,
|
||||||
|
currentVersion = BuildConfig.VERSION_NAME,
|
||||||
|
downloadState = downloadState,
|
||||||
|
onDownload = {
|
||||||
|
downloadState = DownloadState.Downloading(0, 0, availableUpdate!!.sizeBytes)
|
||||||
|
updateManager.downloadApk(availableUpdate!!.downloadUrl) { state ->
|
||||||
|
downloadState = state
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onInstall = { file ->
|
||||||
|
updateManager.installApk(file)
|
||||||
|
},
|
||||||
|
onDismiss = {
|
||||||
|
showUpdateDialog = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,285 @@
|
|||||||
|
package com.expapp.trigger.update
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.provider.Settings
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
import okhttp3.Call
|
||||||
|
import okhttp3.Callback
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class UpdateManager(
|
||||||
|
private val context: Context,
|
||||||
|
private val okHttpClient: OkHttpClient = OkHttpClient.Builder()
|
||||||
|
.connectTimeout(30, TimeUnit.SECONDS)
|
||||||
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
|
.build(),
|
||||||
|
val githubRepo: String = "vaishnosingh/server-control-app"
|
||||||
|
) {
|
||||||
|
private val mainHandler = try {
|
||||||
|
val looper = Looper.getMainLooper()
|
||||||
|
if (looper != null) Handler(looper) else null
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runOnMain(block: () -> Unit) {
|
||||||
|
mainHandler?.post(block) ?: block()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks GitHub Releases API for the latest published release.
|
||||||
|
*/
|
||||||
|
fun checkForUpdate(
|
||||||
|
currentVersionName: String,
|
||||||
|
callback: (UpdateCheckResult) -> Unit
|
||||||
|
) {
|
||||||
|
val url = "https://api.github.com/repos/$githubRepo/releases/latest"
|
||||||
|
|
||||||
|
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("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()
|
||||||
|
try {
|
||||||
|
val json = JsonParser.parseString(body).asJsonObject
|
||||||
|
val tagName = json.get("tag_name")?.asString.orEmpty()
|
||||||
|
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 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
|
||||||
|
apkName = name
|
||||||
|
apkSize = assetObj.get("size")?.asLong ?: 0L
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apkUrl.isNullOrBlank()) {
|
||||||
|
runOnMain { callback(UpdateCheckResult.UpToDate) }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val cleanRemoteVersion = tagName.removePrefix("v").removePrefix("V").trim()
|
||||||
|
val cleanLocalVersion = currentVersionName.removePrefix("v").removePrefix("V").trim()
|
||||||
|
|
||||||
|
if (isNewerVersion(cleanRemoteVersion, cleanLocalVersion)) {
|
||||||
|
val releaseInfo = ReleaseInfo(
|
||||||
|
tagName = tagName,
|
||||||
|
versionName = cleanRemoteVersion,
|
||||||
|
title = title,
|
||||||
|
changelog = changelog,
|
||||||
|
downloadUrl = apkUrl,
|
||||||
|
apkFileName = apkName,
|
||||||
|
sizeBytes = apkSize
|
||||||
|
)
|
||||||
|
runOnMain {
|
||||||
|
callback(UpdateCheckResult.UpdateAvailable(releaseInfo))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
runOnMain { callback(UpdateCheckResult.UpToDate) }
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
runOnMain {
|
||||||
|
callback(UpdateCheckResult.Error("Failed to parse update info: ${e.message}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the APK file to the app's cache directory and streams progress updates.
|
||||||
|
*/
|
||||||
|
fun downloadApk(
|
||||||
|
downloadUrl: String,
|
||||||
|
onProgress: (DownloadState) -> Unit
|
||||||
|
): Call {
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(downloadUrl)
|
||||||
|
.addHeader("User-Agent", "ServerControlApp")
|
||||||
|
.get()
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val call = okHttpClient.newCall(request)
|
||||||
|
call.enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {
|
||||||
|
if (!call.isCanceled()) {
|
||||||
|
runOnMain {
|
||||||
|
onProgress(DownloadState.Failed("Download failed: ${e.localizedMessage}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call, response: Response) {
|
||||||
|
if (!response.isSuccessful) {
|
||||||
|
runOnMain {
|
||||||
|
onProgress(DownloadState.Failed("Server returned HTTP ${response.code}"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val responseBody = response.body
|
||||||
|
if (responseBody == null) {
|
||||||
|
runOnMain {
|
||||||
|
onProgress(DownloadState.Failed("Response body was empty"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val updateDir = File(context.cacheDir, "updates")
|
||||||
|
if (!updateDir.exists()) {
|
||||||
|
updateDir.mkdirs()
|
||||||
|
}
|
||||||
|
val apkFile = File(updateDir, "update.apk")
|
||||||
|
if (apkFile.exists()) {
|
||||||
|
apkFile.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val totalBytes = responseBody.contentLength()
|
||||||
|
var bytesDownloaded = 0L
|
||||||
|
|
||||||
|
responseBody.byteStream().use { input ->
|
||||||
|
FileOutputStream(apkFile).use { output ->
|
||||||
|
val buffer = ByteArray(8192)
|
||||||
|
var read: Int
|
||||||
|
var lastPercent = -1
|
||||||
|
|
||||||
|
while (input.read(buffer).also { read = it } != -1) {
|
||||||
|
if (call.isCanceled()) return
|
||||||
|
|
||||||
|
output.write(buffer, 0, read)
|
||||||
|
bytesDownloaded += read
|
||||||
|
|
||||||
|
val percent = if (totalBytes > 0) {
|
||||||
|
((bytesDownloaded * 100) / totalBytes).toInt()
|
||||||
|
} else 0
|
||||||
|
|
||||||
|
if (percent != lastPercent) {
|
||||||
|
lastPercent = percent
|
||||||
|
runOnMain {
|
||||||
|
onProgress(
|
||||||
|
DownloadState.Downloading(
|
||||||
|
progressPercent = percent,
|
||||||
|
bytesDownloaded = bytesDownloaded,
|
||||||
|
totalBytes = totalBytes
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnMain {
|
||||||
|
onProgress(DownloadState.ReadyToInstall(apkFile))
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (!call.isCanceled()) {
|
||||||
|
runOnMain {
|
||||||
|
onProgress(DownloadState.Failed("File write failed: ${e.localizedMessage}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return call
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompts Android package installer to install the downloaded APK.
|
||||||
|
*/
|
||||||
|
fun installApk(apkFile: File) {
|
||||||
|
if (!apkFile.exists()) return
|
||||||
|
|
||||||
|
// On Android 8.0+, check if installing from unknown sources is permitted
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
if (!context.packageManager.canRequestPackageInstalls()) {
|
||||||
|
val settingsIntent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).apply {
|
||||||
|
data = Uri.parse("package:${context.packageName}")
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
}
|
||||||
|
context.startActivity(settingsIntent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val apkUri = FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
"${context.packageName}.fileprovider",
|
||||||
|
apkFile
|
||||||
|
)
|
||||||
|
|
||||||
|
val installIntent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
|
setDataAndType(apkUri, "application/vnd.android.package-archive")
|
||||||
|
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
}
|
||||||
|
context.startActivity(installIntent)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Semantic version comparator. Returns true if remote is strictly greater than local.
|
||||||
|
*/
|
||||||
|
fun isNewerVersion(remote: String, local: String): Boolean {
|
||||||
|
val remoteParts = remote.split("-")[0].split(".").mapNotNull { it.toIntOrNull() }
|
||||||
|
val localParts = local.split("-")[0].split(".").mapNotNull { it.toIntOrNull() }
|
||||||
|
|
||||||
|
val maxLen = maxOf(remoteParts.size, localParts.size)
|
||||||
|
for (i in 0 until maxLen) {
|
||||||
|
val r = remoteParts.getOrElse(i) { 0 }
|
||||||
|
val l = localParts.getOrElse(i) { 0 }
|
||||||
|
if (r > l) return true
|
||||||
|
if (r < l) return false
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.expapp.trigger.update
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
data class ReleaseInfo(
|
||||||
|
val tagName: String,
|
||||||
|
val versionName: String,
|
||||||
|
val title: String,
|
||||||
|
val changelog: String,
|
||||||
|
val downloadUrl: String,
|
||||||
|
val apkFileName: String,
|
||||||
|
val sizeBytes: Long
|
||||||
|
)
|
||||||
|
|
||||||
|
sealed class UpdateCheckResult {
|
||||||
|
data class UpdateAvailable(val info: ReleaseInfo) : UpdateCheckResult()
|
||||||
|
object UpToDate : UpdateCheckResult()
|
||||||
|
data class Error(val message: String) : UpdateCheckResult()
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class DownloadState {
|
||||||
|
object Idle : DownloadState()
|
||||||
|
data class Downloading(
|
||||||
|
val progressPercent: Int,
|
||||||
|
val bytesDownloaded: Long,
|
||||||
|
val totalBytes: Long
|
||||||
|
) : DownloadState()
|
||||||
|
data class ReadyToInstall(val apkFile: File) : DownloadState()
|
||||||
|
data class Failed(val error: String) : DownloadState()
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<cache-path name="apk_cache" path="updates/" />
|
||||||
|
<external-cache-path name="apk_external_cache" path="updates/" />
|
||||||
|
</paths>
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.expapp.trigger.update
|
||||||
|
|
||||||
|
import okhttp3.mockwebserver.MockResponse
|
||||||
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class UpdateManagerTest {
|
||||||
|
|
||||||
|
private lateinit var server: MockWebServer
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
server = MockWebServer()
|
||||||
|
server.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() {
|
||||||
|
server.shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun isNewerVersion_correctlyComparesVersions() {
|
||||||
|
assertTrue(UpdateManager.isNewerVersion("1.1", "1.0"))
|
||||||
|
assertTrue(UpdateManager.isNewerVersion("1.0.1", "1.0.0"))
|
||||||
|
assertTrue(UpdateManager.isNewerVersion("2.0.0", "1.9.9"))
|
||||||
|
assertTrue(UpdateManager.isNewerVersion("1.2.0", "1.1"))
|
||||||
|
|
||||||
|
assertFalse(UpdateManager.isNewerVersion("1.0", "1.0"))
|
||||||
|
assertFalse(UpdateManager.isNewerVersion("1.0.0", "1.0"))
|
||||||
|
assertFalse(UpdateManager.isNewerVersion("1.0", "1.1"))
|
||||||
|
assertFalse(UpdateManager.isNewerVersion("0.9", "1.0"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
sdk.dir=/home/creserver/Android/Sdk
|
|
||||||
Reference in New Issue
Block a user