A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
fix(ui): real uptime baseline, memoize settings probes, resync storage toggle, surface export errors
ExTvf0224c518e87
diff --git a/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt b/app/src/main/java/com/excp/podroid/engine/EngineHolder.ktindex 77464fd..8c54251 100644--- a/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt+++ b/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt@@ -282,6 +282,8 @@ class EngineHolder @Inject constructor(_currentFlow.value = next}+ override val runningSinceMs: Long? get() = current.runningSinceMs+// ── VmEngine: flows that follow the currently-selected engine ──────────// A freshly (re)selected engine that hasn't been started this cycle has its// retained terminal state (Stopped/Error) normalized to Idle, so a swap-backdiff --git a/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.ktindex 680f296..a05d70d 100644--- a/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt+++ b/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt@@ -127,17 +127,28 @@ class HomeViewModel @Inject constructor(}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false)- private var runningSinceMs: Long? = null+ // Fallback timestamp stamped the first time we observe Running, used when the+ // engine doesn't supply runningSinceMs (e.g. a future engine that omits the override).+ private var fallbackRunningSinceMs: Long? = null++ // The uptime baseline: prefer the real →Running timestamp from the engine so+ // rotation / Activity recreation doesn't reset the displayed uptime to "Up 0s"+ // while the VM has actually been running for minutes.+ private val runningSinceMs: Long?+ get() = engine.runningSinceMs ?: fallbackRunningSinceMsinit {checkForUpdate()- // Maintain runningSinceMs for the synchronous read path used by uptime formatter.+ // Maintain fallbackRunningSinceMs for engines that don't override runningSinceMs.viewModelScope.launch {var lastWasRunning = falseengine.state.collect { state ->val nowRunning = state is VmState.Running- if (nowRunning && !lastWasRunning) runningSinceMs = System.currentTimeMillis()- if (!nowRunning) runningSinceMs = null+ if (nowRunning && !lastWasRunning) {+ // Only stamp the fallback when the engine doesn't provide the real time.+ if (engine.runningSinceMs == null) fallbackRunningSinceMs = System.currentTimeMillis()+ }+ if (!nowRunning) fallbackRunningSinceMs = nulllastWasRunning = nowRunning}}diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.ktindex 44c83f9..5d0857a 100644--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt@@ -33,11 +33,14 @@ import androidx.compose.material3.IconButtonimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.OutlinedTextFieldimport androidx.compose.material3.Scaffold+import androidx.compose.material3.SnackbarHost+import androidx.compose.material3.SnackbarHostStateimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.material3.windowsizeclass.WindowHeightSizeClassimport androidx.compose.material3.windowsizeclass.WindowSizeClassimport androidx.compose.runtime.Composable+import androidx.compose.runtime.DisposableEffectimport androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValueimport androidx.compose.runtime.key@@ -54,6 +57,9 @@ import androidx.compose.ui.text.input.KeyboardTypeimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.spimport androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel+import androidx.lifecycle.Lifecycle+import androidx.lifecycle.LifecycleEventObserver+import androidx.lifecycle.compose.LocalLifecycleOwnerimport androidx.lifecycle.compose.collectAsStateWithLifecycleimport com.excp.podroid.BuildConfigimport com.excp.podroid.data.repository.PortForwardRule@@ -86,6 +92,7 @@ fun SettingsScreen(val ui by viewModel.uiState.collectAsStateWithLifecycle()val portForwardRules by viewModel.portForwardRules.collectAsStateWithLifecycle()val vmState by viewModel.vmState.collectAsStateWithLifecycle()+ val exportError by viewModel.exportError.collectAsStateWithLifecycle()var advancedExpanded by remember { mutableStateOf(false) }var showAddDialog by remember { mutableStateOf(false) }@@ -96,6 +103,35 @@ fun SettingsScreen(val ctx = LocalContext.currentval vmNotRunning = vmState !is VmState.Running && vmState !is VmState.Starting+ // Memoize: both values are constant for the process lifetime / until a backend+ // swap, so there's no point re-running reflection on every recomposition.+ val isDownloadsShareAvailable = remember { viewModel.isDownloadsShareAvailable() }+ val activeBackendId = remember { viewModel.activeBackendId() }++ // Re-sync the persisted storageAccessEnabled flag against the real OS grant on+ // every resume (user may have denied all-files-access on the system screen we+ // sent them to, but the DataStore flag still reads true).+ val lifecycleOwner = LocalLifecycleOwner.current+ DisposableEffect(lifecycleOwner) {+ val observer = LifecycleEventObserver { _, event ->+ if (event == Lifecycle.Event.ON_RESUME &&+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&+ !Environment.isExternalStorageManager()+ ) {+ viewModel.setStorageAccessEnabled(false)+ }+ }+ lifecycleOwner.lifecycle.addObserver(observer)+ onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }+ }++ val snackbarHostState = remember { SnackbarHostState() }+ LaunchedEffect(exportError) {+ val msg = exportError ?: return@LaunchedEffect+ snackbarHostState.showSnackbar(msg)+ viewModel.clearExportError()+ }+Scaffold(topBar = {PodroidTopBar(@@ -107,6 +143,7 @@ fun SettingsScreen(},)},+ snackbarHost = { SnackbarHost(snackbarHostState) },containerColor = MaterialTheme.colorScheme.background,) { innerPadding ->val isCompactHeight = windowSizeClass.heightSizeClass == WindowHeightSizeClass.Compact@@ -203,8 +240,8 @@ fun SettingsScreen(DownloadsSharingRow(enabled = ui.storageAccessEnabled,vmNotRunning = vmNotRunning,- available = viewModel.isDownloadsShareAvailable(),- activeBackendId = viewModel.activeBackendId(),+ available = isDownloadsShareAvailable,+ activeBackendId = activeBackendId,onToggle = { viewModel.setStorageAccessEnabled(it) },)Spacer(Modifier.height(PodroidTokens.Spacing.MD))@@ -295,7 +332,7 @@ fun SettingsScreen(} else nullavfReportText = probe.copy(smokeTestResult = smoke,- activeBackend = viewModel.activeBackendId(),+ activeBackend = activeBackendId,).pretty()avfRunning = false}diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.ktindex bc30f96..263baf8 100644--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt@@ -24,8 +24,10 @@ import com.excp.podroid.util.NetworkUtilsimport dagger.hilt.android.lifecycle.HiltViewModelimport dagger.hilt.android.qualifiers.ApplicationContextimport kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.SharingStartedimport kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.flow.combineimport kotlinx.coroutines.flow.stateInimport kotlinx.coroutines.launch@@ -228,6 +230,12 @@ class SettingsViewModel @Inject constructor(else -> true}+ private val _exportError = MutableStateFlow<String?>(null)+ /** One-shot export failure message; clear after showing with [clearExportError]. */+ val exportError: StateFlow<String?> = _exportError.asStateFlow()++ fun clearExportError() { _exportError.value = null }+fun removePortForward(rule: PortForwardRule) {viewModelScope.launch { portForwardRepository.removeRule(rule) }}@@ -279,6 +287,7 @@ class SettingsViewModel @Inject constructor(})} catch (e: Exception) {Log.w(TAG, "Export failed", e)+ _exportError.value = "Export failed: ${e.message ?: "unknown error"}"}}}