feat: initial Cutdex application
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.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,162 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/features/settings/appearance_settings.dart';
|
||||
import 'package:cutdex/features/settings/language_settings.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
_testSettings<AppAppearance>(
|
||||
name: 'appearance',
|
||||
initial: AppAppearance.system,
|
||||
first: AppAppearance.penLight,
|
||||
second: AppAppearance.penDark,
|
||||
container: (store) => ProviderContainer(
|
||||
overrides: [
|
||||
appearanceSettingsRepositoryProvider.overrideWithValue(
|
||||
_AppearanceRepository(store),
|
||||
),
|
||||
],
|
||||
),
|
||||
load: (container) => container.read(appearanceSettingsProvider.future),
|
||||
value: (container) =>
|
||||
container.read(appearanceSettingsProvider).requireValue,
|
||||
save: (container, value) =>
|
||||
container.read(appearanceSettingsProvider.notifier).setMode(value),
|
||||
);
|
||||
_testSettings<AppLanguage>(
|
||||
name: 'language',
|
||||
initial: AppLanguage.system,
|
||||
first: AppLanguage.english,
|
||||
second: AppLanguage.simplifiedChinese,
|
||||
container: (store) => ProviderContainer(
|
||||
overrides: [
|
||||
languageSettingsRepositoryProvider.overrideWithValue(
|
||||
_LanguageRepository(store),
|
||||
),
|
||||
],
|
||||
),
|
||||
load: (container) => container.read(languageSettingsProvider.future),
|
||||
value: (container) => container.read(languageSettingsProvider).requireValue,
|
||||
save: (container, value) =>
|
||||
container.read(languageSettingsProvider.notifier).setLanguage(value),
|
||||
);
|
||||
}
|
||||
|
||||
void _testSettings<T>({
|
||||
required String name,
|
||||
required T initial,
|
||||
required T first,
|
||||
required T second,
|
||||
required ProviderContainer Function(_Store<T>) container,
|
||||
required Future<T> Function(ProviderContainer) load,
|
||||
required T Function(ProviderContainer) value,
|
||||
required Future<void> Function(ProviderContainer, T) save,
|
||||
}) {
|
||||
test('$name saves in order and publishes only committed values', () async {
|
||||
final store = _Store(initial)..writeGate = Completer<void>();
|
||||
final scope = container(store);
|
||||
addTearDown(scope.dispose);
|
||||
await load(scope);
|
||||
final firstSave = save(scope, first);
|
||||
await store.started.future;
|
||||
final secondSave = save(scope, second);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(store.writes, [first]);
|
||||
expect(value(scope), initial);
|
||||
store.writeGate!.complete();
|
||||
await Future.wait([firstSave, secondSave]);
|
||||
expect(store.writes, [first, second]);
|
||||
expect(store.value, second);
|
||||
expect(value(scope), second);
|
||||
});
|
||||
|
||||
test('$name can save again after a failed write', () async {
|
||||
final store = _Store(initial)..failWrites = true;
|
||||
final scope = container(store);
|
||||
addTearDown(scope.dispose);
|
||||
await load(scope);
|
||||
await expectLater(save(scope, first), throwsStateError);
|
||||
expect(value(scope), initial);
|
||||
expect(store.value, initial);
|
||||
store.failWrites = false;
|
||||
await save(scope, second);
|
||||
expect(value(scope), second);
|
||||
expect(store.value, second);
|
||||
});
|
||||
|
||||
test('$name waits for initial load before saving', () async {
|
||||
final store = _Store(initial)..loadGate = Completer<void>();
|
||||
final scope = container(store);
|
||||
addTearDown(scope.dispose);
|
||||
final initialLoad = load(scope);
|
||||
final pending = save(scope, first);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(store.writes, isEmpty);
|
||||
store.loadGate!.complete();
|
||||
await initialLoad;
|
||||
await pending;
|
||||
expect(value(scope), first);
|
||||
expect(store.value, first);
|
||||
});
|
||||
|
||||
test('$name finishes an in-flight save safely after disposal', () async {
|
||||
final store = _Store(initial)..writeGate = Completer<void>();
|
||||
final scope = container(store);
|
||||
await load(scope);
|
||||
final firstSave = save(scope, first);
|
||||
await store.started.future;
|
||||
final queuedSave = save(scope, second);
|
||||
scope.dispose();
|
||||
store.writeGate!.complete();
|
||||
await Future.wait([firstSave, queuedSave]);
|
||||
expect(store.writes, [first]);
|
||||
expect(store.value, first);
|
||||
});
|
||||
}
|
||||
|
||||
class _Store<T> {
|
||||
_Store(this.value);
|
||||
|
||||
T value;
|
||||
final writes = <T>[];
|
||||
final started = Completer<void>();
|
||||
Completer<void>? loadGate;
|
||||
Completer<void>? writeGate;
|
||||
bool failWrites = false;
|
||||
|
||||
Future<T> load() async {
|
||||
final snapshot = value;
|
||||
await loadGate?.future;
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
Future<void> save(T next) async {
|
||||
writes.add(next);
|
||||
if (!started.isCompleted) started.complete();
|
||||
await writeGate?.future;
|
||||
if (failWrites) throw StateError('Storage unavailable');
|
||||
value = next;
|
||||
}
|
||||
}
|
||||
|
||||
class _AppearanceRepository implements AppearanceSettingsRepository {
|
||||
_AppearanceRepository(this.store);
|
||||
final _Store<AppAppearance> store;
|
||||
|
||||
@override
|
||||
Future<AppAppearance> load() => store.load();
|
||||
@override
|
||||
Future<void> save(AppAppearance value) => store.save(value);
|
||||
}
|
||||
|
||||
class _LanguageRepository implements LanguageSettingsRepository {
|
||||
_LanguageRepository(this.store);
|
||||
final _Store<AppLanguage> store;
|
||||
|
||||
@override
|
||||
Future<AppLanguage> load() => store.load();
|
||||
@override
|
||||
Future<void> save(AppLanguage value) => store.save(value);
|
||||
}
|
||||
Reference in new issue
Block a user