fix(preview): 接入已合并 SDK 与 Android 0.1.3 预览验证 (#12)
Gitea CI / Build Windows x64 app (push) Successful in 2m38s
Gitea CI / Check code and tests (push) Successful in 5m19s
Gitea CI / Build Android APK (push) Successful in 3m13s
Gitea CI / Audit and package Windows x64 (push) Successful in 2m49s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 59s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea CI / Build Windows x64 app (push) Successful in 2m38s
Gitea CI / Check code and tests (push) Successful in 5m19s
Gitea CI / Build Android APK (push) Successful in 3m13s
Gitea CI / Audit and package Windows x64 (push) Successful in 2m49s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 59s
Gitea CI / Gitea CI passed (push) Successful in 2s
This commit was merged in pull request #12.
This commit is contained in:
1 parent
b4cb12cbe3
commit
aa5255d1e4
11 files changed
+1577
-30
No files matched your search
@@ -13,6 +13,9 @@ part 'preview_controller_registry.g.dart';
|
||||
PreviewControllerRegistry previewControllerRegistry(Ref ref) {
|
||||
final registry = PreviewControllerRegistry(
|
||||
ref.read(runtimeConnectionProvider),
|
||||
onChanged: () => scheduleMicrotask(() {
|
||||
if (ref.mounted) ref.notifyListeners();
|
||||
}),
|
||||
);
|
||||
ref.onDispose(registry.dispose);
|
||||
return registry;
|
||||
@@ -21,9 +24,10 @@ PreviewControllerRegistry previewControllerRegistry(Ref ref) {
|
||||
/// Owns native preview controllers independently of the currently visible
|
||||
/// timeline. Prepared controllers make timeline selection a synchronous swap.
|
||||
final class PreviewControllerRegistry {
|
||||
PreviewControllerRegistry(this._runtime);
|
||||
PreviewControllerRegistry(this._runtime, {this._onChanged});
|
||||
|
||||
final CutdexRuntime _runtime;
|
||||
final void Function()? _onChanged;
|
||||
final _controllers = <(String, String), PreviewController>{};
|
||||
final _preparing = <(String, String), Future<PreviewController>>{};
|
||||
bool _disposed = false;
|
||||
@@ -39,10 +43,10 @@ final class PreviewControllerRegistry {
|
||||
if (sequence == null || timeline.sequenceDurationTicks(sequence) == 0) {
|
||||
return null;
|
||||
}
|
||||
final cached = _controllers[ids];
|
||||
if (cached != null) return cached;
|
||||
final pending = _preparing[ids];
|
||||
if (pending != null) return pending;
|
||||
final cached = _controllers[ids];
|
||||
if (cached != null) return cached;
|
||||
final future = _initialize(ids, timeline);
|
||||
_preparing[ids] = future;
|
||||
return future;
|
||||
@@ -58,15 +62,22 @@ final class PreviewControllerRegistry {
|
||||
viewForSequence: timeline.view,
|
||||
runtime: _runtime,
|
||||
);
|
||||
// Mount native output while initialization is pending. Android exact seeks
|
||||
// cannot complete their first frame before the SurfaceView is attached.
|
||||
_controllers[ids] = controller;
|
||||
_onChanged?.call();
|
||||
try {
|
||||
await controller.initialize();
|
||||
if (_disposed) {
|
||||
if (_disposed || !identical(_controllers[ids], controller)) {
|
||||
await controller.close();
|
||||
throw StateError('Preview registry is closed');
|
||||
}
|
||||
_controllers[ids] = controller;
|
||||
return controller;
|
||||
} catch (_) {
|
||||
if (identical(_controllers[ids], controller)) {
|
||||
_controllers.remove(ids);
|
||||
_onChanged?.call();
|
||||
}
|
||||
await controller.close().catchError((Object _) {});
|
||||
rethrow;
|
||||
} finally {
|
||||
@@ -76,6 +87,7 @@ final class PreviewControllerRegistry {
|
||||
|
||||
Future<void> invalidate((String, String) ids) async {
|
||||
final controller = _controllers.remove(ids);
|
||||
if (controller != null) _onChanged?.call();
|
||||
if (controller != null) await controller.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,4 +55,4 @@ final class PreviewControllerRegistryProvider
|
||||
}
|
||||
|
||||
String _$previewControllerRegistryHash() =>
|
||||
r'ec6788d52acb279d31cd745f0e244d604f09a890';
|
||||
r'2ca41396aa3bffe169b2dff87753440aac6ff33a';
|
||||
Reference in new issue
Block a user