import 'dart:ui'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../features/settings/language_settings.dart'; import '../l10n/app_localizations.dart'; import '../workspace/project_state.dart'; import '../workspace/projects.dart'; import '../workspace/preview_target.dart'; import '../workspace/timeline_provider.dart'; import '../workspace/timeline_session.dart'; abstract interface class ApplicationCommandDependencies { Future projectState(); Future createProject(String name); Future openProject(String path, {String? expectedId}); Future createTimeline(String name); Future openTimeline(String projectId, String timelineId); Future timeline(String projectId, String timelineId); PreviewTarget preview(String projectId, String timelineId); } /// Riverpod is confined to the composition adapter, not the command host. class RiverpodApplicationCommandDependencies implements ApplicationCommandDependencies { const RiverpodApplicationCommandDependencies(this._ref); final Ref _ref; Projects get _projects => _ref.read(projectsProvider.notifier); @override Future projectState() => _ref.read(projectsProvider.future); @override Future createProject(String name) { final configured = _ref.read(languageSettingsProvider).asData?.value; final locale = configured?.locale ?? resolveAppLocale( PlatformDispatcher.instance.locales, AppLocalizations.supportedLocales, ); return _projects.createProject( name, initialTimelineName: lookupAppLocalizations(locale) .defaultTimelineName(1), ); } @override Future openProject(String path, {String? expectedId}) => _projects.open(path, expectedId: expectedId); @override Future createTimeline(String name) => _projects.createTimeline(name: name); @override Future openTimeline(String projectId, String timelineId) => _projects.openTimeline(projectId, timelineId); @override Future timeline(String projectId, String timelineId) => _ref.read(editorTimelineProvider(projectId, timelineId).future); @override PreviewTarget preview(String projectId, String timelineId) => _ref.read(previewTargetProvider(projectId, timelineId)); }