feat: one project sheet for sessions and scheduled tasks

- the scheduled-task scope dropdown becomes the same project sheet the
  new-session composer opens: Chat row, project icons, paths, the current
  check mark, and one row per checkout
- a filesystem root ("/") no longer reads as a blank row: pathLeaf falls
  back to the path itself instead of an empty last segment
- the sheet opens at once and refreshes the project list behind it; an
  empty list shows "Loading projects…" until the answer arrives, so the
  project chip no longer waits before anything appears
- bump to 0.5.5
This commit is contained in:
blumia committed 2026-11-26 14:00:35 +08:00
1 parent 545778c6f3
commit a70e9290ef
9 files changed
+338 -127

No files matched your search

+11
View File
@@ -5,6 +5,17 @@
--- ---
## 0.5.5 项目选择与计划任务运行位置(分支 `flutter`)
| 项 | 结果 |
| --- | --- |
| 空白选项 | 服务器会把根目录 `/` 也列成一个项目;`pathLeaf('/')` 取最后一段时得到空串,标签就成了空白。根路径现在用自己的路径作名称(`/`);同一个 checkout 被服务器列两次(项目记录 + sandbox)时也合并成一行 |
| 新建会话 | 点项目名不再先等项目接口:bottomsheet 立即弹出,列表为空时显示「正在加载项目…」,刷新完成(或已有缓存)后展示列表;确实没有项目时显示「没有可用的项目」 |
| 计划任务 | 运行位置改用与新建会话相同的项目 bottomsheet(含「聊天」scope、图标、路径与当前选中标记),不再用长列表下拉框 |
| 版本 | **0.5.5(code 505)** |
---
## 0.5.4 文件下载进度(分支 `flutter`) ## 0.5.4 文件下载进度(分支 `flutter`)
| 项 | 结果 | | 项 | 结果 |
+1 -1
View File
@@ -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.5.4 — servers (passwordless / password login, HTTP/HTTPS and Status: 0.5.5 — servers (passwordless / password login, HTTP/HTTPS and
SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link
over the OpenChamber private relay with end-to-end encryption; the pairing 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 link is pasted or scanned with the camera), session list with search and live
+3
View File
@@ -250,6 +250,9 @@ class ProjectInfo {
/// sends `C:\...` and a project has to read as its folder name, not the path. /// sends `C:\...` and a project has to read as its folder name, not the path.
String pathLeaf(String path) { String pathLeaf(String path) {
final trimmed = path.replaceAll(RegExp(r'[/\\]+$'), ''); final trimmed = path.replaceAll(RegExp(r'[/\\]+$'), '');
// A filesystem root ("/", "C:\") has no last segment; its own path is the
// only name left, and an empty one would render a blank row and menu entry.
if (trimmed.isEmpty) return path.trim();
final index = trimmed.lastIndexOf(RegExp(r'[/\\]')); final index = trimmed.lastIndexOf(RegExp(r'[/\\]'));
return index >= 0 ? trimmed.substring(index + 1) : trimmed; return index >= 0 ? trimmed.substring(index + 1) : trimmed;
} }
+1
View File
@@ -216,6 +216,7 @@ const Map<String, String> chineseStrings = {
'Let the agent show charts, tables, diagrams and UI sketches in chat (isolated from your files) and ask you to pick one of them.': '让智能体在聊天中展示图表、表格、示意图和界面草图(与你的文件隔离),并请你在其中选择一个选项。', 'Let the agent show charts, tables, diagrams and UI sketches in chat (isolated from your files) and ask you to pick one of them.': '让智能体在聊天中展示图表、表格、示意图和界面草图(与你的文件隔离),并请你在其中选择一个选项。',
'Light': '浅色', 'Light': '浅色',
'List': '列出', 'List': '列出',
'Loading projects…': '正在加载项目…',
'Load earlier messages': '载入更早的消息', 'Load earlier messages': '载入更早的消息',
'Load more': '载入更多', 'Load more': '载入更多',
'Loading models…': '正在载入模型…', 'Loading models…': '正在载入模型…',
+10 -90
View File
@@ -4,13 +4,13 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import '../api/models.dart';
import '../state.dart'; import '../state.dart';
import '../widgets/composer_attachment.dart'; import '../widgets/composer_attachment.dart';
import '../widgets/composer_box.dart'; import '../widgets/composer_box.dart';
import '../widgets/model_controls.dart'; import '../widgets/model_controls.dart';
import '../widgets/pet_sprite.dart'; import '../widgets/pet_sprite.dart';
import '../widgets/project_icon.dart'; import '../widgets/project_icon.dart';
import '../widgets/project_picker.dart';
import '../widgets/slash_palette.dart'; import '../widgets/slash_palette.dart';
import 'files_panel.dart'; import 'files_panel.dart';
import '../l10n.dart'; import '../l10n.dart';
@@ -462,98 +462,18 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
Future<void> _pickProject() async { Future<void> _pickProject() async {
final app = widget.app; final app = widget.app;
await Future.wait([app.refreshProjects(), app.refreshFsHome()]);
if (!mounted) return;
final draft = app.draft; final draft = app.draft;
if (draft == null) return; if (draft == null) return;
final projects = _selectableProjects(app.projects); // The sheet opens right away; it refreshes the project list inside.
await showModalBottomSheet<void>( final choice = await showProjectPicker(
context: context, context,
isScrollControlled: true, app: app,
builder: (context) => DraggableScrollableSheet( selected: draft.directory,
expand: false,
initialChildSize: 0.6,
maxChildSize: 0.9,
builder: (context, controller) => Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(16, 14, 16, 6),
child: AppText('Choose project',
style:
TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
),
Expanded(
child: ListView(
controller: controller,
children: [
ListTile(
dense: true,
leading: ProjectIcon(
app: widget.app, chat: true, size: 20),
title: const AppText('Chat'),
subtitle: const AppText('Not tied to a project, saved in OpenChamber\'s chat directory'),
trailing: draft.directory == AppState.chatTarget
? Icon(Icons.check,
size: 18,
color: Theme.of(context).colorScheme.primary)
: null,
onTap: () {
app.updateDraftTarget(AppState.chatTarget);
_slashLoaded = false;
_slashItems = [];
Navigator.pop(context);
},
),
for (final project in projects)
ListTile(
dense: true,
leading:
ProjectIcon(app: widget.app, project: project, size: 20),
title: Text(project.label,
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: Text(project.canonical,
maxLines: 1, overflow: TextOverflow.ellipsis),
trailing: project.canonical == draft.directory
? Icon(Icons.check,
size: 18,
color: Theme.of(context).colorScheme.primary)
: null,
onTap: () {
app.updateDraftTarget(project.canonical);
_slashLoaded = false;
_slashItems = [];
Navigator.pop(context);
},
),
if (projects.isEmpty)
const Padding(
padding: EdgeInsets.all(24),
child: AppText('No projects available', textAlign: TextAlign.center),
),
],
),
),
],
),
),
); );
if (choice == null || !mounted) return;
app.updateDraftTarget(choice.canonical);
_slashLoaded = false;
_slashItems = [];
} }
/// The picker shows checkouts, not the server's chat folders (those are
/// reached by just starting a chat, not by choosing a project). The server
/// can list the same path twice (a project record and a sandbox), so one
/// path is one row, preferring the one that knows its VCS.
List<ProjectInfo> _selectableProjects(List<ProjectInfo> projects) {
final byPath = <String, ProjectInfo>{};
for (final project in projects) {
if (project.canonical.isEmpty) continue;
if (widget.app.isChatDirectory(project.canonical)) continue;
final existing = byPath[project.canonical];
if (existing == null ||
(existing.vcs.isEmpty && project.vcs.isNotEmpty)) {
byPath[project.canonical] = project;
}
}
return byPath.values.toList();
}
} }
+57 -35
View File
@@ -7,6 +7,7 @@ import '../api/client.dart';
import '../api/models.dart'; import '../api/models.dart';
import '../api/scheduled_tasks.dart'; import '../api/scheduled_tasks.dart';
import '../state.dart'; import '../state.dart';
import '../widgets/project_picker.dart';
import '../widgets/scheduled_task_editor.dart'; import '../widgets/scheduled_task_editor.dart';
import '../l10n.dart'; import '../l10n.dart';
@@ -49,21 +50,23 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
List<_TaskScope> _buildScopes() { List<_TaskScope> _buildScopes() {
return [ return [
for (final project in app.projects) for (final project in selectableProjects(app))
// A chat's own directory is not a project of its own: every chat _scopeFor(project),
// schedules into the chats scope below. _chatsScope,
if (project.canonical.isNotEmpty && !app.isChatDirectory(project.canonical))
_TaskScope(
project.metaId.isNotEmpty
? project.metaId
: Client.projectIdFor(project.canonical),
project.label,
project.canonical,
),
_TaskScope(Client.scheduledChatsScope, tr('Chat')),
]; ];
} }
static _TaskScope _scopeFor(ProjectInfo project) => _TaskScope(
project.metaId.isNotEmpty
? project.metaId
: Client.projectIdFor(project.canonical),
project.label,
project.canonical,
);
_TaskScope get _chatsScope =>
_TaskScope(Client.scheduledChatsScope, tr('Chat'));
_TaskScope? _defaultScope() { _TaskScope? _defaultScope() {
if (_scopes.isEmpty) return null; if (_scopes.isEmpty) return null;
final directory = app.directory; final directory = app.directory;
@@ -260,6 +263,28 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
); );
} }
/// The same sheet the new-session composer uses: checkouts and the Chat
/// scope, with the project list refreshed behind it.
Future<void> _pickScope() async {
final selected =
_scope == null || _scope!.directory.isEmpty ? AppState.chatTarget : _scope!.directory;
final choice = await showProjectPicker(
context,
app: app,
selected: selected,
);
if (choice == null || !mounted) return;
final next = choice.isChat ? _chatsScope : _scopeFor(choice.project!);
if (next.id == _scope?.id) return;
setState(() {
_scope = next;
_tasks = const [];
_loading = true;
_error = null;
});
_load();
}
Widget _scopeBar(ThemeData theme) { Widget _scopeBar(ThemeData theme) {
return Padding( return Padding(
padding: const EdgeInsets.fromLTRB(16, 6, 8, 6), padding: const EdgeInsets.fromLTRB(16, 6, 8, 6),
@@ -270,30 +295,27 @@ class _ScheduledTasksScreenState extends State<ScheduledTasksScreen> {
AppText('Runs in', style: TextStyle(fontSize: 13, color: theme.hintColor)), AppText('Runs in', style: TextStyle(fontSize: 13, color: theme.hintColor)),
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: DropdownButtonHideUnderline( child: InkWell(
child: DropdownButton<String>( borderRadius: BorderRadius.circular(8),
value: _scope?.id, onTap: _pickScope,
isExpanded: true, child: Padding(
items: [ padding:
for (final scope in _scopes) const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
DropdownMenuItem( child: Row(
value: scope.id, children: [
child: Text(scope.label, Expanded(
maxLines: 1, overflow: TextOverflow.ellipsis), child: Text(
_scope?.label ?? tr('Choose project'),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13.5,
color: theme.colorScheme.onSurface),
),
), ),
], Icon(Icons.expand_more, size: 18, color: theme.hintColor),
onChanged: (id) { ],
final scope = ),
_scopes.where((s) => s.id == id).cast<_TaskScope?>().firstOrNull;
if (scope == null || scope.id == _scope?.id) return;
setState(() {
_scope = scope;
_tasks = const [];
_loading = true;
_error = null;
});
_load();
},
), ),
), ),
), ),
+178
View File
@@ -0,0 +1,178 @@
// Choosing a project, shared by the new-session draft and scheduled tasks.
// The sheet opens at once and refreshes the project list behind it: a tap on
// the project chip should never wait for the server before anything appears.
import 'package:flutter/material.dart';
import '../api/models.dart';
import '../l10n.dart';
import '../state.dart';
import 'project_icon.dart';
/// What the picker returns: the Chat row or a project checkout.
class ProjectChoice {
/// Null for the Chat row: a chat is not tied to a project.
final ProjectInfo? project;
const ProjectChoice.chat() : project = null;
const ProjectChoice.project(this.project);
bool get isChat => project == null;
String get canonical => project?.canonical ?? AppState.chatTarget;
String get label => project?.label ?? tr('Chat');
}
/// Opens the project sheet and returns the chosen target, or null when the
/// person dismissed it. [selected] is a checkout path, or [AppState.chatTarget]
/// for the Chat row.
Future<ProjectChoice?> showProjectPicker(
BuildContext context, {
required AppState app,
required String selected,
}) {
return showModalBottomSheet<ProjectChoice>(
context: context,
isScrollControlled: true,
builder: (context) => DraggableScrollableSheet(
expand: false,
initialChildSize: 0.6,
maxChildSize: 0.9,
builder: (context, controller) => _ProjectPickerSheet(
app: app,
selected: selected,
controller: controller,
),
),
);
}
/// The projects a picker offers: checkouts, not the server's chat folders.
/// The server can list the same path twice (a project record and a sandbox),
/// so one path is one row, preferring the one that knows its VCS.
List<ProjectInfo> selectableProjects(AppState app) {
final byPath = <String, ProjectInfo>{};
for (final project in app.projects) {
if (project.canonical.isEmpty) continue;
if (app.isChatDirectory(project.canonical)) continue;
final existing = byPath[project.canonical];
if (existing == null ||
(existing.vcs.isEmpty && project.vcs.isNotEmpty)) {
byPath[project.canonical] = project;
}
}
return byPath.values.toList();
}
class _ProjectPickerSheet extends StatefulWidget {
final AppState app;
final String selected;
final ScrollController controller;
const _ProjectPickerSheet({
required this.app,
required this.selected,
required this.controller,
});
@override
State<_ProjectPickerSheet> createState() => _ProjectPickerSheetState();
}
class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
/// True until the list behind the sheet has been refreshed. The sheet is
/// already up by then; only its body shows the spinner.
bool _refreshing = true;
@override
void initState() {
super.initState();
_refresh();
}
Future<void> _refresh() async {
await Future.wait([
widget.app.refreshProjects(),
widget.app.refreshFsHome(),
]);
if (!mounted) return;
setState(() => _refreshing = false);
}
@override
Widget build(BuildContext context) {
final chat = widget.selected == AppState.chatTarget;
// A cached list is shown at once; the refresh updates it in place.
final projects = selectableProjects(widget.app);
final loading = _refreshing && projects.isEmpty;
return Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(16, 14, 16, 6),
child: AppText('Choose project',
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600)),
),
Expanded(
child: loading
? const Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 22,
height: 22,
child: CircularProgressIndicator(strokeWidth: 2)),
SizedBox(height: 12),
AppText('Loading projects…'),
],
),
),
)
: ListView(
controller: widget.controller,
children: [
ListTile(
dense: true,
leading:
ProjectIcon(app: widget.app, chat: true, size: 20),
title: const AppText('Chat'),
subtitle: const AppText(
'Not tied to a project, saved in OpenChamber\'s chat directory'),
trailing: chat
? Icon(Icons.check,
size: 18,
color: Theme.of(context).colorScheme.primary)
: null,
onTap: () =>
Navigator.pop(context, const ProjectChoice.chat()),
),
for (final project in projects)
ListTile(
dense: true,
leading: ProjectIcon(
app: widget.app, project: project, size: 20),
title: Text(project.label,
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: Text(project.canonical,
maxLines: 1, overflow: TextOverflow.ellipsis),
trailing: samePath(project.canonical, widget.selected)
? Icon(Icons.check,
size: 18,
color: Theme.of(context).colorScheme.primary)
: null,
onTap: () => Navigator.pop(
context, ProjectChoice.project(project)),
),
if (!_refreshing && projects.isEmpty)
const Padding(
padding: EdgeInsets.all(24),
child: AppText('No projects available',
textAlign: TextAlign.center),
),
],
),
),
],
);
}
}
+1 -1
View File
@@ -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.5.4+504 version: 0.5.5+505
environment: environment:
sdk: ^3.14.0 sdk: ^3.14.0
+76
View File
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:openchamber/api/models.dart';
import 'package:openchamber/l10n.dart';
import 'package:openchamber/screens/scheduled_tasks_screen.dart';
import 'package:openchamber/state.dart';
import 'package:openchamber/widgets/project_picker.dart';
void main() {
setUp(() => L10n.instance.apply(AppLanguage.en));
tearDown(() => L10n.instance.apply(AppLanguage.zh));
test('a filesystem root keeps its own name', () {
expect(pathLeaf('/'), '/');
expect(pathLeaf('/home/me/project/'), 'project');
expect(pathLeaf(r'C:\Users\me'), 'me');
});
testWidgets('the picker lists checkouts and the Chat row', (tester) async {
final app = AppState();
addTearDown(app.dispose);
app.projects = const [
ProjectInfo(id: 'p1', canonical: '/home/me/project', name: 'My project'),
// The server also knows the root; it must not read as a blank row.
ProjectInfo(id: 'root', canonical: '/'),
// The same checkout listed twice (a project record and a sandbox).
ProjectInfo(
id: 'p2', canonical: '/home/me/project', name: 'My project', vcs: 'git'),
];
ProjectChoice? choice;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) => TextButton(
onPressed: () async {
choice = await showProjectPicker(context,
app: app, selected: AppState.chatTarget);
},
child: const Text('open'),
),
),
),
));
await tester.tap(find.text('open'));
await tester.pumpAndSettle();
expect(find.text('Choose project'), findsOneWidget);
expect(find.text('Chat'), findsWidgets);
expect(find.text('My project'), findsOneWidget);
// The root's label and its path are the same text.
expect(find.text('/'), findsWidgets);
await tester.tap(find.text('My project'));
await tester.pumpAndSettle();
expect(choice, isNotNull);
expect(choice!.canonical, '/home/me/project');
expect(choice!.isChat, isFalse);
});
testWidgets('scheduled tasks open the same project sheet', (tester) async {
final app = AppState();
addTearDown(app.dispose);
app.projects = const [
ProjectInfo(id: 'p1', canonical: '/home/me/project', name: 'My project'),
];
await tester.pumpWidget(MaterialApp(home: ScheduledTasksScreen(app: app)));
await tester.pumpAndSettle();
await tester.tap(find.text('My project'));
await tester.pumpAndSettle();
expect(find.text('Choose project'), findsOneWidget);
expect(find.text('My project'), findsWidgets);
});
}