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
This commit is contained in:
blumia committed 2026-11-27 17:44:36 +08:00
1 parent 8ac36b1fb1
commit ba3c820186
6 files changed
+154 -9

No files matched your search

+11
View File
@@ -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`)
| 项 | 结果 |
+1 -1
View File
@@ -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
+19 -7
View File
@@ -80,8 +80,9 @@ class _FilesPanelState extends State<FilesPanel> {
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<FsEntry> _deepResults = [];
bool _deepDone = false;
@@ -112,17 +113,29 @@ class _FilesPanelState extends State<FilesPanel> {
@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<void> _load([String? path]) async {
@@ -138,8 +151,8 @@ class _FilesPanelState extends State<FilesPanel> {
_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<FilesPanel> {
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<FilesPanel> {
itemBuilder: (_) => [
CheckedPopupMenuItem(
value: 'ignored',
checked: _showIgnored,
checked: widget.app.showGitignored,
child: const AppText('Show git-ignored files'),
),
const PopupMenuItem(
+33
View File
@@ -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<bool> 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<void> init() async {
connections = await storage.connections();
if (connections.isNotEmpty) {
+1 -1
View File
@@ -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
+89
View File
@@ -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<String, dynamic> settings;
bool failWrites;
_FakeTransport(this.settings, {this.failWrites = false});
@override
Future<TransportResponse> 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<String, dynamic>;
settings = {...settings, ...patch};
}
final body = isSettings ? settings : <String, dynamic>{};
return TransportResponse(
200,
const {'content-type': 'application/json'},
Stream.value(Uint8List.fromList(utf8.encode(jsonEncode(body)))),
);
}
@override
Future<TransportSocket> webSocket(String path,
{String? rawQuery, Map<String, String> 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);
});
}