mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
feat(agent): keep the unsent message across leaving the Agent tab (#2863)
This commit is contained in:
1 parent
d852b1a4e5
commit
674e0d6fa4
2 files changed
+29
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package com.droiddeck.launcher.agent
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
|
||||
/** The text typed in the Agent tab and not yet sent, kept across leaving the tab and restarts. */
|
||||
object AgentDraft {
|
||||
private const val KEY = "draft"
|
||||
private var state: MutableState<String>? = null
|
||||
|
||||
fun state(context: Context): MutableState<String> = state ?: run {
|
||||
val prefs = AgentHost.prefs(context.applicationContext)
|
||||
val backing = mutableStateOf(prefs.getString(KEY, "") ?: "")
|
||||
object : MutableState<String> {
|
||||
override var value: String
|
||||
get() = backing.value
|
||||
set(text) {
|
||||
if (text == backing.value) return
|
||||
backing.value = text
|
||||
prefs.edit().apply { if (text.isEmpty()) remove(KEY) else putString(KEY, text) }.apply()
|
||||
}
|
||||
override fun component1() = value
|
||||
override fun component2(): (String) -> Unit = { value = it }
|
||||
}.also { state = it }
|
||||
}
|
||||
}
|
||||
@@ -122,6 +122,7 @@ import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.DialogWindowProvider
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.agent.AgentAttachments
|
||||
import com.droiddeck.launcher.agent.AgentDraft
|
||||
import com.droiddeck.launcher.agent.AgentHost
|
||||
import com.droiddeck.launcher.agent.AgentHost.Entry
|
||||
import com.droiddeck.launcher.agent.AgentSetup
|
||||
@@ -207,7 +208,7 @@ private fun AgentPageContent(
|
||||
}
|
||||
remember { AgentSetup.check(context) }
|
||||
var setup by rememberSaveable { mutableStateOf(false) }
|
||||
val draft = rememberSaveable { mutableStateOf("") }
|
||||
val draft = remember { AgentDraft.state(context) }
|
||||
if (setup || AgentHost.state == AgentHost.State.MISSING || !(AgentSetup.ready || AgentSetup.completed(context))) {
|
||||
AgentSetupView(modifier, firstControl = inputModifier, onDone = { setup = false })
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user