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
@@ -5,6 +5,18 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.3.17 设置页、侧栏底部服务器栏与追问处理行为(分支 `flutter`)
|
||||||
|
|
||||||
|
| 项 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 设置页 | 新增 `lib/screens/settings_screen.dart`,分「外观 / 聊天 / 宠物」三组 |
|
||||||
|
| 侧栏 | 服务器切换从顶部移到底部:左侧是当前服务器名(点击打开服务器面板),右侧齿轮进入设置页,和原版手机端侧栏一致 |
|
||||||
|
| 外观 | 主题模式(跟随系统 / 浅色 / 深色)与主题色(8 个种子色);`lib/appearance_prefs.dart` 存本机 `shared_preferences`,明确不同步服务端;`main.dart` 的 `ThemeData` 读取它 |
|
||||||
|
| 聊天 | 「追问处理行为」:转向 / 排队。读写服务端 `GET/PUT /api/config/settings?surface=mobile` 的 `followUpBehavior`(profile 级、跨 surface 共享,默认 queue)。运行中短按发送按该设置执行,长按「发送方式」可临时选另一种并标出默认项。连接成功、设置页打开、应用回到前台时重新读取 |
|
||||||
|
| 宠物 | 仅占位,显示「暂未提供设置」 |
|
||||||
|
| 版本 | **0.3.17(code 317)** |
|
||||||
|
---
|
||||||
|
|
||||||
## 0.3.16 输入法收起、模式面板与排队消息(分支 `flutter`)
|
## 0.3.16 输入法收起、模式面板与排队消息(分支 `flutter`)
|
||||||
|
|
||||||
| 项 | 结果 |
|
| 项 | 结果 |
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
|
|||||||
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
||||||
Flutter to compare mobile UI maturity.
|
Flutter to compare mobile UI maturity.
|
||||||
|
|
||||||
Status: 0.3.16 — servers (passwordless / password login, HTTP/HTTPS and
|
Status: 0.3.17 — servers (passwordless / password login, HTTP/HTTPS and
|
||||||
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
SOCKS5/socks5h proxy, self-signed certificates and pinning), session list with search and live
|
||||||
events, chat with streaming Markdown and full history paging, tool steps
|
events, chat with streaming Markdown and full history paging, tool steps
|
||||||
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
grouped per turn (icon, one-line summary, foldable run) with image previews, a
|
||||||
@@ -23,7 +23,10 @@ and opens into two rows on focus, as in dsh-Go: the model and its thinking level
|
|||||||
form one pill, the Build/Plan mode a separate chip (picked from a sheet). A
|
form one pill, the Build/Plan mode a separate chip (picked from a sheet). A
|
||||||
message sent while a turn runs can steer it or queue for its end, and waits as a
|
message sent while a turn runs can steer it or queue for its end, and waits as a
|
||||||
pending bubble that can be withdrawn. The picker groups providers, favourites,
|
pending bubble that can be withdrawn. The picker groups providers, favourites,
|
||||||
recents and context size. A
|
recents and context size. The sidebar footer names the connected server (tap to
|
||||||
|
switch) beside a settings key; settings holds appearance (theme mode and seed
|
||||||
|
colour, device-local), the server's follow-up behavior (steer or queue on a send
|
||||||
|
while a turn runs) and a pet placeholder. A
|
||||||
phone opens the session list as the left drawer and a wide window (tablet,
|
phone opens the session list as the left drawer and a wide window (tablet,
|
||||||
desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop
|
desktop) shows it beside the chat. Android 7.0 (API 24)+, plus a Linux desktop
|
||||||
target used for local testing.
|
target used for local testing.
|
||||||
@@ -34,7 +37,8 @@ target used for local testing.
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `lib/api/` | Dart OpenChamber client: auth, sessions, messages, SSE, models/agents, forms, permissions, prompt/interrupt/fork/revert, `/api/fs/raw`; every request goes through `Transport` (today `DirectTransport`: HTTP/HTTPS proxies via `HttpClient.findProxy`, SOCKS5/socks5h via `socks5_proxy`, pinning/self-signed via `badCertificateCallback`), so a relay tunnel only adds an implementation |
|
| `lib/api/` | Dart OpenChamber client: auth, sessions, messages, SSE, models/agents, forms, permissions, prompt/interrupt/fork/revert, `/api/fs/raw`; every request goes through `Transport` (today `DirectTransport`: HTTP/HTTPS proxies via `HttpClient.findProxy`, SOCKS5/socks5h via `socks5_proxy`, pinning/self-signed via `badCertificateCallback`), so a relay tunnel only adds an implementation |
|
||||||
| `lib/storage.dart` | Saved servers in `shared_preferences`, tokens in `flutter_secure_storage` (Android Keystore) |
|
| `lib/storage.dart` | Saved servers in `shared_preferences`, tokens in `flutter_secure_storage` (Android Keystore) |
|
||||||
| `lib/state.dart` | The app state: connections, live sessions, the open chat, and SSE event folding |
|
| `lib/state.dart` | The app state: connections, live sessions, the open chat, the server's follow-up behavior, and SSE event folding |
|
||||||
|
| `lib/appearance_prefs.dart` | Device-local theme mode and seed colour (`shared_preferences`) |
|
||||||
| `lib/terminal_state.dart` | The terminal session: an xterm model plus the `/api/terminal/ws` socket (binary control frames), kept per workspace so closing the panel keeps the shell |
|
| `lib/terminal_state.dart` | The terminal session: an xterm model plus the `/api/terminal/ws` socket (binary control frames), kept per workspace so closing the panel keeps the shell |
|
||||||
| `lib/screens/` | Servers, the connected shell (`home_screen.dart`: drawer on a phone, two columns from 840 px), sessions, chat (streaming Markdown via `gpt_markdown`, composer, sheets, the native form dock, the files sidebar with the knowledge and terminal tabs); the message list is reversed so older pages grow above without moving the viewport |
|
| `lib/screens/` | Servers, the connected shell (`home_screen.dart`: drawer on a phone, two columns from 840 px), sessions, chat (streaming Markdown via `gpt_markdown`, composer, sheets, the native form dock, the files sidebar with the knowledge and terminal tabs); the message list is reversed so older pages grow above without moving the viewport |
|
||||||
| `lib/widgets/` | The context usage ring |
|
| `lib/widgets/` | The context usage ring |
|
||||||
|
|||||||
@@ -343,6 +343,19 @@ class Client {
|
|||||||
directory: directory, body: {'model': model.toJson()});
|
directory: directory, body: {'model': model.toJson()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The instance settings. `surface` selects a per-surface profile (a phone
|
||||||
|
/// still shares every key that is not marked per-surface).
|
||||||
|
Future<Map<String, dynamic>> settings({String surface = 'mobile'}) async {
|
||||||
|
return _json('GET', '/api/config/settings', query: {'surface': surface});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Persists a partial settings patch and returns the updated settings.
|
||||||
|
Future<Map<String, dynamic>> saveSettings(Map<String, dynamic> patch,
|
||||||
|
{String surface = 'mobile'}) async {
|
||||||
|
return _json('PUT', '/api/config/settings',
|
||||||
|
query: {'surface': surface}, body: patch);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> switchAgent(String sessionId, String agent, {String? directory}) async {
|
Future<void> switchAgent(String sessionId, String agent, {String? directory}) async {
|
||||||
await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/agent',
|
await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/agent',
|
||||||
directory: directory, body: {'agent': agent});
|
directory: directory, body: {'agent': agent});
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// Appearance preferences: theme mode and seed colour. Device-local — the
|
||||||
|
// phone draws its own Material theme, so none of this is sent to the server.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class AppearancePrefs extends ChangeNotifier {
|
||||||
|
AppearancePrefs._();
|
||||||
|
static final AppearancePrefs instance = AppearancePrefs._();
|
||||||
|
|
||||||
|
static const _modeKey = 'appearance.themeMode.v1';
|
||||||
|
static const _seedKey = 'appearance.seedColor.v1';
|
||||||
|
|
||||||
|
/// The first-party client's colour; a fresh install starts here.
|
||||||
|
static const defaultSeed = 0xFF6C5CE7;
|
||||||
|
|
||||||
|
ThemeMode _themeMode = ThemeMode.system;
|
||||||
|
int _seed = defaultSeed;
|
||||||
|
bool _loaded = false;
|
||||||
|
|
||||||
|
ThemeMode get themeMode => _themeMode;
|
||||||
|
Color get seedColor => Color(_seed);
|
||||||
|
|
||||||
|
Future<void> ensureLoaded() async {
|
||||||
|
if (_loaded) return;
|
||||||
|
_loaded = true;
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
_themeMode = switch (prefs.getString(_modeKey)) {
|
||||||
|
'light' => ThemeMode.light,
|
||||||
|
'dark' => ThemeMode.dark,
|
||||||
|
_ => ThemeMode.system,
|
||||||
|
};
|
||||||
|
_seed = prefs.getInt(_seedKey) ?? defaultSeed;
|
||||||
|
notifyListeners();
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setThemeMode(ThemeMode mode) async {
|
||||||
|
if (mode == _themeMode) return;
|
||||||
|
_themeMode = mode;
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setString(_modeKey, mode.name);
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setSeedColor(int value) async {
|
||||||
|
if (value == _seed) return;
|
||||||
|
_seed = value;
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_seedKey, value);
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The colours the appearance section offers; the first is the default.
|
||||||
|
const appearanceSeeds = <int>[
|
||||||
|
0xFF6C5CE7,
|
||||||
|
0xFF2F80ED,
|
||||||
|
0xFF00A884,
|
||||||
|
0xFF0FA3B1,
|
||||||
|
0xFFF2994A,
|
||||||
|
0xFFEB5757,
|
||||||
|
0xFFE84393,
|
||||||
|
0xFF6B7280,
|
||||||
|
];
|
||||||
+7
-3
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'appearance_prefs.dart';
|
||||||
import 'screens/home_screen.dart';
|
import 'screens/home_screen.dart';
|
||||||
import 'screens/servers_screen.dart';
|
import 'screens/servers_screen.dart';
|
||||||
import 'state.dart';
|
import 'state.dart';
|
||||||
@@ -23,6 +24,7 @@ class _OpenChamberAppState extends State<OpenChamberApp>
|
|||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
app.init();
|
app.init();
|
||||||
|
AppearancePrefs.instance.ensureLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -40,24 +42,26 @@ class _OpenChamberAppState extends State<OpenChamberApp>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final look = AppearancePrefs.instance;
|
||||||
return ListenableBuilder(
|
return ListenableBuilder(
|
||||||
listenable: app,
|
listenable: Listenable.merge([app, look]),
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
final home = app.client == null
|
final home = app.client == null
|
||||||
? ServersScreen(app: app)
|
? ServersScreen(app: app)
|
||||||
: HomeScreen(app: app);
|
: HomeScreen(app: app);
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'OpenChamber',
|
title: 'OpenChamber',
|
||||||
|
themeMode: look.themeMode,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
seedColor: const Color(0xFF6C5CE7),
|
seedColor: look.seedColor,
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
),
|
),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
darkTheme: ThemeData(
|
darkTheme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
seedColor: const Color(0xFF6C5CE7),
|
seedColor: look.seedColor,
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
),
|
),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
|||||||
@@ -1621,6 +1621,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
if (!chat.running) return _send();
|
if (!chat.running) return _send();
|
||||||
final text = _draftCtrl.text.trim();
|
final text = _draftCtrl.text.trim();
|
||||||
if (text.isEmpty && _attachments.isEmpty) return;
|
if (text.isEmpty && _attachments.isEmpty) return;
|
||||||
|
// The configured behavior is what a short press does; mark it here too.
|
||||||
|
final fallback = widget.app.followUpBehavior;
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
final picked = await showModalBottomSheet<String>(
|
final picked = await showModalBottomSheet<String>(
|
||||||
context: context,
|
context: context,
|
||||||
showDragHandle: true,
|
showDragHandle: true,
|
||||||
@@ -1639,12 +1642,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
leading: const Icon(Icons.alt_route),
|
leading: const Icon(Icons.alt_route),
|
||||||
title: const Text('转向当前回合'),
|
title: const Text('转向当前回合'),
|
||||||
subtitle: const Text('在下一步加入,工作继续'),
|
subtitle: const Text('在下一步加入,工作继续'),
|
||||||
|
trailing: fallback == 'steer'
|
||||||
|
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||||
|
: null,
|
||||||
onTap: () => Navigator.pop(sheet, 'steer'),
|
onTap: () => Navigator.pop(sheet, 'steer'),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.schedule),
|
leading: const Icon(Icons.schedule),
|
||||||
title: const Text('排队'),
|
title: const Text('排队'),
|
||||||
subtitle: const Text('等本轮结束后发送'),
|
subtitle: const Text('等本轮结束后发送'),
|
||||||
|
trailing: fallback == 'queue'
|
||||||
|
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||||
|
: null,
|
||||||
onTap: () => Navigator.pop(sheet, 'queue'),
|
onTap: () => Navigator.pop(sheet, 'queue'),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
@@ -1659,9 +1668,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
Future<void> _send({String? delivery}) async {
|
Future<void> _send({String? delivery}) async {
|
||||||
final text = _draftCtrl.text.trim();
|
final text = _draftCtrl.text.trim();
|
||||||
if (text.isEmpty && _attachments.isEmpty) return;
|
if (text.isEmpty && _attachments.isEmpty) return;
|
||||||
// An ordinary send while a turn runs joins it, as dsh-Go does; the
|
// A short send while a turn runs uses the configured follow-up behavior;
|
||||||
// long-press sheet can choose to wait instead.
|
// the long-press sheet can choose the other one for this message.
|
||||||
final effective = chat.running ? (delivery ?? 'steer') : null;
|
final effective =
|
||||||
|
chat.running ? (delivery ?? widget.app.followUpBehavior) : null;
|
||||||
// Files ride with the prompt as data URLs.
|
// Files ride with the prompt as data URLs.
|
||||||
final files = <Map<String, String>>[];
|
final files = <Map<String, String>>[];
|
||||||
final images = <String>[];
|
final images = <String>[];
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
|
|||||||
import '../api/models.dart';
|
import '../api/models.dart';
|
||||||
import '../state.dart';
|
import '../state.dart';
|
||||||
import 'servers_screen.dart';
|
import 'servers_screen.dart';
|
||||||
|
import 'settings_screen.dart';
|
||||||
|
|
||||||
/// The session list: a drawer on a phone, a persistent column on a wide
|
/// The session list: a drawer on a phone, a persistent column on a wide
|
||||||
/// layout. Sessions are grouped by project, dated within it, and a row swipes
|
/// layout. Sessions are grouped by project, dated within it, and a row swipes
|
||||||
@@ -69,11 +70,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
padding: const EdgeInsets.fromLTRB(4, 6, 4, 0),
|
padding: const EdgeInsets.fromLTRB(4, 6, 4, 0),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
const SizedBox(width: 12),
|
||||||
icon: const Icon(Icons.dns_outlined),
|
|
||||||
tooltip: '服务器',
|
|
||||||
onPressed: _instancesSheet,
|
|
||||||
),
|
|
||||||
const Expanded(
|
const Expanded(
|
||||||
child: Text('会话',
|
child: Text('会话',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -132,6 +129,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(child: _body(scheme)),
|
Expanded(child: _body(scheme)),
|
||||||
|
_serverFooter(scheme),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -139,6 +137,67 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The bottom bar: the connected server on the left (tap to switch), the
|
||||||
|
/// settings key on the right, as the first-party phone sidebar has it.
|
||||||
|
Widget _serverFooter(ColorScheme scheme) {
|
||||||
|
return DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
top: BorderSide(color: scheme.outlineVariant.withValues(alpha: 0.6)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(8, 4, 4, 4),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
onTap: _instancesSheet,
|
||||||
|
child: Padding(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.dns_outlined,
|
||||||
|
size: 18, color: scheme.onSurfaceVariant),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
_app.connectionName,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
color: scheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.settings_outlined),
|
||||||
|
tooltip: '设置',
|
||||||
|
onPressed: _openSettings,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _openSettings() {
|
||||||
|
// A phone's list is a drawer: close it before the settings page covers
|
||||||
|
// the shell.
|
||||||
|
widget.onOpened?.call();
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (_) => SettingsScreen(app: _app),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Widget _body(ColorScheme scheme) {
|
Widget _body(ColorScheme scheme) {
|
||||||
final app = _app;
|
final app = _app;
|
||||||
if (app.sessionsLoading && app.sessions.isEmpty) {
|
if (app.sessionsLoading && app.sessions.isEmpty) {
|
||||||
|
|||||||
@@ -0,0 +1,221 @@
|
|||||||
|
// Settings. Three groups for now: appearance (device-local theme), chat (the
|
||||||
|
// server's follow-up behavior) and a pet placeholder.
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../appearance_prefs.dart';
|
||||||
|
import '../state.dart';
|
||||||
|
|
||||||
|
class SettingsScreen extends StatefulWidget {
|
||||||
|
final AppState app;
|
||||||
|
const SettingsScreen({super.key, required this.app});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
// Pick up a change made on another client while this page opens.
|
||||||
|
widget.app.refreshFollowUpBehavior();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final look = AppearancePrefs.instance;
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('设置')),
|
||||||
|
body: ListenableBuilder(
|
||||||
|
listenable: Listenable.merge([widget.app, look]),
|
||||||
|
builder: (context, _) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return ListView(
|
||||||
|
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
||||||
|
children: [
|
||||||
|
const _SectionHeader('外观', note: '仅当前设备生效,不同步到服务器'),
|
||||||
|
_appearance(theme, look),
|
||||||
|
const _SectionHeader('聊天'),
|
||||||
|
_chat(theme),
|
||||||
|
const _SectionHeader('宠物'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 4, 20, 8),
|
||||||
|
child: Text('暂未提供设置',
|
||||||
|
style: TextStyle(fontSize: 13, color: theme.hintColor)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------- appearance
|
||||||
|
|
||||||
|
Widget _appearance(ThemeData theme, AppearancePrefs look) {
|
||||||
|
const modes = [
|
||||||
|
(ThemeMode.system, '跟随系统'),
|
||||||
|
(ThemeMode.light, '浅色'),
|
||||||
|
(ThemeMode.dark, '深色'),
|
||||||
|
];
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const _Label('主题模式'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 12),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
for (final (mode, label) in modes)
|
||||||
|
ChoiceChip(
|
||||||
|
label: Text(label),
|
||||||
|
selected: look.themeMode == mode,
|
||||||
|
onSelected: (_) => look.setThemeMode(mode),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const _Label('主题色'),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 12,
|
||||||
|
runSpacing: 12,
|
||||||
|
children: [
|
||||||
|
for (final seed in appearanceSeeds) _swatch(theme, look, seed),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _swatch(ThemeData theme, AppearancePrefs look, int seed) {
|
||||||
|
final color = Color(seed);
|
||||||
|
final selected = look.seedColor.toARGB32() == seed;
|
||||||
|
return Semantics(
|
||||||
|
button: true,
|
||||||
|
selected: selected,
|
||||||
|
label: '主题色 ${seed.toRadixString(16)}',
|
||||||
|
child: InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(22),
|
||||||
|
onTap: () => look.setSeedColor(seed),
|
||||||
|
child: Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: color,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: selected
|
||||||
|
? theme.colorScheme.onSurface
|
||||||
|
: theme.colorScheme.outlineVariant,
|
||||||
|
width: selected ? 2.5 : 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: selected
|
||||||
|
? const Icon(Icons.check, size: 20, color: Colors.white)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------- chat
|
||||||
|
|
||||||
|
Widget _chat(ThemeData theme) {
|
||||||
|
final steer = widget.app.followUpBehavior == 'steer';
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const ListTile(
|
||||||
|
title: Text('追问处理行为'),
|
||||||
|
subtitle: Text('运行中按发送时,消息默认怎么处理。与网页端设置同步。'),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 6),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
ChoiceChip(
|
||||||
|
label: const Text('转向'),
|
||||||
|
selected: steer,
|
||||||
|
onSelected: (_) => _setFollowUp('steer'),
|
||||||
|
),
|
||||||
|
ChoiceChip(
|
||||||
|
label: const Text('排队'),
|
||||||
|
selected: !steer,
|
||||||
|
onSelected: (_) => _setFollowUp('queue'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||||
|
child: Text(
|
||||||
|
steer ? '转向:在下一步加入当前回合,工作继续。' : '排队:等当前回合结束后再发送。',
|
||||||
|
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setFollowUp(String value) async {
|
||||||
|
final ok = await widget.app.setFollowUpBehavior(value);
|
||||||
|
if (!ok && mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(widget.app.lastError ?? '保存失败')),
|
||||||
|
);
|
||||||
|
widget.app.clearLastError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SectionHeader extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final String? note;
|
||||||
|
const _SectionHeader(this.title, {this.note});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 18, 20, 6),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(title,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
)),
|
||||||
|
if (note != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 2),
|
||||||
|
child: Text(note!,
|
||||||
|
style: TextStyle(fontSize: 11.5, color: theme.hintColor)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _Label extends StatelessWidget {
|
||||||
|
final String text;
|
||||||
|
const _Label(this.text);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(20, 2, 20, 6),
|
||||||
|
child: Text(text,
|
||||||
|
style: const TextStyle(fontSize: 13.5, fontWeight: FontWeight.w500)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,6 +94,11 @@ class AppState extends ChangeNotifier {
|
|||||||
|
|
||||||
ChatState? chat;
|
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
|
/// Projects the server knows, for the new-session picker and the sidebar's
|
||||||
/// group headers.
|
/// group headers.
|
||||||
List<ProjectInfo> projects = [];
|
List<ProjectInfo> projects = [];
|
||||||
@@ -125,6 +130,57 @@ class AppState extends ChangeNotifier {
|
|||||||
/// Public way to signal UI changes (notifyListeners is protected).
|
/// Public way to signal UI changes (notifyListeners is protected).
|
||||||
void touch() => notifyListeners();
|
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 {
|
Future<void> init() async {
|
||||||
connections = await storage.connections();
|
connections = await storage.connections();
|
||||||
if (connections.isNotEmpty) {
|
if (connections.isNotEmpty) {
|
||||||
@@ -230,6 +286,7 @@ class AppState extends ChangeNotifier {
|
|||||||
refreshActive();
|
refreshActive();
|
||||||
refreshPerms();
|
refreshPerms();
|
||||||
refreshModels();
|
refreshModels();
|
||||||
|
refreshFollowUpBehavior();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,6 +749,7 @@ class AppState extends ChangeNotifier {
|
|||||||
Future<void> onResumed() async {
|
Future<void> onResumed() async {
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
_startStream();
|
_startStream();
|
||||||
|
refreshFollowUpBehavior();
|
||||||
await refreshSessions();
|
await refreshSessions();
|
||||||
if (chat != null) {
|
if (chat != null) {
|
||||||
await chat!.reloadTail();
|
await chat!.reloadTail();
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
|||||||
description: "A lightweight OpenChamber client for phones."
|
description: "A lightweight OpenChamber client for phones."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.3.16+316
|
version: 0.3.17+317
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.14.0
|
sdk: ^3.14.0
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:openchamber/state.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('follow-up behavior reads as the first-party default when unknown', () {
|
||||||
|
expect(AppState.normalizeFollowUp('steer'), 'steer');
|
||||||
|
// The removed "immediate" mode was wire-identical to steer.
|
||||||
|
expect(AppState.normalizeFollowUp('immediate'), 'steer');
|
||||||
|
expect(AppState.normalizeFollowUp('queue'), 'queue');
|
||||||
|
expect(AppState.normalizeFollowUp(null), 'queue');
|
||||||
|
expect(AppState.normalizeFollowUp('bogus'), 'queue');
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:openchamber/screens/settings_screen.dart';
|
||||||
|
import 'package:openchamber/state.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('settings shows appearance, chat and the pet placeholder',
|
||||||
|
(tester) async {
|
||||||
|
final app = AppState();
|
||||||
|
addTearDown(app.dispose);
|
||||||
|
|
||||||
|
await tester.pumpWidget(MaterialApp(home: SettingsScreen(app: app)));
|
||||||
|
|
||||||
|
expect(find.text('外观'), findsOneWidget);
|
||||||
|
expect(find.text('聊天'), findsOneWidget);
|
||||||
|
expect(find.text('宠物'), findsOneWidget);
|
||||||
|
expect(find.text('主题模式'), findsOneWidget);
|
||||||
|
expect(find.text('主题色'), findsOneWidget);
|
||||||
|
expect(find.text('追问处理行为'), findsOneWidget);
|
||||||
|
expect(find.text('暂未提供设置'), findsOneWidget);
|
||||||
|
|
||||||
|
// The choice is the server-backed follow-up behavior.
|
||||||
|
ChoiceChip chip(String label) =>
|
||||||
|
tester.widget<ChoiceChip>(find.widgetWithText(ChoiceChip, label));
|
||||||
|
expect(chip('排队').selected, isTrue);
|
||||||
|
|
||||||
|
await tester.tap(find.text('转向'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(app.followUpBehavior, 'steer');
|
||||||
|
expect(chip('转向').selected, isTrue);
|
||||||
|
expect(chip('排队').selected, isFalse);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:openchamber/screens/sessions_screen.dart';
|
||||||
|
import 'package:openchamber/state.dart';
|
||||||
|
import 'package:openchamber/storage.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('the sidebar footer names the server and opens settings',
|
||||||
|
(tester) async {
|
||||||
|
final app = AppState();
|
||||||
|
app.conn = Connection(
|
||||||
|
id: 'c1',
|
||||||
|
label: '家里的服务器',
|
||||||
|
url: 'http://127.0.0.1:3000',
|
||||||
|
);
|
||||||
|
addTearDown(app.dispose);
|
||||||
|
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
home: Scaffold(body: SessionListPane(app: app)),
|
||||||
|
));
|
||||||
|
|
||||||
|
expect(find.text('家里的服务器'), findsOneWidget);
|
||||||
|
expect(find.byIcon(Icons.dns_outlined), findsOneWidget);
|
||||||
|
expect(find.byTooltip('设置'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byTooltip('设置'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
// The settings page replaced the shell.
|
||||||
|
expect(find.text('外观'), findsOneWidget);
|
||||||
|
expect(find.text('聊天'), findsOneWidget);
|
||||||
|
expect(find.text('宠物'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user