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
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:
1 parent
0ecf920669
commit
b4cb12cbe3
36 files changed
+3292
-148
No files matched your search
@@ -39,3 +39,8 @@ abstract class ProjectState with _$ProjectState {
|
||||
AppFailure? error,
|
||||
}) = _ProjectState;
|
||||
}
|
||||
|
||||
extension ProjectTimelineSelection on ProjectState {
|
||||
/// Navigation intent is visible before its editing session is ready.
|
||||
String? get visibleTimelineId => openingTimelineId ?? timeline?.id;
|
||||
}
|
||||
+96
-44
@@ -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);
|
||||
|
||||
@@ -33,7 +33,7 @@ final class ProjectsProvider
|
||||
Projects create() => Projects();
|
||||
}
|
||||
|
||||
String _$projectsHash() => r'89495fb433ac9e5d066f0882599598fb2e0a4e54';
|
||||
String _$projectsHash() => r'ecadd6625f90f179184942fe492eac7edb6e21c6';
|
||||
|
||||
abstract class _$Projects extends $AsyncNotifier<ProjectState> {
|
||||
FutureOr<ProjectState> build();
|
||||
|
||||
@@ -8,6 +8,10 @@ import 'timeline_session.dart';
|
||||
/// Keeps local timeline navigation out of the authored project document.
|
||||
final class TimelineViewStateBinding {
|
||||
static final _initialized = Expando<bool>();
|
||||
static final _preparing = Expando<Future<void>>();
|
||||
|
||||
static bool isPrepared(EditorTimelineSession session) =>
|
||||
_initialized[session] == true;
|
||||
|
||||
TimelineViewStateBinding._(
|
||||
this.projectId,
|
||||
@@ -21,16 +25,21 @@ final class TimelineViewStateBinding {
|
||||
required String timelineId,
|
||||
required EditorTimelineSession session,
|
||||
required TimelineViewSettingsRepository repository,
|
||||
}) async {
|
||||
if (_initialized[session] == true) return;
|
||||
var saved = const TimelineViewState();
|
||||
try {
|
||||
saved = await repository.load(projectId, timelineId);
|
||||
} catch (_) {
|
||||
// Corrupt or unavailable local UI state must not block the timeline.
|
||||
}
|
||||
_restore(session, saved);
|
||||
_initialized[session] = true;
|
||||
}) {
|
||||
if (isPrepared(session)) return Future<void>.value();
|
||||
final pending = _preparing[session];
|
||||
if (pending != null) return pending;
|
||||
return _preparing[session] = () async {
|
||||
var saved = const TimelineViewState();
|
||||
try {
|
||||
saved = await repository.load(projectId, timelineId);
|
||||
} catch (_) {
|
||||
// Corrupt or unavailable local UI state must not block the timeline.
|
||||
}
|
||||
_restore(session, saved);
|
||||
_initialized[session] = true;
|
||||
_preparing[session] = null;
|
||||
}();
|
||||
}
|
||||
|
||||
static FutureOr<TimelineViewStateBinding> attach({
|
||||
|
||||
@@ -22,7 +22,9 @@ 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) {
|
||||
if (projectId != null &&
|
||||
timelineId != null &&
|
||||
state.openingTimelineId == null) {
|
||||
ref.watch(editorTimelineProvider(projectId, timelineId));
|
||||
}
|
||||
final selection = ref.watch(conversationSelectionProvider(projectId));
|
||||
|
||||
Reference in new issue
Block a user