Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions packages/app_center/lib/manage/manage_app_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,31 @@ class ManageAppActions extends ConsumerWidget {
);
}

/// Builds snap action buttons using the per-snap [SnapModel]. Shows a loading
/// indicator while the snap model loads, an active change status when a snapd
/// operation is in progress, or the appropriate action buttons (update, open,
/// remove) otherwise.
/// Builds snap action buttons. Uses data from [snap] directly for display
/// decisions to avoid creating per-snap [SnapModel] instances on each tile.
/// Only creates a [SnapModel] when an action is actually performed.
Widget _buildSnapActions(
BuildContext context,
WidgetRef ref,
AppLocalizations l10n,
Snap snap,
String? updateVersion,
) {
final snapModel = ref.watch(snapModelProvider(snap.name));
if (!snapModel.hasValue) {
return const Center(
child: SizedBox.square(
dimension: kLoaderMediumHeight,
child: YaruCircularProgressIndicator(),
),
);
}
final snapData = snapModel.value!;
final shouldQuitToUpdate = snapData.localSnap?.refreshInhibit != null;
final snapViewModel = ref.watch(snapModelProvider(snap.name).notifier);
final snapLauncher = snapData.localSnap == null
? null
: ref.watch(launchProvider(snapData.localSnap!));
final canOpen = snapLauncher?.isLaunchable ?? false;
final hasActiveChange = snapData.activeChangeId != null;
final currentlyInstalling = ref.watch(currentlyInstallingModelProvider);
final activeChangeData = currentlyInstalling[snap.name];
final hasActiveChange = activeChangeData?.activeChangeId != null;

if (hasActiveChange) {
return ActiveChangeStatus(
snapName: snap.name,
activeChangeId: snapData.activeChangeId!,
activeChangeId: activeChangeData!.activeChangeId!,
);
}

final shouldQuitToUpdate = snap.refreshInhibit != null;
final canOpen = snap.apps.isNotEmpty;
final hasUpdate = updateVersion != null;

return Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -90,34 +80,26 @@ class ManageAppActions extends ConsumerWidget {
],
if (showOnlyUpdate)
OutlinedButton(
onPressed: SnapAction.update.callback(
snapData,
snapViewModel,
snapLauncher,
context,
),
onPressed: () => ref
.read(snapModelProvider(snap.name).notifier)
.refresh()
.then((_) {}),
child: Text(SnapAction.update.label(l10n)),
),
if (!showOnlyUpdate && snapData.isInstalled) ...[
if (!showOnlyUpdate) ...[
OutlinedButton(
onPressed: canOpen
? SnapAction.open.callback(
snapData,
snapViewModel,
snapLauncher,
context,
)
? () {
final launcher = ref.read(launchProvider(snap));
if (launcher.isLaunchable) launcher.open();
}
: null,
child: Text(SnapAction.open.label(l10n)),
),
const SizedBox(width: kSpacing),
OutlinedButton(
onPressed: SnapAction.remove.callback(
snapData,
snapViewModel,
snapLauncher,
context,
),
onPressed: () =>
ref.read(snapModelProvider(snap.name).notifier).remove(),
child: Text(SnapAction.remove.label(l10n)),
),
],
Expand Down
Loading