Check the git for a newer release and install it from the Car screen.

This commit is contained in:
RallyBlock committed 2026-10-22 21:00:41 -07:00
1 parent b95cbefeab
commit a164d9c135
6 files changed
+188 -2

No files matched your search

@@ -30,7 +30,9 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import android.content.Context
import com.racingapp.pitlog.data.Car
import com.racingapp.pitlog.data.checkForAppUpdate
import com.racingapp.pitlog.data.DEFAULT_CAR
import com.racingapp.pitlog.data.DEFAULT_CLASS
import com.racingapp.pitlog.data.DEFAULT_DISCIPLINE
@@ -62,6 +64,9 @@ class SettingsViewModel(private val repository: Repository) : ViewModel() {
private set
var syncing by mutableStateOf(false)
private set
var updating by mutableStateOf(false)
private set
var updateStatus by mutableStateOf("")
init {
serverAddress = repository.syncAddress()
@@ -148,6 +153,20 @@ class SettingsViewModel(private val repository: Repository) : ViewModel() {
}
}
fun checkForUpdate(context: Context) {
if (updating) return
updating = true
updateStatus = "Checking…"
viewModelScope.launch {
updateStatus = try {
checkForAppUpdate(context) { updateStatus = it }
} catch (_: Exception) {
"Couldn't check for an update."
}
updating = false
}
}
fun changeAutomatic(enabled: Boolean) {
automatic = enabled
repository.saveAddress(serverAddress)
@@ -325,6 +344,23 @@ fun SettingsScreen(onBack: () -> Unit) {
modifier = Modifier.padding(top = 8.dp),
)
}
SectionLabel("App")
OutlinedButton(
onClick = { viewModel.checkForUpdate(context) },
enabled = !viewModel.updating,
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
) {
Text(if (viewModel.updating) "Checking…" else "Check for updates")
}
if (viewModel.updateStatus.isNotBlank()) {
Text(
viewModel.updateStatus,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 8.dp),
)
}
}
}
}