feat: a settings page, a server footer in the sidebar, and follow-up behaviour
- The sidebar's server switch moves to a footer bar: the connected server's name on the left (tap for the server sheet) and a settings key on the right, matching the first-party phone layout. - Settings has three groups: 外观 (theme mode and seed colour, stored on the device only in shared_preferences), 聊天 (the server's followUpBehavior: steer or queue) and a 宠物 placeholder. The app theme now reads the seed and mode. - The chat's short send while a turn runs uses the configured follow-up behaviour; the long-press sheet offers both and marks the default. The value is read from GET /api/config/settings?surface=mobile on connect, on resume and when the page opens, and written back with PUT. - Tests: settings page groups and choice, sidebar footer naming the server and opening settings, follow-up normalization. - 0.3.17 (317).
This commit is contained in:
1 parent
1aa84a53e5
commit
e646130d1f
13 files changed
+544
-15
No files matched your search
@@ -94,6 +94,11 @@ class AppState extends ChangeNotifier {
|
||||
|
||||
ChatState? chat;
|
||||
|
||||
/// What a send does while a turn runs: 'steer' (join it at the next step) or
|
||||
/// 'queue' (wait for it to end). Server-backed (`followUpBehavior`), shared
|
||||
/// with the web UI; 'queue' is the first-party default.
|
||||
String followUpBehavior = 'queue';
|
||||
|
||||
/// Projects the server knows, for the new-session picker and the sidebar's
|
||||
/// group headers.
|
||||
List<ProjectInfo> projects = [];
|
||||
@@ -125,6 +130,57 @@ class AppState extends ChangeNotifier {
|
||||
/// Public way to signal UI changes (notifyListeners is protected).
|
||||
void touch() => notifyListeners();
|
||||
|
||||
/// The name of the connected server, for the sidebar footer.
|
||||
String get connectionName {
|
||||
final c = conn;
|
||||
if (c == null) return '未连接';
|
||||
final label = c.label.trim();
|
||||
if (label.isNotEmpty) return label;
|
||||
final host = Uri.tryParse(c.url)?.host ?? '';
|
||||
return host.isNotEmpty ? host : c.url;
|
||||
}
|
||||
|
||||
/// The server's follow-up behavior; an absent or unknown value reads as the
|
||||
/// first-party default, 'queue'.
|
||||
static String normalizeFollowUp(Object? value) {
|
||||
if (value == 'steer' || value == 'immediate') return 'steer';
|
||||
return 'queue';
|
||||
}
|
||||
|
||||
Future<void> refreshFollowUpBehavior() async {
|
||||
final cl = client;
|
||||
if (cl == null) return;
|
||||
try {
|
||||
final settings = await cl.settings();
|
||||
if (client != cl) return;
|
||||
followUpBehavior = normalizeFollowUp(settings['followUpBehavior']);
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// Saves the choice to the server and keeps it locally; a failed save puts
|
||||
/// the previous value back.
|
||||
Future<bool> setFollowUpBehavior(String value) async {
|
||||
final next = value == 'steer' ? 'steer' : 'queue';
|
||||
final before = followUpBehavior;
|
||||
if (next == before) return true;
|
||||
followUpBehavior = next;
|
||||
notifyListeners();
|
||||
final cl = client;
|
||||
if (cl == null) return true;
|
||||
try {
|
||||
await cl.saveSettings({'followUpBehavior': next});
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (client == cl) {
|
||||
followUpBehavior = before;
|
||||
_lastError = '保存失败:$e';
|
||||
notifyListeners();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
connections = await storage.connections();
|
||||
if (connections.isNotEmpty) {
|
||||
@@ -230,6 +286,7 @@ class AppState extends ChangeNotifier {
|
||||
refreshActive();
|
||||
refreshPerms();
|
||||
refreshModels();
|
||||
refreshFollowUpBehavior();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -692,6 +749,7 @@ class AppState extends ChangeNotifier {
|
||||
Future<void> onResumed() async {
|
||||
if (client == null) return;
|
||||
_startStream();
|
||||
refreshFollowUpBehavior();
|
||||
await refreshSessions();
|
||||
if (chat != null) {
|
||||
await chat!.reloadTail();
|
||||
|
||||
Reference in new issue
Block a user