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

@@ -12,6 +12,8 @@ data class ServerStoreState(
val port: Int = 9119,
val baseUrl: String? = null,
val autoReconnect: Boolean = true,
val restoreLastSession: Boolean = false,
val lastOpenedSessionIds: Map<String, String> = emptyMap(),
val themePreference: ThemePreference = ThemePreference.SYSTEM,
val useDynamicColors: Boolean = false,
val themePreset: ThemePreset = ThemePreset.DEFAULT,
@@ -616,6 +616,47 @@ object AuthManager {
serverStore.update { it.copy(autoReconnect = enabled) }
}
// ── Restore last session on startup (issue #1102) ─────────────────────
private fun currentSessionScopeKey(): String {
val connId = getSelectedProfileId()?.takeIf { it.isNotBlank() } ?: DEFAULT_PROFILE_ID
val serverProfile = activeProfileId.value?.takeIf { it.isNotBlank() } ?: DEFAULT_PROFILE_ID
return "$connId:$serverProfile"
}
fun isRestoreLastSession(): Boolean = serverStore.getLatestState().restoreLastSession
fun setRestoreLastSession(enabled: Boolean) {
serverStore.update { it.copy(restoreLastSession = enabled) }
}
fun getLastOpenedSessionId(): String? = serverStore.getLatestState().lastOpenedSessionIds[currentSessionScopeKey()]
fun setLastOpenedSessionId(sessionId: String?) {
val key = currentSessionScopeKey()
serverStore.update { state ->
val updated =
if (sessionId != null) {
state.lastOpenedSessionIds + (key to sessionId)
} else {
state.lastOpenedSessionIds - key
}
state.copy(lastOpenedSessionIds = updated)
}
}
fun clearLastOpenedSessionId() {
setLastOpenedSessionId(null)
}
fun clearLastOpenedSessionIdsForConnection(connectionProfileId: String) {
serverStore.update { state ->
val prefix = "$connectionProfileId:"
val updated = state.lastOpenedSessionIds.filterKeys { !it.startsWith(prefix) }
state.copy(lastOpenedSessionIds = updated)
}
}
// ── Theme preference ──────────────────────────────────────────────────
fun getThemePreference(): ThemePreference = serverStore.getLatestState().themePreference