feat(settings): restore last session on startup (#1102) (#1105)

This commit is contained in:
M57 authored and GitHub committed 2026-09-13 16:45:04 +03:00
1 parent 7e8af8db01
commit 4246ae196d
16 files changed
+234 -4

No files matched your search

@@ -677,6 +677,13 @@ class ChatViewModel(
if (!initial.isNullOrBlank()) {
initialSessionId = null
switchSession(initial)
} else if (AuthManager.isRestoreLastSession()) {
val restoredId = AuthManager.getLastOpenedSessionId()
if (!restoredId.isNullOrBlank()) {
switchSession(restoredId)
} else {
createNewSession(setLoading = false)
}
} else {
createNewSession(setLoading = false)
}
@@ -1406,6 +1413,7 @@ class ChatViewModel(
userMessage: ChatMessage? = null,
) {
val dispatchGeneration = sessionGeneration
AuthManager.setLastOpenedSessionId(storageSessionId)
val msgToPersist =
userMessage ?: ChatMessage(
role = MessageRole.USER,
@@ -2356,6 +2364,7 @@ class ChatViewModel(
.find { it.id == sessionId }
?.title ?: "Hermes"
val generation = resetSessionState(sessionId, title, isLoading = true)
AuthManager.setLastOpenedSessionId(sessionId)
viewModelScope.launch {
// Warm-cache fast-path (desktop parity): paint the cached Room
// transcript immediately so the screen never sits blank, then load
@@ -2708,6 +2717,9 @@ class ChatViewModel(
}
sessionGoneRecoveryInFlight = true
cancelResumeRetry()
if (AuthManager.getLastOpenedSessionId() == sessionId) {
AuthManager.clearLastOpenedSessionId()
}
_uiState.update {
it.copy(
isLoading = false,