feat: split settings into category pages and add an about page
- the settings screen is now an index: 通用 → 聊天, 外观 → 主题 / 宠物, 帮助与关于 → 关于; each row opens its own page, the controls moved there unchanged - 关于 shows the app version, the server's OpenCode (/api/info) and OpenChamber (/api/version) versions with a refresh, and the open-source licenses, listed per package with their full text on tap - the app version is read from the platform at startup (package_info_plus), so pubspec.yaml is the only place it is written; the pairing/relay handshake now sends it too instead of a constant that had drifted
This commit is contained in:
1 parent
00564fe94b
commit
2185054aab
11 files changed
+736
-192
No files matched your search
@@ -5,6 +5,19 @@
|
||||
|
||||
---
|
||||
|
||||
## 0.4.17 设置按分组拆页,新增「关于」(分支 `flutter`)
|
||||
|
||||
| 项 | 结果 |
|
||||
| --- | --- |
|
||||
| 分组 | 设置页改成索引,对齐 dsh-Go 的组织方式:【通用】聊天;【外观】主题、宠物;【帮助与关于】关于。每行带图标、一句说明与右箭头,点开是独立子页;原来的全部控件搬进各自子页,索引里只留入口 |
|
||||
| 版本 | 应用版本改为运行时从平台读取(`package_info_plus` 的 `version`;不含 Android build 号,因为 ABI 拆分会给它加一位、四个 APK 各不相同),`pubspec.yaml` 成为唯一出处;配对/relay 握手里的 `appVersion` 也用它,不再有写死的常量(之前还停在 0.4.14) |
|
||||
| 关于 | 新增「关于」子页:应用图标与名称、版本号、开源许可入口、服务端 OpenCode 版本(`/api/info`)与 OpenChamber 版本(`/api/version`),右上角可重新获取;开源许可按包列出,点开看完整许可证文本(自绘中文页,不用英文的 `LicensePage`);未连接或取不到时明确写「未连接」「未获取到」 |
|
||||
| 测试 | `test/settings_screen_test.dart` 重写:索引分组、聊天/主题/宠物/关于四个子页、版本与许可入口;87 项全过 |
|
||||
| 验证 | 模拟器:设置索引三个分组四行;主题页模式/主题色可用;宠物页显示已导入的「Deepy 小鲸鱼」、启用开关与大小;关于页版本「0.4.17」、OpenCode「2.4.0」、OpenChamber「2.8.0」(取自当前服务器),许可页按包列出、点开显示完整许可证文本 |
|
||||
| 版本 | **0.4.17(code 417)** |
|
||||
|
||||
---
|
||||
|
||||
## 0.4.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
|
||||
Flutter to compare mobile UI maturity.
|
||||
|
||||
Status: 0.4.16 — servers (passwordless / password login, HTTP/HTTPS and
|
||||
Status: 0.4.17 — servers (passwordless / password login, HTTP/HTTPS and
|
||||
SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link
|
||||
over the OpenChamber private relay with end-to-end encryption; the pairing
|
||||
link is pasted or scanned with the camera), session list with search and live
|
||||
|
||||
@@ -122,6 +122,24 @@ class Client {
|
||||
return Session.fromJson(r['data'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
/// The versions behind the server. Each endpoint is optional: an older
|
||||
/// server answers neither, and the about page then says it could not tell.
|
||||
Future<ServerVersions> serverVersions() async {
|
||||
var opencode = '';
|
||||
var openchamber = '';
|
||||
try {
|
||||
final info = await _json('GET', '/api/info');
|
||||
final v = info['version'];
|
||||
if (v is String) opencode = v;
|
||||
} catch (_) {}
|
||||
try {
|
||||
final version = await _json('GET', '/api/version');
|
||||
final v = version['openchamberVersion'];
|
||||
if (v is String) openchamber = v;
|
||||
} catch (_) {}
|
||||
return ServerVersions(opencode: opencode, openchamber: openchamber);
|
||||
}
|
||||
|
||||
Future<Set<String>> activeSessions() async {
|
||||
final r = await _json('GET', '/api/session/active');
|
||||
final data = r['data'] as Map<String, dynamic>? ?? {};
|
||||
|
||||
@@ -1093,3 +1093,12 @@ List<String> generatedImagePaths(ContentPart part) {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// What the server says it runs: OpenCode itself (`/api/info`) and the
|
||||
/// OpenChamber web layer in front of it (`/api/version`). Either may be
|
||||
/// empty on older servers.
|
||||
class ServerVersions {
|
||||
final String opencode;
|
||||
final String openchamber;
|
||||
const ServerVersions({this.opencode = '', this.openchamber = ''});
|
||||
}
|
||||
@@ -19,13 +19,15 @@ class RelayTransport implements Transport {
|
||||
required String serverId,
|
||||
required Map<String, dynamic> hostKey,
|
||||
String? grant,
|
||||
String version = appVersion,
|
||||
String? version,
|
||||
}) : _tunnel = RelayTunnel(
|
||||
relayUrl: relayUrl,
|
||||
serverId: serverId,
|
||||
hostKey: hostKey,
|
||||
grant: grant,
|
||||
appVersion: version,
|
||||
// Read at construction: the version is known once the app has
|
||||
// started, which is after this default would have been fixed.
|
||||
appVersion: version ?? appVersion,
|
||||
);
|
||||
|
||||
@override
|
||||
|
||||
+6
-1
@@ -5,8 +5,13 @@ import 'pets/pet_library.dart';
|
||||
import 'screens/home_screen.dart';
|
||||
import 'screens/servers_screen.dart';
|
||||
import 'state.dart';
|
||||
import 'version.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// The version goes into every connection's handshake; read it once here so
|
||||
// nothing waits for it later.
|
||||
await loadAppVersion();
|
||||
runApp(const OpenChamberApp());
|
||||
}
|
||||
|
||||
|
||||
+580
-176
@@ -1,49 +1,128 @@
|
||||
// Settings. Three groups for now: appearance (device-local theme), chat (the
|
||||
// server's follow-up behavior) and a pet placeholder.
|
||||
// Settings, organised like the desktop client: a short index of categories,
|
||||
// each opening its own page. 通用 holds the server-backed chat behavior, 外观
|
||||
// the device-local theme and pet, 帮助与关于 the app itself.
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart'
|
||||
show LicenseEntry, LicenseParagraph, LicenseRegistry;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/models.dart';
|
||||
import '../appearance_prefs.dart';
|
||||
import '../pets/pet_library.dart';
|
||||
import '../pets/pet_pack.dart';
|
||||
import '../state.dart';
|
||||
import '../version.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
final AppState app;
|
||||
const SettingsScreen({super.key, required this.app});
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
||||
children: [
|
||||
const _SectionHeader('通用'),
|
||||
_Section(children: [
|
||||
_NavTile(
|
||||
icon: Icons.chat_bubble_outline,
|
||||
title: '聊天',
|
||||
subtitle: '追问处理行为',
|
||||
builder: (_) => ChatSettingsPage(app: app),
|
||||
),
|
||||
]),
|
||||
const _SectionHeader('外观', note: '仅当前设备生效,不同步到服务器'),
|
||||
_Section(children: [
|
||||
_NavTile(
|
||||
icon: Icons.palette_outlined,
|
||||
title: '主题',
|
||||
subtitle: '主题模式与主题色',
|
||||
builder: (_) => const ThemeSettingsPage(),
|
||||
),
|
||||
_NavTile(
|
||||
icon: Icons.pets_outlined,
|
||||
title: '宠物',
|
||||
subtitle: '导入、启用与大小',
|
||||
builder: (_) => const PetSettingsPage(),
|
||||
),
|
||||
]),
|
||||
const _SectionHeader('帮助与关于'),
|
||||
_Section(children: [
|
||||
_NavTile(
|
||||
icon: Icons.info_outline,
|
||||
title: '关于',
|
||||
subtitle: '版本、服务端与开源许可',
|
||||
builder: (_) => AboutSettingsPage(app: app),
|
||||
),
|
||||
]),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
// ------------------------------------------------------------------- chat
|
||||
|
||||
class ChatSettingsPage extends StatefulWidget {
|
||||
final AppState app;
|
||||
const ChatSettingsPage({super.key, required this.app});
|
||||
|
||||
@override
|
||||
State<ChatSettingsPage> createState() => _ChatSettingsPageState();
|
||||
}
|
||||
|
||||
class _ChatSettingsPageState extends State<ChatSettingsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Pick up a change made on another client while this page opens.
|
||||
widget.app.refreshFollowUpBehavior();
|
||||
PetLibrary.instance.ensureLoaded();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final look = AppearancePrefs.instance;
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('设置')),
|
||||
appBar: AppBar(title: const Text('聊天')),
|
||||
body: ListenableBuilder(
|
||||
listenable: Listenable.merge(
|
||||
[widget.app, look, PetLibrary.instance]),
|
||||
listenable: widget.app,
|
||||
builder: (context, _) {
|
||||
final theme = Theme.of(context);
|
||||
final steer = widget.app.followUpBehavior == 'steer';
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 4, bottom: 32),
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
const _SectionHeader('外观', note: '仅当前设备生效,不同步到服务器'),
|
||||
_appearance(theme, look),
|
||||
const _SectionHeader('聊天'),
|
||||
_chat(theme),
|
||||
const _SectionHeader('宠物',
|
||||
note: '默认不提供;宠物包只存放在本机'),
|
||||
_pet(theme),
|
||||
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),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -51,45 +130,77 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- appearance
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
// ------------------------------------------------------------------ theme
|
||||
|
||||
class ThemeSettingsPage extends StatelessWidget {
|
||||
const ThemeSettingsPage({super.key});
|
||||
|
||||
static const _modes = [
|
||||
(ThemeMode.system, '跟随系统'),
|
||||
(ThemeMode.light, '浅色'),
|
||||
(ThemeMode.dark, '深色'),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final look = AppearancePrefs.instance;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('主题')),
|
||||
body: ListenableBuilder(
|
||||
listenable: look,
|
||||
builder: (context, _) {
|
||||
final theme = Theme.of(context);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
for (final (mode, label) in modes)
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
selected: look.themeMode == mode,
|
||||
onSelected: (_) => look.setThemeMode(mode),
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text('主题只保存在本机,不随服务器同步。',
|
||||
style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,138 +234,119 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- chat
|
||||
// -------------------------------------------------------------------- pet
|
||||
|
||||
Widget _chat(ThemeData theme) {
|
||||
final steer = widget.app.followUpBehavior == 'steer';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
class PetSettingsPage extends StatefulWidget {
|
||||
const PetSettingsPage({super.key});
|
||||
|
||||
@override
|
||||
State<PetSettingsPage> createState() => _PetSettingsPageState();
|
||||
}
|
||||
|
||||
class _PetSettingsPageState extends State<PetSettingsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
PetLibrary.instance.ensureLoaded();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('宠物')),
|
||||
body: ListenableBuilder(
|
||||
listenable: PetLibrary.instance,
|
||||
builder: (context, _) {
|
||||
final library = PetLibrary.instance;
|
||||
final pack = library.pack;
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text('默认不提供宠物;宠物包只存放在本机。',
|
||||
style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
if (pack == null) ..._empty(theme) else ..._loaded(theme, pack),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _empty(ThemeData theme) => [
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text('尚未导入宠物'),
|
||||
subtitle: Text('导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Text(
|
||||
steer ? '转向:在下一步加入当前回合,工作继续。' : '排队:等当前回合结束后再发送。',
|
||||
style: TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.file_upload_outlined, size: 18),
|
||||
label: const Text('导入宠物包'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
];
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- pet
|
||||
|
||||
Widget _pet(ThemeData theme) {
|
||||
List<Widget> _loaded(ThemeData theme, PetPack pack) {
|
||||
final library = PetLibrary.instance;
|
||||
final pack = library.pack;
|
||||
if (pack == null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const ListTile(
|
||||
title: Text('尚未导入宠物'),
|
||||
subtitle: Text('默认不提供宠物。导入一个宠物包(.zip)后,它会站在输入框上方。'),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: FilledButton.tonalIcon(
|
||||
final info =
|
||||
[pack.author, pack.license].where((s) => s.trim().isNotEmpty).join(' · ');
|
||||
return [
|
||||
ListTile(
|
||||
title: Text(pack.name.isEmpty ? pack.id : pack.name),
|
||||
subtitle: info.isEmpty
|
||||
? null
|
||||
: Text(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('启用宠物'),
|
||||
subtitle: const Text('站在输入框上方,默认关闭'),
|
||||
value: library.enabled,
|
||||
onChanged: (v) => library.setEnabled(v),
|
||||
),
|
||||
const _Label('大小'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (final (size, label) in const [
|
||||
(40.0, '小'),
|
||||
(52.0, '中'),
|
||||
(64.0, '大'),
|
||||
])
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
selected: (library.size - size).abs() < 0.5,
|
||||
onSelected: (_) => library.setSize(size),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 2, 20, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.file_upload_outlined, size: 18),
|
||||
label: const Text('导入宠物包'),
|
||||
icon: const Icon(Icons.swap_horiz, size: 18),
|
||||
label: const Text('更换宠物包'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
final info = [pack.author, pack.license]
|
||||
.where((s) => s.trim().isNotEmpty)
|
||||
.join(' · ');
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(pack.name.isEmpty ? pack.id : pack.name),
|
||||
subtitle: info.isEmpty
|
||||
? null
|
||||
: Text(info, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: _confirmRemovePet,
|
||||
child: const Text('移除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('启用宠物'),
|
||||
subtitle: const Text('站在输入框上方,默认关闭'),
|
||||
value: library.enabled,
|
||||
onChanged: (v) => library.setEnabled(v),
|
||||
),
|
||||
const _Label('大小'),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
for (final (size, label) in const [
|
||||
(40.0, '小'),
|
||||
(52.0, '中'),
|
||||
(64.0, '大'),
|
||||
])
|
||||
ChoiceChip(
|
||||
label: Text(label),
|
||||
selected: (library.size - size).abs() < 0.5,
|
||||
onSelected: (_) => library.setSize(size),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 2, 20, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: _importPet,
|
||||
icon: const Icon(Icons.swap_horiz, size: 18),
|
||||
label: const Text('更换宠物包'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
onPressed: _confirmRemovePet,
|
||||
child: const Text('移除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Future<void> _importPet() async {
|
||||
@@ -269,9 +361,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final pack = await PetLibrary.instance.importZip(bytes);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text('已导入 ${pack.name.isEmpty ? pack.id : pack.name}')),
|
||||
SnackBar(content: Text('已导入 ${pack.name.isEmpty ? pack.id : pack.name}')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
@@ -301,6 +391,320 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ about
|
||||
|
||||
class AboutSettingsPage extends StatefulWidget {
|
||||
final AppState app;
|
||||
const AboutSettingsPage({super.key, required this.app});
|
||||
|
||||
@override
|
||||
State<AboutSettingsPage> createState() => _AboutSettingsPageState();
|
||||
}
|
||||
|
||||
class _AboutSettingsPageState extends State<AboutSettingsPage> {
|
||||
ServerVersions? _versions;
|
||||
bool _loading = false;
|
||||
bool _loaded = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final client = widget.app.client;
|
||||
if (client == null) {
|
||||
setState(() => _loaded = true);
|
||||
return;
|
||||
}
|
||||
setState(() => _loading = true);
|
||||
final versions = await client.serverVersions();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_versions = versions;
|
||||
_loading = false;
|
||||
_loaded = true;
|
||||
});
|
||||
}
|
||||
|
||||
/// What a version row shows: a spinner while fetching, then the value, or
|
||||
/// why there is none.
|
||||
Widget _version(BuildContext context, String value) {
|
||||
final theme = Theme.of(context);
|
||||
if (_loading) {
|
||||
return const SizedBox(
|
||||
width: 14, height: 14, child: CircularProgressIndicator(strokeWidth: 1.6));
|
||||
}
|
||||
final text = !_loaded
|
||||
? '读取中…'
|
||||
: widget.app.client == null
|
||||
? '未连接'
|
||||
: value.isEmpty
|
||||
? '未获取到'
|
||||
: value;
|
||||
return Text(text,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: text == value && value.isNotEmpty
|
||||
? theme.colorScheme.onSurface
|
||||
: theme.hintColor));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final versions = _versions;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('关于'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: '重新获取服务端版本',
|
||||
onPressed: _loading ? null : _load,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Icon(Icons.forum_rounded,
|
||||
size: 28, color: theme.colorScheme.onPrimaryContainer),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('OpenChamber',
|
||||
style: theme.textTheme.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.w600)),
|
||||
Text('手机客户端',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5, color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const _SectionHeader('应用'),
|
||||
_Section(children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.tag, size: 20),
|
||||
title: const Text('版本'),
|
||||
trailing: Text(
|
||||
appVersion.isEmpty ? '未知' : appVersion,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.description_outlined, size: 20),
|
||||
title: const Text('开源许可'),
|
||||
subtitle: const Text('本应用使用的第三方组件与它们的许可证'),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => const LicensesPage(),
|
||||
)),
|
||||
),
|
||||
]),
|
||||
const _SectionHeader('服务端', note: '版本取自当前连接的服务器'),
|
||||
_Section(children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.terminal, size: 20),
|
||||
title: const Text('OpenCode'),
|
||||
trailing: _version(context, versions?.opencode ?? ''),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.hub_outlined, size: 20),
|
||||
title: const Text('OpenChamber'),
|
||||
trailing: _version(context, versions?.openchamber ?? ''),
|
||||
),
|
||||
]),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LicensesPage extends StatefulWidget {
|
||||
const LicensesPage({super.key});
|
||||
|
||||
@override
|
||||
State<LicensesPage> createState() => _LicensesPageState();
|
||||
}
|
||||
|
||||
class _LicensesPageState extends State<LicensesPage> {
|
||||
Map<String, String>? _licenses;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_collect();
|
||||
}
|
||||
|
||||
/// One entry per package, the license text appended in the order Flutter
|
||||
/// reports the notices.
|
||||
Future<void> _collect() async {
|
||||
final texts = <String, StringBuffer>{};
|
||||
await for (final entry in LicenseRegistry.licenses) {
|
||||
for (final package in entry.packages) {
|
||||
texts.putIfAbsent(package, () => StringBuffer()).write(_text(entry));
|
||||
}
|
||||
}
|
||||
final names = texts.keys.toList()
|
||||
..sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_licenses = {
|
||||
for (final name in names) name: texts[name].toString().trim(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final licenses = _licenses;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('开源许可')),
|
||||
body: licenses == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
itemCount: licenses.length + 1,
|
||||
separatorBuilder: (_, __) =>
|
||||
const Divider(height: 1, indent: 20, endIndent: 20),
|
||||
itemBuilder: (context, i) {
|
||||
if (i == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 20, 14),
|
||||
child: Text(
|
||||
'下面列出随本应用打包的第三方组件;点开可阅读完整许可证。',
|
||||
style:
|
||||
TextStyle(fontSize: 12.5, color: theme.hintColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
final name = licenses.keys.elementAt(i - 1);
|
||||
return ListTile(
|
||||
title: Text(name),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (_) => _LicenseTextPage(
|
||||
name: name, text: licenses[name] ?? ''),
|
||||
)),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A license's paragraphs as one text, indented the way the license itself
|
||||
/// asks (a centered paragraph is only trimmed).
|
||||
String _text(LicenseEntry entry) {
|
||||
final buffer = StringBuffer();
|
||||
for (final paragraph in entry.paragraphs) {
|
||||
if (buffer.isNotEmpty) buffer.write('\n\n');
|
||||
final body = paragraph.text.trimRight();
|
||||
if (paragraph.indent == LicenseParagraph.centeredIndent) {
|
||||
buffer.write(body.trim());
|
||||
} else {
|
||||
buffer.write('${' ' * (paragraph.indent < 0 ? 0 : paragraph.indent)}$body');
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
class _LicenseTextPage extends StatelessWidget {
|
||||
final String name;
|
||||
final String text;
|
||||
const _LicenseTextPage({required this.name, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(name)),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: SelectableText(
|
||||
text.isEmpty ? '该组件没有附带许可证文本。' : text,
|
||||
style: const TextStyle(fontSize: 12, fontFamily: 'monospace', height: 1.45),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- chrome
|
||||
|
||||
class _Section extends StatelessWidget {
|
||||
/// Rows of one category in a rounded block, separated by hairlines that
|
||||
/// start at the text, the way the session list draws its groups.
|
||||
final List<Widget> children;
|
||||
const _Section({required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Material(
|
||||
color: theme.colorScheme.surfaceContainerHighest.withValues(alpha: 0.45),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
children: [
|
||||
for (var i = 0; i < children.length; i++) ...[
|
||||
if (i > 0) const Divider(height: 1, indent: 56),
|
||||
children[i],
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NavTile extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final WidgetBuilder builder;
|
||||
|
||||
const _NavTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, size: 22),
|
||||
title: Text(title),
|
||||
subtitle: Text(subtitle),
|
||||
trailing: const Icon(Icons.chevron_right, size: 20),
|
||||
onTap: () => Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: builder)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
final String title;
|
||||
final String? note;
|
||||
|
||||
+22
-2
@@ -1,2 +1,22 @@
|
||||
/// The app version sent to the server in pairing and relay handshakes.
|
||||
const appVersion = '0.4.14';
|
||||
// The build's version: shown in 设置 → 关于 and sent to the server in pairing
|
||||
// and relay handshakes. Read from the platform at startup, so pubspec.yaml
|
||||
// stays the only place the number is written.
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
/// The version this build was made from, empty until [loadAppVersion] has
|
||||
/// read it. The Android build number is left out on purpose: an ABI split
|
||||
/// prefixes it with its own digit, so it would differ between the APKs of one
|
||||
/// release.
|
||||
String appVersion = '';
|
||||
|
||||
/// Reads the version this build was made from. Failure leaves [appVersion]
|
||||
/// empty: the handshake still works and 关于 says the version is unknown.
|
||||
Future<void> loadAppVersion() async {
|
||||
try {
|
||||
final info =
|
||||
await PackageInfo.fromPlatform().timeout(const Duration(seconds: 3));
|
||||
appVersion = info.version.trim();
|
||||
} catch (_) {
|
||||
// Keep the empty fallback.
|
||||
}
|
||||
}
|
||||
@@ -525,6 +525,22 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
package_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: package_info_plus
|
||||
sha256: "73ef2cd5c11a7548f9b7f6fc2a4f6113de2e64aa2a70de63feede95548822908"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "10.2.2"
|
||||
package_info_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_info_plus_platform_interface
|
||||
sha256: db762cb2f4f25ee60fb6359773861b0f199e00b90d237bd85a76a1e806b46ef4
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+2
-1
@@ -2,7 +2,7 @@ name: openchamber
|
||||
description: "A lightweight OpenChamber client for phones."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.4.16+416
|
||||
version: 0.4.17+417
|
||||
|
||||
environment:
|
||||
sdk: ^3.14.0
|
||||
@@ -23,6 +23,7 @@ dependencies:
|
||||
camera: ^0.12.2
|
||||
zxing2: ^0.2.4
|
||||
flutter_svg: ^2.5.0
|
||||
package_info_plus: ^10.2.2
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
@@ -4,23 +4,37 @@ 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 {
|
||||
Future<AppState> pumpSettings(WidgetTester tester) async {
|
||||
final app = AppState();
|
||||
addTearDown(app.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(home: SettingsScreen(app: app)));
|
||||
return app;
|
||||
}
|
||||
|
||||
testWidgets('settings is an index of categories, not one long page',
|
||||
(tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
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);
|
||||
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.
|
||||
// The category pages keep their controls off the index.
|
||||
expect(find.text('主题模式'), findsNothing);
|
||||
expect(find.byType(Switch), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('聊天 opens the follow-up behavior page', (tester) async {
|
||||
final app = await pumpSettings(tester);
|
||||
|
||||
await tester.tap(find.text('聊天'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('追问处理行为'), findsOneWidget);
|
||||
ChoiceChip chip(String label) =>
|
||||
tester.widget<ChoiceChip>(find.widgetWithText(ChoiceChip, label));
|
||||
expect(chip('排队').selected, isTrue);
|
||||
@@ -31,4 +45,46 @@ void main() {
|
||||
expect(chip('转向').selected, isTrue);
|
||||
expect(chip('排队').selected, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('主题 opens the theme page', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
await tester.tap(find.text('主题'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('主题模式'), findsOneWidget);
|
||||
expect(find.text('主题色'), findsOneWidget);
|
||||
expect(find.text('跟随系统'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('宠物 opens the pet page', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
await tester.tap(find.text('宠物'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('尚未导入宠物'), findsOneWidget);
|
||||
expect(find.text('导入宠物包'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('关于 shows the app version, the server versions and licenses',
|
||||
(tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
await tester.tap(find.text('关于'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('版本'), findsOneWidget);
|
||||
expect(find.text('未知'), findsOneWidget); // no platform version in a test
|
||||
expect(find.text('开源许可'), findsOneWidget);
|
||||
expect(find.widgetWithText(ListTile, 'OpenCode'), findsOneWidget);
|
||||
// The header carries the name too, so look for the server row itself.
|
||||
expect(find.widgetWithText(ListTile, 'OpenChamber'), findsOneWidget);
|
||||
// No client: both server rows say so instead of showing a dash.
|
||||
expect(find.text('未连接'), findsNWidgets(2));
|
||||
|
||||
await tester.tap(find.text('开源许可'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('第三方组件'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user