Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
70 lines
2.2 KiB
Dart
70 lines
2.2 KiB
Dart
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:cutdex_ui/icons.dart';
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
import '../../integrations/runtime/processing_resource_repository.dart';
|
|
import '../../workspace/background_task_registry.dart';
|
|
import '../../shared/widgets/listenable_selector.dart';
|
|
import '../../integrations/runtime/processing_resource_state.dart';
|
|
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
import '../media/background_tasks_dialog.dart';
|
|
|
|
class BackgroundTasksButton extends ConsumerWidget {
|
|
const BackgroundTasksButton({
|
|
super.key,
|
|
this.iconSize = AppIconSize.header,
|
|
this.alignment = AlignmentDirectional.bottomStart,
|
|
});
|
|
|
|
final double iconSize;
|
|
final AlignmentGeometry alignment;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final registry = ref.watch(backgroundTaskRegistryProvider);
|
|
final resources = ref
|
|
.watch(processingResourceRepositoryProvider)
|
|
.asData
|
|
?.value;
|
|
final downloads = resources == null
|
|
? null
|
|
: ref.watch(
|
|
processingResourcesProvider(resources).select(
|
|
(downloads) =>
|
|
downloads.subtitleDownloading ||
|
|
downloads.installs.any(
|
|
(install) =>
|
|
install.state == ProcessingResourceState.downloading,
|
|
),
|
|
),
|
|
);
|
|
Widget button(VoidCallback toggle, bool running) => IconButton(
|
|
key: const ValueKey('background-tasks-button'),
|
|
tooltip: context.l10n.backgroundTasks,
|
|
onPressed: toggle,
|
|
icon: Badge(
|
|
isLabelVisible: running || downloads == true,
|
|
child: Icon(AppIcons.success, size: iconSize),
|
|
),
|
|
);
|
|
return ListenableSelector<bool>(
|
|
listenable: registry,
|
|
select: () => registry.runningCount > 0,
|
|
builder: (context, running) => AppPopover(
|
|
width: 384,
|
|
alignment: alignment,
|
|
builder: (_, toggle) => button(toggle, running),
|
|
child: BackgroundTasksContent(
|
|
registry: registry,
|
|
repository: resources,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|