feat: persist login state and remove mock entry flow
This commit is contained in:
1 parent
6ec824f078
commit
eeff16a4ca
7 files changed
+76
-90
No files matched your search
@@ -62,6 +62,7 @@ kotlin {
|
|||||||
implementation(libs.ktor.client.contentNegotiation)
|
implementation(libs.ktor.client.contentNegotiation)
|
||||||
implementation(libs.ktor.serialization.kotlinx.json)
|
implementation(libs.ktor.serialization.kotlinx.json)
|
||||||
implementation(libs.kotlinx.serialization.json)
|
implementation(libs.kotlinx.serialization.json)
|
||||||
|
implementation(libs.multiplatform.settings.no.arg)
|
||||||
}
|
}
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(libs.kotlin.test)
|
implementation(libs.kotlin.test)
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.xiaobai.openclawapp.app.DataSourceMode
|
|
||||||
import cn.xiaobai.openclawapp.app.MainTab
|
import cn.xiaobai.openclawapp.app.MainTab
|
||||||
import cn.xiaobai.openclawapp.app.OpenClawAppState
|
import cn.xiaobai.openclawapp.app.OpenClawAppState
|
||||||
import cn.xiaobai.openclawapp.data.ServerConfig
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
@@ -49,14 +48,12 @@ fun App() {
|
|||||||
token = token,
|
token = token,
|
||||||
password = password,
|
password = password,
|
||||||
defaultAgent = agent,
|
defaultAgent = agent,
|
||||||
dataSource = appState.dataSource,
|
|
||||||
isConnecting = appState.isConnecting,
|
isConnecting = appState.isConnecting,
|
||||||
errorMessage = appState.configError,
|
errorMessage = appState.configError,
|
||||||
onBaseUrlChange = { baseUrl = it },
|
onBaseUrlChange = { baseUrl = it },
|
||||||
onTokenChange = { token = it },
|
onTokenChange = { token = it },
|
||||||
onPasswordChange = { password = it },
|
onPasswordChange = { password = it },
|
||||||
onDefaultAgentChange = { agent = it },
|
onDefaultAgentChange = { agent = it },
|
||||||
onDataSourceChange = appState::updateDataSource,
|
|
||||||
onConnect = {
|
onConnect = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
appState.clearConfigError()
|
appState.clearConfigError()
|
||||||
@@ -90,8 +87,8 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(appState.isConfigured, appState.dataSource) {
|
LaunchedEffect(appState.isConfigured) {
|
||||||
if (appState.isConfigured && appState.dataSource == DataSourceMode.Remote) {
|
if (appState.isConfigured) {
|
||||||
appState.syncRemoteIfNeeded()
|
appState.syncRemoteIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,10 +201,8 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
currentModel = appState.repository.status.currentModel,
|
currentModel = appState.repository.status.currentModel,
|
||||||
availableAgents = appState.repository.availableAgents,
|
availableAgents = appState.repository.availableAgents,
|
||||||
currentTheme = appState.themeMode,
|
currentTheme = appState.themeMode,
|
||||||
currentDataSource = appState.dataSource,
|
|
||||||
onSelectAgent = appState::updateDefaultAgent,
|
onSelectAgent = appState::updateDefaultAgent,
|
||||||
onSelectTheme = appState::updateTheme,
|
onSelectTheme = appState::updateTheme,
|
||||||
onSelectDataSource = appState::updateDataSource,
|
|
||||||
onDisconnect = appState::disconnect,
|
onDisconnect = appState::disconnect,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,36 @@ package cn.xiaobai.openclawapp.app
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import cn.xiaobai.openclawapp.data.AppPreferences
|
||||||
import cn.xiaobai.openclawapp.data.OpenClawRepository
|
import cn.xiaobai.openclawapp.data.OpenClawRepository
|
||||||
import cn.xiaobai.openclawapp.data.RemoteOpenClawRepository
|
import cn.xiaobai.openclawapp.data.RemoteOpenClawRepository
|
||||||
import cn.xiaobai.openclawapp.data.RepositoryFactory
|
import cn.xiaobai.openclawapp.data.RepositoryFactory
|
||||||
import cn.xiaobai.openclawapp.data.ServerConfig
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
import cn.xiaobai.openclawapp.network.MobileGatewayApi
|
import cn.xiaobai.openclawapp.network.MobileGatewayApi
|
||||||
|
|
||||||
class OpenClawAppState {
|
class OpenClawAppState(
|
||||||
var isConfigured by mutableStateOf(false)
|
private val preferences: AppPreferences = AppPreferences(),
|
||||||
|
) {
|
||||||
var selectedTab by mutableStateOf(MainTab.Sessions)
|
var selectedTab by mutableStateOf(MainTab.Sessions)
|
||||||
var activeSessionId by mutableStateOf<String?>(null)
|
var activeSessionId by mutableStateOf<String?>(null)
|
||||||
var serverConfig by mutableStateOf(ServerConfig())
|
var serverConfig by mutableStateOf(preferences.loadServerConfig())
|
||||||
var feedbackMessage by mutableStateOf<String?>(null)
|
var feedbackMessage by mutableStateOf<String?>(null)
|
||||||
var themeMode by mutableStateOf(AppThemeMode.Dark)
|
var themeMode by mutableStateOf(preferences.loadThemeMode())
|
||||||
var dataSource by mutableStateOf(DataSourceMode.Mock)
|
|
||||||
var isSyncing by mutableStateOf(false)
|
var isSyncing by mutableStateOf(false)
|
||||||
var isSending by mutableStateOf(false)
|
var isSending by mutableStateOf(false)
|
||||||
var isConnecting by mutableStateOf(false)
|
var isConnecting by mutableStateOf(false)
|
||||||
var syncError by mutableStateOf<String?>(null)
|
var syncError by mutableStateOf<String?>(null)
|
||||||
var configError by mutableStateOf<String?>(null)
|
var configError by mutableStateOf<String?>(null)
|
||||||
var repository: OpenClawRepository by mutableStateOf(RepositoryFactory.createMock())
|
var repository: OpenClawRepository by mutableStateOf(RepositoryFactory.createRemote(serverConfig))
|
||||||
|
var isConfigured by mutableStateOf(serverConfig.baseUrl.isNotBlank() && serverConfig.token.isNotBlank())
|
||||||
|
|
||||||
suspend fun connect(config: ServerConfig, password: String) {
|
suspend fun connect(config: ServerConfig, password: String) {
|
||||||
isConnecting = true
|
isConnecting = true
|
||||||
configError = null
|
configError = null
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
val resolvedConfig = if (dataSource == DataSourceMode.Remote && config.token.isBlank()) {
|
val resolvedConfig = if (config.token.isBlank()) {
|
||||||
require(password.isNotBlank()) { "Remote 模式下请输入登录密码或直接填写 token" }
|
require(password.isNotBlank()) { "请输入 BFF 登录密码或直接填写 token" }
|
||||||
val loginApi = MobileGatewayApi(baseUrl = config.baseUrl, tokenProvider = { "" })
|
val loginApi = MobileGatewayApi(baseUrl = config.baseUrl, tokenProvider = { "" })
|
||||||
val login = loginApi.login(password)
|
val login = loginApi.login(password)
|
||||||
config.copy(token = login.token)
|
config.copy(token = login.token)
|
||||||
@@ -39,16 +41,11 @@ class OpenClawAppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverConfig = resolvedConfig
|
serverConfig = resolvedConfig
|
||||||
repository = when (dataSource) {
|
preferences.saveServerConfig(resolvedConfig)
|
||||||
DataSourceMode.Mock -> RepositoryFactory.createMock()
|
repository = RepositoryFactory.createRemote(resolvedConfig)
|
||||||
DataSourceMode.Remote -> RepositoryFactory.createRemote(resolvedConfig)
|
|
||||||
}
|
|
||||||
isConfigured = true
|
isConfigured = true
|
||||||
syncError = null
|
syncError = null
|
||||||
feedbackMessage = when (dataSource) {
|
feedbackMessage = "已连接到 ${resolvedConfig.baseUrl}"
|
||||||
DataSourceMode.Mock -> "已进入 Mock 模式"
|
|
||||||
DataSourceMode.Remote -> "已连接到 ${resolvedConfig.baseUrl}"
|
|
||||||
}
|
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
configError = it.message ?: "连接失败"
|
configError = it.message ?: "连接失败"
|
||||||
feedbackMessage = "连接失败"
|
feedbackMessage = "连接失败"
|
||||||
@@ -63,6 +60,9 @@ class OpenClawAppState {
|
|||||||
selectedTab = MainTab.Sessions
|
selectedTab = MainTab.Sessions
|
||||||
syncError = null
|
syncError = null
|
||||||
configError = null
|
configError = null
|
||||||
|
serverConfig = serverConfig.copy(token = "")
|
||||||
|
preferences.clearLoginState()
|
||||||
|
repository = RepositoryFactory.createRemote(serverConfig)
|
||||||
feedbackMessage = "连接已断开"
|
feedbackMessage = "连接已断开"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,12 +100,7 @@ class OpenClawAppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun sendMessage(sessionId: String, text: String) {
|
suspend fun sendMessage(sessionId: String, text: String) {
|
||||||
val remote = repository as? RemoteOpenClawRepository
|
val remote = repository as? RemoteOpenClawRepository ?: return
|
||||||
if (remote == null) {
|
|
||||||
repository.sendMessage(sessionId, text)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isSending = true
|
isSending = true
|
||||||
runCatching {
|
runCatching {
|
||||||
remote.sendMessageRemote(sessionId, text)
|
remote.sendMessageRemote(sessionId, text)
|
||||||
@@ -118,12 +113,14 @@ class OpenClawAppState {
|
|||||||
|
|
||||||
fun updateDefaultAgent(agent: String) {
|
fun updateDefaultAgent(agent: String) {
|
||||||
serverConfig = serverConfig.copy(defaultAgent = agent)
|
serverConfig = serverConfig.copy(defaultAgent = agent)
|
||||||
|
preferences.saveServerConfig(serverConfig)
|
||||||
repository.status = repository.status.copy(defaultAgent = agent)
|
repository.status = repository.status.copy(defaultAgent = agent)
|
||||||
feedbackMessage = "默认 Agent 已切换到 $agent"
|
feedbackMessage = "默认 Agent 已切换到 $agent"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateTheme(theme: AppThemeMode) {
|
fun updateTheme(theme: AppThemeMode) {
|
||||||
themeMode = theme
|
themeMode = theme
|
||||||
|
preferences.saveThemeMode(theme)
|
||||||
feedbackMessage = when (theme) {
|
feedbackMessage = when (theme) {
|
||||||
AppThemeMode.Dark -> "已切到深色主题"
|
AppThemeMode.Dark -> "已切到深色主题"
|
||||||
AppThemeMode.Light -> "已切到浅色主题"
|
AppThemeMode.Light -> "已切到浅色主题"
|
||||||
@@ -135,14 +132,6 @@ class OpenClawAppState {
|
|||||||
feedbackMessage = if (pinned) "已置顶会话" else "已取消置顶"
|
feedbackMessage = if (pinned) "已置顶会话" else "已取消置顶"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateDataSource(mode: DataSourceMode) {
|
|
||||||
dataSource = mode
|
|
||||||
feedbackMessage = when (mode) {
|
|
||||||
DataSourceMode.Mock -> "数据源已切到 Mock"
|
|
||||||
DataSourceMode.Remote -> "数据源已切到 Remote"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearFeedback() {
|
fun clearFeedback() {
|
||||||
feedbackMessage = null
|
feedbackMessage = null
|
||||||
}
|
}
|
||||||
@@ -166,8 +155,3 @@ enum class AppThemeMode(val label: String) {
|
|||||||
Dark("深色"),
|
Dark("深色"),
|
||||||
Light("浅色"),
|
Light("浅色"),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DataSourceMode(val label: String) {
|
|
||||||
Mock("Mock"),
|
|
||||||
Remote("Remote"),
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cn.xiaobai.openclawapp.data
|
||||||
|
|
||||||
|
import cn.xiaobai.openclawapp.app.AppThemeMode
|
||||||
|
import com.russhwolf.settings.Settings
|
||||||
|
|
||||||
|
class AppPreferences(
|
||||||
|
private val settings: Settings = Settings(),
|
||||||
|
) {
|
||||||
|
fun loadServerConfig(): ServerConfig {
|
||||||
|
return ServerConfig(
|
||||||
|
baseUrl = settings.getStringOrNull(KEY_BASE_URL) ?: "http://192.168.31.116:8788",
|
||||||
|
token = settings.getStringOrNull(KEY_TOKEN) ?: "",
|
||||||
|
defaultAgent = settings.getStringOrNull(KEY_DEFAULT_AGENT) ?: "main",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveServerConfig(config: ServerConfig) {
|
||||||
|
settings.putString(KEY_BASE_URL, config.baseUrl)
|
||||||
|
settings.putString(KEY_TOKEN, config.token)
|
||||||
|
settings.putString(KEY_DEFAULT_AGENT, config.defaultAgent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearLoginState() {
|
||||||
|
settings.remove(KEY_TOKEN)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadThemeMode(): AppThemeMode {
|
||||||
|
return when (settings.getStringOrNull(KEY_THEME_MODE)) {
|
||||||
|
AppThemeMode.Light.name -> AppThemeMode.Light
|
||||||
|
else -> AppThemeMode.Dark
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveThemeMode(themeMode: AppThemeMode) {
|
||||||
|
settings.putString(KEY_THEME_MODE, themeMode.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val KEY_BASE_URL = "server.base_url"
|
||||||
|
private const val KEY_TOKEN = "server.token"
|
||||||
|
private const val KEY_DEFAULT_AGENT = "server.default_agent"
|
||||||
|
private const val KEY_THEME_MODE = "ui.theme_mode"
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-29
@@ -1,6 +1,5 @@
|
|||||||
package cn.xiaobai.openclawapp.feature.config
|
package cn.xiaobai.openclawapp.feature.config
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
@@ -17,9 +16,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.xiaobai.openclawapp.app.DataSourceMode
|
|
||||||
import cn.xiaobai.openclawapp.ui.HeroCard
|
import cn.xiaobai.openclawapp.ui.HeroCard
|
||||||
import cn.xiaobai.openclawapp.ui.SelectableRowCard
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ServerConfigScreen(
|
fun ServerConfigScreen(
|
||||||
@@ -27,14 +24,12 @@ fun ServerConfigScreen(
|
|||||||
token: String,
|
token: String,
|
||||||
password: String,
|
password: String,
|
||||||
defaultAgent: String,
|
defaultAgent: String,
|
||||||
dataSource: DataSourceMode,
|
|
||||||
isConnecting: Boolean,
|
isConnecting: Boolean,
|
||||||
errorMessage: String?,
|
errorMessage: String?,
|
||||||
onBaseUrlChange: (String) -> Unit,
|
onBaseUrlChange: (String) -> Unit,
|
||||||
onTokenChange: (String) -> Unit,
|
onTokenChange: (String) -> Unit,
|
||||||
onPasswordChange: (String) -> Unit,
|
onPasswordChange: (String) -> Unit,
|
||||||
onDefaultAgentChange: (String) -> Unit,
|
onDefaultAgentChange: (String) -> Unit,
|
||||||
onDataSourceChange: (DataSourceMode) -> Unit,
|
|
||||||
onConnect: () -> Unit,
|
onConnect: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
@@ -46,29 +41,10 @@ fun ServerConfigScreen(
|
|||||||
) {
|
) {
|
||||||
HeroCard(
|
HeroCard(
|
||||||
title = "连接 OpenClaw",
|
title = "连接 OpenClaw",
|
||||||
subtitle = "第一版先支持 Mock 和 Remote 两种数据源。Remote 模式下可以直接用 BFF 登录密码换 token。",
|
subtitle = "现在默认直接连接真实 BFF。地址和 token 会自动持久化,下次打开 app 可以直接恢复。",
|
||||||
badge = "Setup",
|
badge = "Remote Only",
|
||||||
)
|
)
|
||||||
|
|
||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(18.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
|
||||||
) {
|
|
||||||
Text("数据源", style = MaterialTheme.typography.titleMedium)
|
|
||||||
DataSourceMode.entries.forEach { mode ->
|
|
||||||
SelectableRowCard(
|
|
||||||
title = mode.label,
|
|
||||||
trailing = if (mode == dataSource) "当前" else null,
|
|
||||||
selected = mode == dataSource,
|
|
||||||
modifier = Modifier.clickable { onDataSourceChange(mode) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -89,7 +65,7 @@ fun ServerConfigScreen(
|
|||||||
onValueChange = onPasswordChange,
|
onValueChange = onPasswordChange,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
label = { Text("登录密码") },
|
label = { Text("登录密码") },
|
||||||
placeholder = { Text("Remote 模式可直接填 BFF 登录密码") },
|
placeholder = { Text("优先推荐填 BFF 登录密码") },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
)
|
)
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
@@ -97,7 +73,7 @@ fun ServerConfigScreen(
|
|||||||
onValueChange = onTokenChange,
|
onValueChange = onTokenChange,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
label = { Text("访问令牌(可选)") },
|
label = { Text("访问令牌(可选)") },
|
||||||
placeholder = { Text("如果已知 token,也可以直接填写") },
|
placeholder = { Text("如果已经登录过,也可以直接填 token") },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
)
|
)
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
@@ -129,7 +105,7 @@ fun ServerConfigScreen(
|
|||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
CircularProgressIndicator()
|
CircularProgressIndicator()
|
||||||
} else {
|
} else {
|
||||||
Text(if (dataSource == DataSourceMode.Mock) "进入应用(Mock)" else "登录并进入")
|
Text("登录并进入")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-19
@@ -13,7 +13,6 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.xiaobai.openclawapp.app.AppThemeMode
|
import cn.xiaobai.openclawapp.app.AppThemeMode
|
||||||
import cn.xiaobai.openclawapp.app.DataSourceMode
|
|
||||||
import cn.xiaobai.openclawapp.data.ServerConfig
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
import cn.xiaobai.openclawapp.ui.HeroCard
|
import cn.xiaobai.openclawapp.ui.HeroCard
|
||||||
import cn.xiaobai.openclawapp.ui.LabelValueCard
|
import cn.xiaobai.openclawapp.ui.LabelValueCard
|
||||||
@@ -26,10 +25,8 @@ fun SettingsScreen(
|
|||||||
currentModel: String,
|
currentModel: String,
|
||||||
availableAgents: List<String>,
|
availableAgents: List<String>,
|
||||||
currentTheme: AppThemeMode,
|
currentTheme: AppThemeMode,
|
||||||
currentDataSource: DataSourceMode,
|
|
||||||
onSelectAgent: (String) -> Unit,
|
onSelectAgent: (String) -> Unit,
|
||||||
onSelectTheme: (AppThemeMode) -> Unit,
|
onSelectTheme: (AppThemeMode) -> Unit,
|
||||||
onSelectDataSource: (DataSourceMode) -> Unit,
|
|
||||||
onDisconnect: () -> Unit,
|
onDisconnect: () -> Unit,
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -39,7 +36,7 @@ fun SettingsScreen(
|
|||||||
item {
|
item {
|
||||||
HeroCard(
|
HeroCard(
|
||||||
title = "连接配置",
|
title = "连接配置",
|
||||||
subtitle = "这里先承载服务器地址、token 状态、默认 Agent、主题和数据源。等网络层接通后,再继续拆细。",
|
subtitle = "现在 app 默认只走真实 BFF。这里主要管理地址、token 状态、默认 Agent 和主题。",
|
||||||
badge = "Settings",
|
badge = "Settings",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -51,20 +48,7 @@ fun SettingsScreen(
|
|||||||
LabelValueCard(label = "当前模型", value = currentModel)
|
LabelValueCard(label = "当前模型", value = currentModel)
|
||||||
}
|
}
|
||||||
item {
|
item {
|
||||||
LabelValueCard(label = "访问令牌", value = if (serverConfig.token.isBlank()) "未设置" else "已配置")
|
LabelValueCard(label = "访问令牌", value = if (serverConfig.token.isBlank()) "未设置" else "已持久化")
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
Text("数据源", style = MaterialTheme.typography.titleMedium)
|
|
||||||
}
|
|
||||||
|
|
||||||
items(DataSourceMode.entries) { mode ->
|
|
||||||
SelectableRowCard(
|
|
||||||
title = mode.label,
|
|
||||||
trailing = if (mode == currentDataSource) "当前" else null,
|
|
||||||
selected = mode == currentDataSource,
|
|
||||||
modifier = Modifier.clickable { onSelectDataSource(mode) },
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
@@ -95,7 +79,7 @@ fun SettingsScreen(
|
|||||||
|
|
||||||
item {
|
item {
|
||||||
Button(onClick = onDisconnect, modifier = Modifier.fillMaxWidth()) {
|
Button(onClick = onDisconnect, modifier = Modifier.fillMaxWidth()) {
|
||||||
Text("断开连接")
|
Text("退出登录")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ kotlin = "2.3.0"
|
|||||||
material3 = "1.10.0-alpha05"
|
material3 = "1.10.0-alpha05"
|
||||||
ktor = "3.3.0"
|
ktor = "3.3.0"
|
||||||
kotlinxSerializationJson = "1.9.0"
|
kotlinxSerializationJson = "1.9.0"
|
||||||
|
multiplatformSettings = "1.2.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||||
@@ -41,6 +42,7 @@ ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "kto
|
|||||||
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
|
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
|
||||||
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
|
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
|
||||||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
|
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
|
||||||
|
multiplatform-settings-no-arg = { module = "com.russhwolf:multiplatform-settings-no-arg", version.ref = "multiplatformSettings" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
Reference in new issue
Block a user