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.
66 lines
1.9 KiB
Dart
66 lines
1.9 KiB
Dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import '../../integrations/app_updates.dart';
|
|
import '../../integrations/app_update_coordinator.dart';
|
|
import '../../settings/settings_operation.dart';
|
|
|
|
part 'update_controller.g.dart';
|
|
|
|
@riverpod
|
|
class UpdateController extends _$UpdateController {
|
|
int _eventRevision = 0;
|
|
UpdateStatus? _latestEvent;
|
|
|
|
@override
|
|
Future<UpdateStatus> build() {
|
|
ref.watch(appUpdateLifecycleProvider);
|
|
final subscription = ref.watch(appUpdateBridgeProvider).events.listen((
|
|
status,
|
|
) {
|
|
_eventRevision++;
|
|
_latestEvent = status;
|
|
if (ref.mounted) state = AsyncData(_latestEvent!);
|
|
});
|
|
ref.onDispose(subscription.cancel);
|
|
return _load();
|
|
}
|
|
|
|
Future<UpdateStatus> _load() async {
|
|
final revision = _eventRevision;
|
|
try {
|
|
final status = await ref.read(appUpdateBridgeProvider).status();
|
|
return revision != _eventRevision && _latestEvent != null
|
|
? _latestEvent!
|
|
: status;
|
|
} catch (_) {
|
|
return const UpdateStatus();
|
|
}
|
|
}
|
|
|
|
Future<void> check() => _invoke((bridge) => bridge.check());
|
|
Future<void> download() => _invoke((bridge) => bridge.download());
|
|
Future<void> install() async {
|
|
final link = ref.keepAlive();
|
|
try {
|
|
await ref.read(settingsOperationProvider('updates').notifier).run(
|
|
() async {
|
|
await installWindowsUpdate(ref);
|
|
},
|
|
);
|
|
} finally {
|
|
link.close();
|
|
}
|
|
}
|
|
|
|
Future<void> setAutomaticChecks(bool value) =>
|
|
_invoke((bridge) => bridge.setAutomaticChecks(value));
|
|
|
|
Future<void> _invoke(Future<void> Function(AppUpdateBridge) action) async {
|
|
await ref.read(settingsOperationProvider('updates').notifier).run(() async {
|
|
await action(ref.read(appUpdateBridgeProvider));
|
|
final next = await _load();
|
|
if (ref.mounted) state = AsyncData(next);
|
|
});
|
|
}
|
|
}
|