Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
82 lines
2.3 KiB
Dart
82 lines
2.3 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import 'timeline_session.dart';
|
|
|
|
part 'background_task_registry.g.dart';
|
|
part 'background_task_registry.freezed.dart';
|
|
|
|
@Riverpod(keepAlive: true)
|
|
Raw<BackgroundTaskRegistry> backgroundTaskRegistry(Ref ref) {
|
|
final registry = BackgroundTaskRegistry();
|
|
ref.onDispose(registry.dispose);
|
|
return registry;
|
|
}
|
|
|
|
@freezed
|
|
abstract class BackgroundTaskSession with _$BackgroundTaskSession {
|
|
const factory BackgroundTaskSession({
|
|
required String projectId,
|
|
required String projectName,
|
|
required String timelineId,
|
|
required String timelineName,
|
|
required EditorTimelineSession session,
|
|
}) = _BackgroundTaskSession;
|
|
}
|
|
|
|
/// Application-level index of task owners. Tasks remain owned by their editor
|
|
/// session; global UI observes them without depending on the visible timeline.
|
|
final class BackgroundTaskRegistry extends ChangeNotifier {
|
|
final _entries = <EditorTimelineSession, BackgroundTaskSession>{};
|
|
bool _disposed = false;
|
|
|
|
List<BackgroundTaskSession> get entries => List.unmodifiable(_entries.values);
|
|
|
|
int get runningCount => _entries.values.fold(
|
|
0,
|
|
(count, entry) =>
|
|
count +
|
|
entry.session.subtitleWorkflows.runningCount +
|
|
entry.session.backgroundRemovals.runningCount,
|
|
);
|
|
|
|
void register({
|
|
required String projectId,
|
|
required String projectName,
|
|
required EditorTimelineSession session,
|
|
}) {
|
|
if (_disposed || _entries.containsKey(session)) return;
|
|
_entries[session] = BackgroundTaskSession(
|
|
projectId: projectId,
|
|
projectName: projectName,
|
|
timelineId: session.document.id,
|
|
timelineName: session.document.name,
|
|
session: session,
|
|
);
|
|
session.addListener(_changed);
|
|
notifyListeners();
|
|
}
|
|
|
|
void unregister(EditorTimelineSession session) {
|
|
if (_entries.remove(session) == null) return;
|
|
session.removeListener(_changed);
|
|
if (!_disposed) notifyListeners();
|
|
}
|
|
|
|
void _changed() {
|
|
if (!_disposed) notifyListeners();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
if (_disposed) return;
|
|
_disposed = true;
|
|
for (final session in _entries.keys) {
|
|
session.removeListener(_changed);
|
|
}
|
|
_entries.clear();
|
|
super.dispose();
|
|
}
|
|
}
|