perf(editor): native Windows preview and UI-first timeline navigation (#11)
Gitea CI / Check code and tests (push) Successful in 8m7s
Gitea CI / Build Windows x64 app (push) Successful in 5m48s
Gitea CI / Build Android APK (push) Successful in 5m59s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m17s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m22s
Gitea CI / Gitea CI passed (push) Successful in 2s

This commit was merged in pull request #11.
This commit is contained in:
lingjhf committed 2026-10-07 10:05:14 +00:00
1 parent 0ecf920669
commit b4cb12cbe3
36 files changed
+3292 -148

No files matched your search

+96 -44
View File
@@ -43,6 +43,10 @@ class Projects extends _$Projects {
late ProjectWorkspace _workspace;
bool _workspaceReady = false;
int _timelineNavigation = 0;
(String, String)? _pendingTimelineIds;
Future<bool>? _pendingTimeline;
Future<void> _rememberTimelineTail = Future<void>.value();
AppLocalizations get _localizations {
final configured = ref.read(languageSettingsProvider).asData?.value;
@@ -169,8 +173,13 @@ class Projects extends _$Projects {
Future<bool> _perform(Future<void> Function() action) async {
await future;
if (!ref.mounted || state.requireValue.projectBusy) return false;
_timelineNavigation++;
state = AsyncData(
state.requireValue.copyWith(projectBusy: true, error: null),
state.requireValue.copyWith(
projectBusy: true,
openingTimelineId: null,
error: null,
),
);
try {
await action();
@@ -267,11 +276,7 @@ class Projects extends _$Projects {
}
checkCurrent();
if (selectedDocument != null) {
await _prepareTimeline(
active.id,
selectedDocument,
preparePreview: false,
);
await _prepareTimeline(active.id, selectedDocument);
}
checkCurrent();
await ref
@@ -657,9 +662,8 @@ class Projects extends _$Projects {
Future<EditorTimelineSession> _prepareTimeline(
String projectId,
TimelineDocument document, {
bool preparePreview = true,
}) async {
TimelineDocument document,
) async {
final session = await _workspace.openTimelineSession(projectId, document);
await TimelineViewStateBinding.prepare(
projectId: projectId,
@@ -667,17 +671,8 @@ class Projects extends _$Projects {
session: session,
repository: ref.read(timelineViewSettingsRepositoryProvider),
);
// The preview panel owns asynchronous startup after project publication.
// Cached controllers still bind synchronously when revisiting a project.
if (!preparePreview) return session;
try {
await ref.read(previewControllerRegistryProvider).prepare((
projectId,
document.id,
), session);
} catch (error, stackTrace) {
AppDiagnostics.failure('preview', 'prepare', error, stackTrace);
}
// The preview panel starts decoding after publication. Editing and
// navigation must never wait for native preview initialization.
return session;
}
@@ -689,16 +684,52 @@ class Projects extends _$Projects {
return _workspace.leaseTimeline(projectId, timelineId);
}
Future<bool> openTimeline(String projectId, String timelineId) async {
await future;
final current = state.requireValue;
Future<bool> openTimeline(String projectId, String timelineId) {
final ids = (projectId, timelineId);
if (_pendingTimelineIds == ids &&
_pendingTimeline != null &&
state.value?.openingTimelineId == timelineId) {
return _pendingTimeline!;
}
final pending = _openTimeline(projectId, timelineId);
_pendingTimelineIds = ids;
_pendingTimeline = pending;
void clearPending() {
if (identical(_pendingTimeline, pending)) {
_pendingTimeline = null;
_pendingTimelineIds = null;
}
}
unawaited(
pending.then<void>(
(_) => clearPending(),
onError: (Object _, StackTrace _) => clearPending(),
),
);
return pending;
}
bool _isTimelineNavigationCurrent(int navigation, String projectId) =>
ref.mounted &&
navigation == _timelineNavigation &&
state.value?.activeProject?.id == projectId;
Future<bool> _openTimeline(String projectId, String timelineId) async {
final current = state.value ?? await future;
if (current.projectBusy ||
current.creatingTimeline ||
current.openingTimelineId != null ||
current.activeProject?.id != projectId) {
return false;
}
if (current.timeline?.id == timelineId) return true;
if (!current.timelines.any((timeline) => timeline.id == timelineId)) {
return false;
}
if (current.timeline?.id == timelineId &&
current.openingTimelineId == null) {
return true;
}
final navigation = ++_timelineNavigation;
final cachedTimeline = _workspace.cachedTimelineDocument(
projectId,
timelineId,
@@ -707,11 +738,17 @@ class Projects extends _$Projects {
projectId,
timelineId,
);
if (cachedTimeline != null && cachedSession != null) {
if (cachedTimeline != null &&
cachedSession != null &&
TimelineViewStateBinding.isPrepared(cachedSession)) {
state = AsyncData(
current.copyWith(timeline: cachedTimeline, error: null),
current.copyWith(
timeline: cachedTimeline,
openingTimelineId: null,
error: null,
),
);
await _rememberTimeline(projectId, timelineId);
await _rememberTimeline(projectId, timelineId, navigation: navigation);
return true;
}
state = AsyncData(
@@ -719,18 +756,19 @@ class Projects extends _$Projects {
);
try {
final timeline = await _workspace.loadTimeline(projectId, timelineId);
if (!_isTimelineNavigationCurrent(navigation, projectId)) return false;
await _prepareTimeline(projectId, timeline);
if (!ref.mounted) return true;
if (!_isTimelineNavigationCurrent(navigation, projectId)) return false;
state = AsyncData(
state.requireValue.copyWith(
timeline: timeline,
openingTimelineId: null,
),
);
await _rememberTimeline(projectId, timelineId);
await _rememberTimeline(projectId, timelineId, navigation: navigation);
return true;
} catch (error) {
if (ref.mounted) {
if (_isTimelineNavigationCurrent(navigation, projectId)) {
state = AsyncData(
state.requireValue.copyWith(
openingTimelineId: null,
@@ -742,20 +780,34 @@ class Projects extends _$Projects {
}
}
Future<void> _rememberTimeline(String projectId, String timelineId) async {
try {
await ref
.read(recentProjectsProvider)
.rememberTimeline(projectId, timelineId);
} catch (_) {
if (ref.mounted) {
state = AsyncData(
state.requireValue.copyWith(
error: const AppFailure(AppErrorCode.lastProjectSaveFailed),
),
);
Future<void> _rememberTimeline(
String projectId,
String timelineId, {
int? navigation,
}) {
bool isCurrent() =>
ref.mounted &&
state.value?.activeProject?.id == projectId &&
state.value?.timeline?.id == timelineId &&
state.value?.openingTimelineId == null &&
(navigation == null || navigation == _timelineNavigation);
// Serialize preferences so an older in-flight write cannot finish last.
return _rememberTimelineTail = _rememberTimelineTail.then((_) async {
if (!isCurrent()) return;
try {
await ref
.read(recentProjectsProvider)
.rememberTimeline(projectId, timelineId);
} catch (_) {
if (isCurrent()) {
state = AsyncData(
state.requireValue.copyWith(
error: const AppFailure(AppErrorCode.lastProjectSaveFailed),
),
);
}
}
}
});
}
AppFailure _failureFor(Object error) => projectFailureFromError(error);