From ba3c8201866594bf4c75b73335876c4dd30c614a Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Fri, 27 Nov 2026 17:44:36 +0800 Subject: [PATCH] feat: the files panel uses the server's gitignored setting - OpenChamber keeps filesViewShowGitignored in its profile settings (the web UI's "Display gitignored files"); the client now reads it in refreshChatSettings instead of starting from a local false, so a server that shows ignored files shows them here too - toggling "Show git-ignored files" writes the same key back through PUT /api/config/settings (surface=mobile) and reloads the listing; a failed save restores the previous value and reports the error - while the panel is open, a change to the setting from another client reloads the list with the new filter - version 0.6.3+603; tests cover reading, writing and rollback --- PLAN.md | 11 ++++ README.md | 2 +- lib/screens/files_panel.dart | 26 ++++++--- lib/state.dart | 33 ++++++++++++ pubspec.yaml | 2 +- test/gitignored_setting_test.dart | 89 +++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 test/gitignored_setting_test.dart diff --git a/PLAN.md b/PLAN.md index 03667a6..d5d1175 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,6 +5,17 @@ --- +## 0.6.3 文件侧栏的 gitignore 开关改用服务端值(分支 `flutter`) + +| 项 | 结果 | +| --- | --- | +| 服务端存储 | OpenChamber 的设置文档里有 `filesViewShowGitignored`(profile scope,网页端也用它),没有该键时默认不显示被 git 忽略的文件。客户端现在从 `/api/config/settings` 读取它,不再写死本地默认值 | +| 切换 | 文件侧栏的【显示被 git 忽略的文件】勾选/取消勾选后立即刷新列表,并通过 `PUT /api/config/settings` 写回服务端(`surface=mobile`);保存失败时恢复原值并显示错误 | +| 同步 | 侧栏打开期间如果服务端值变化(例如网页端改了同一设置),监听 `AppState` 后按新值重新加载列表 | +| 版本 | **0.6.3(code 603)** | + +--- + ## 0.6.2 归档选择器只列有归档的项目(分支 `flutter`) | 项 | 结果 | diff --git a/README.md b/README.md index a52929d..5714fc7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,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.6.2 — servers (passwordless / password login, HTTP/HTTPS and +Status: 0.6.3 — 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 diff --git a/lib/screens/files_panel.dart b/lib/screens/files_panel.dart index c63c0d3..f66b023 100644 --- a/lib/screens/files_panel.dart +++ b/lib/screens/files_panel.dart @@ -80,8 +80,9 @@ class _FilesPanelState extends State { String? _error; String _query = ''; - /// A project listing hides what git ignores; the menu can show it. - bool _showIgnored = false; + /// The last gitignore choice seen; the app's server-backed setting can + /// change while the panel is open (the switch writes it, a reload reads it). + bool _lastShowIgnored = false; List _deepResults = []; bool _deepDone = false; @@ -112,17 +113,29 @@ class _FilesPanelState extends State { @override void initState() { super.initState(); + _lastShowIgnored = widget.app.showGitignored; + widget.app.addListener(_onApp); _path = _root; if (_root.isNotEmpty) _load(); } @override void dispose() { + widget.app.removeListener(_onApp); _editor.dispose(); _search.dispose(); super.dispose(); } + /// The gitignore setting is shared with the web UI; when it changes (here + /// or on another client), reload the listing with the new filter. + void _onApp() { + if (!mounted || widget.app.showGitignored == _lastShowIgnored) return; + _lastShowIgnored = widget.app.showGitignored; + setState(() {}); + if (_previewPath == null) _load(); + } + // ------------------------------------------------------------- files Future _load([String? path]) async { @@ -138,8 +151,8 @@ class _FilesPanelState extends State { _deepDone = false; }); try { - final list = await client - .fsList(target, directory: _root, respectGitignore: !_showIgnored) + final list = await client.fsList(target, + directory: _root, respectGitignore: !widget.app.showGitignored) ..removeWhere((e) => e.name == '.git'); list.sort((a, b) { if (a.isDirectory != b.isDirectory) return a.isDirectory ? -1 : 1; @@ -626,8 +639,7 @@ class _FilesPanelState extends State { tooltip: tr('More'), onSelected: (value) { if (value == 'ignored') { - setState(() => _showIgnored = !_showIgnored); - _load(); + widget.app.setShowGitignored(!widget.app.showGitignored); } else if (value == 'refresh') { _load(); } @@ -635,7 +647,7 @@ class _FilesPanelState extends State { itemBuilder: (_) => [ CheckedPopupMenuItem( value: 'ignored', - checked: _showIgnored, + checked: widget.app.showGitignored, child: const AppText('Show git-ignored files'), ), const PopupMenuItem( diff --git a/lib/state.dart b/lib/state.dart index 879ca64..e3bd219 100644 --- a/lib/state.dart +++ b/lib/state.dart @@ -109,6 +109,11 @@ class AppState extends ChangeNotifier { /// `allowPromptingSubagentSessions`). bool allowPromptingSubagentSessions = false; + /// Server setting (`filesViewShowGitignored`): the files panel also lists + /// files git ignores. Shared with the web UI's profile settings; off when + /// the server has never written it. + bool showGitignored = false; + /// OpenChamber's own agent tools — the web client's 通用 page: what the /// agent may do inside a chat, and what it may know about the person and the /// project. Server-backed (`/api/config/settings`), shared with the web UI; @@ -203,6 +208,7 @@ class AppState extends ChangeNotifier { followUpBehavior = normalizeFollowUp(settings['followUpBehavior']); allowPromptingSubagentSessions = settings['allowPromptingSubagentSessions'] == true; + showGitignored = settings['filesViewShowGitignored'] == true; _applyToolSettings(settings); notifyListeners(); } catch (_) {} @@ -264,6 +270,33 @@ class AppState extends ChangeNotifier { } } + /// Shows or hides gitignored files in the files panel and writes the same + /// server setting the web UI keeps (`filesViewShowGitignored`). The switch + /// moves at once; a failed save puts the previous value back. + Future setShowGitignored(bool value) async { + final before = showGitignored; + if (value == before) return true; + showGitignored = value; + notifyListeners(); + final cl = client; + if (cl == null) return true; + try { + final settings = + await cl.saveSettings({'filesViewShowGitignored': value}); + if (client != cl) return true; + showGitignored = settings['filesViewShowGitignored'] as bool? ?? value; + notifyListeners(); + return true; + } catch (e) { + if (client == cl) { + showGitignored = before; + _lastError = trArgs('Couldn\'t save: {0}', [e]); + notifyListeners(); + } + return false; + } + } + Future init() async { connections = await storage.connections(); if (connections.isNotEmpty) { diff --git a/pubspec.yaml b/pubspec.yaml index 8564069..581c13c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: openchamber description: "A lightweight OpenChamber client for phones." publish_to: 'none' -version: 0.6.2+602 +version: 0.6.3+603 environment: sdk: ^3.14.0 diff --git a/test/gitignored_setting_test.dart b/test/gitignored_setting_test.dart new file mode 100644 index 0000000..fa2311c --- /dev/null +++ b/test/gitignored_setting_test.dart @@ -0,0 +1,89 @@ +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:openchamber/api/client.dart'; +import 'package:openchamber/api/transport.dart'; +import 'package:openchamber/state.dart'; + +/// A server that keeps `/api/config/settings` in memory, like OpenChamber's +/// settings document. [failWrites] makes the PUT answer 500 so the rollback +/// can be checked. +class _FakeTransport implements Transport { + Map settings; + bool failWrites; + + _FakeTransport(this.settings, {this.failWrites = false}); + + @override + Future send(TransportRequest r) async { + final isSettings = r.path == '/api/config/settings'; + if (isSettings && r.method == 'PUT' && failWrites) { + return TransportResponse( + 500, + const {'content-type': 'application/json'}, + Stream.value(Uint8List.fromList( + utf8.encode(jsonEncode({'error': 'save failed'})))), + ); + } + if (isSettings && r.method == 'PUT' && r.body != null) { + final patch = jsonDecode(utf8.decode(r.body!)) as Map; + settings = {...settings, ...patch}; + } + final body = isSettings ? settings : {}; + return TransportResponse( + 200, + const {'content-type': 'application/json'}, + Stream.value(Uint8List.fromList(utf8.encode(jsonEncode(body)))), + ); + } + + @override + Future webSocket(String path, + {String? rawQuery, Map headers = const {}}) async => + throw UnimplementedError(); + + @override + void setBearerToken(String? token) {} + + @override + void close() {} +} + +void main() { + test('the server gitignore setting is read and written', () async { + final app = AppState(); + addTearDown(app.dispose); + final transport = _FakeTransport({'filesViewShowGitignored': true}); + app.client = Client(Uri.parse('http://test'), transport: transport); + + await app.refreshChatSettings(); + expect(app.showGitignored, isTrue); + + expect(await app.setShowGitignored(false), isTrue); + expect(app.showGitignored, isFalse); + expect(transport.settings['filesViewShowGitignored'], isFalse); + }); + + test('an absent setting starts off', () async { + final app = AppState(); + addTearDown(app.dispose); + app.client = + Client(Uri.parse('http://test'), transport: _FakeTransport({})); + + await app.refreshChatSettings(); + expect(app.showGitignored, isFalse); + }); + + test('a failed save restores the previous value', () async { + final app = AppState(); + addTearDown(app.dispose); + app.client = Client(Uri.parse('http://test'), + transport: _FakeTransport({'filesViewShowGitignored': true}, + failWrites: true)); + + await app.refreshChatSettings(); + expect(await app.setShowGitignored(false), isFalse); + expect(app.showGitignored, isTrue); + }); +}