feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s

This commit was merged in pull request #13.
This commit is contained in:
lingjhf committed 2026-10-08 18:17:12 +00:00
1 parent aa5255d1e4
commit abc1868550
260 files changed
+43964 -5591

No files matched your search

@@ -130,6 +130,11 @@ class ProjectWorkspace {
_project = null;
}
Future<void> deactivateProject() => _run(() async {
await _retireProject();
await _trimWarmProjects();
});
Future<void> _trimWarmProjects() async {
while (_warmProjects.length > 2) {
final file = _warmProjects.removeAt(0);
@@ -261,7 +266,7 @@ class ProjectWorkspace {
retained ??
(name == null
? await ProjectFile.open(directory)
: await ProjectFile.create(
: await _createProjectFile(
directory,
name: name,
initialTimeline: _newTimelineDocument(
@@ -307,6 +312,26 @@ class ProjectWorkspace {
}
});
Future<ProjectFile> _createProjectFile(
Directory directory, {
required String name,
required TimelineDocument initialTimeline,
}) async {
try {
return await ProjectFile.create(
directory,
name: name,
initialTimeline: initialTimeline,
);
} on ProjectFileException catch (error) {
if (error.code != ProjectFileError.conflict) rethrow;
throw AppException(
AppErrorCode.projectAlreadyExists,
diagnostic: error.toString(),
);
}
}
/// Reads timelines from any project without installing it as the active one.
///
/// This intentionally shares the workspace queue with [open] and all active
+53 -2
View File
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:cutdex_sdk/preview.dart';
import 'package:flutter/foundation.dart';
import 'package:cutdex_sdk/runtime.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
@@ -24,14 +25,57 @@ PreviewControllerRegistry previewControllerRegistry(Ref ref) {
/// Owns native preview controllers independently of the currently visible
/// timeline. Prepared controllers make timeline selection a synchronous swap.
final class PreviewControllerRegistry {
PreviewControllerRegistry(this._runtime, {this._onChanged});
PreviewControllerRegistry(
this._runtime, {
this._onChanged,
this.maximumCachedControllers = 4,
}) : assert(maximumCachedControllers > 0);
final int maximumCachedControllers;
final CutdexRuntime _runtime;
final void Function()? _onChanged;
final _controllers = <(String, String), PreviewController>{};
final _preparing = <(String, String), Future<PreviewController>>{};
final _leases = <(String, String), int>{};
bool _disposed = false;
/// Mounted providers retain their controller; idle entries are evictable.
VoidCallback retain((String, String) ids) {
if (_disposed) throw StateError('Preview registry is closed');
_leases[ids] = (_leases[ids] ?? 0) + 1;
var released = false;
return () {
if (released || _disposed) return;
released = true;
final count = (_leases[ids] ?? 1) - 1;
if (count == 0) {
_leases.remove(ids);
final controller = _controllers[ids];
if (controller != null) {
unawaited(
controller.pauseForCanvasInteraction().catchError((Object _) {}),
);
}
} else {
_leases[ids] = count;
}
_trimCache();
};
}
void _trimCache() {
if (_disposed) return;
while (_controllers.length > maximumCachedControllers) {
final oldest = _controllers.keys
.where(
(ids) => !_preparing.containsKey(ids) && (_leases[ids] ?? 0) == 0,
)
.firstOrNull;
if (oldest == null) return;
unawaited(invalidate(oldest).catchError((Object _) {}));
}
}
PreviewController? cached((String, String) ids) => _controllers[ids];
FutureOr<PreviewController?> prepare(
@@ -46,7 +90,12 @@ final class PreviewControllerRegistry {
final pending = _preparing[ids];
if (pending != null) return pending;
final cached = _controllers[ids];
if (cached != null) return cached;
if (cached != null) {
// Map insertion order is the access order for bounded idle entries.
_controllers.remove(ids);
_controllers[ids] = cached;
return cached;
}
final future = _initialize(ids, timeline);
_preparing[ids] = future;
return future;
@@ -82,6 +131,7 @@ final class PreviewControllerRegistry {
rethrow;
} finally {
_preparing.remove(ids);
_trimCache();
}
}
@@ -114,6 +164,7 @@ final class PreviewControllerRegistry {
final controllers = _controllers.values.toList();
_controllers.clear();
_preparing.clear();
_leases.clear();
for (final controller in controllers) {
unawaited(controller.close().catchError((Object _) {}));
}
+37
View File
@@ -23,6 +23,7 @@ import 'media_import.dart';
import 'timeline_session.dart';
import 'background_task_registry.dart';
import 'timeline_view_state.dart';
import 'view_settings.dart';
import 'preview_controller_registry.dart';
import 'package:cutdex_sdk/editor.dart';
@@ -200,6 +201,19 @@ class Projects extends _$Projects {
}
}
Future<bool> closeActiveProject() => _perform(() async {
await _workspace.deactivateProject();
if (!ref.mounted) return;
state = AsyncData(
state.requireValue.copyWith(
activeProject: null,
timeline: null,
timelines: const [],
assets: const [],
),
);
});
Future<bool> open(
String path, {
String? name,
@@ -278,6 +292,8 @@ class Projects extends _$Projects {
if (selectedDocument != null) {
await _prepareTimeline(active.id, selectedDocument);
}
// Publish content and its saved layout together to avoid a default-layout frame.
await ref.read(projectViewSettingsProvider(active.id).future);
checkCurrent();
await ref
.read(previewControllerRegistryProvider)
@@ -327,6 +343,27 @@ class Projects extends _$Projects {
}
});
/// Checks destination occupancy without creating or changing any files.
/// Creation still checks again to protect against concurrent changes.
Future<AppFailure?> validateNewProjectName(String name) async {
try {
final root = await ref
.read(projectLocationSettingsRepositoryProvider)
.load();
if (root == null || root.trim().isEmpty) return null;
final destination = p.join(root, '${name.trim()}.cutdex');
if (await FileSystemEntity.type(destination, followLinks: false) !=
FileSystemEntityType.notFound) {
return const AppFailure(AppErrorCode.projectAlreadyExists);
}
} on ProjectLocationUnavailableException {
// The creation flow presents location failures with a settings action.
} on FileSystemException {
// Let creation report the access failure through its normal error path.
}
return null;
}
Future<bool> createProject(
String name, {
required String initialTimelineName,
+1 -1
View File
@@ -33,7 +33,7 @@ final class ProjectsProvider
Projects create() => Projects();
}
String _$projectsHash() => r'ecadd6625f90f179184942fe492eac7edb6e21c6';
String _$projectsHash() => r'daffbd0c3f4c8058f0fd53378611a2031770796f';
abstract class _$Projects extends $AsyncNotifier<ProjectState> {
FutureOr<ProjectState> build();
+5 -5
View File
@@ -22,10 +22,10 @@ class WorkspaceSessionScope extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final projectId = state.activeProject?.id;
final timelineId = state.timeline?.id;
if (projectId != null &&
timelineId != null &&
state.openingTimelineId == null) {
ref.watch(editorTimelineProvider(projectId, timelineId));
if (projectId != null && timelineId != null) {
ref.watch(
editorTimelineProvider(projectId, timelineId).select((_) => null),
);
}
final selection = ref.watch(conversationSelectionProvider(projectId));
if (projectId != null) {
@@ -34,7 +34,7 @@ class WorkspaceSessionScope extends ConsumerWidget {
projectId,
conversationId: selection.selectedId,
draftKey: selection.selectedId == null ? selection.draftKey : null,
),
).select((_) => null),
);
}
return child;