Skip to content

Commit

Permalink
Merge pull request #1764 from ubuntu/fix/show-loader-in-check-button
Browse files Browse the repository at this point in the history
fix: Show loader in "Check for updates"-button
  • Loading branch information
spydon authored Aug 16, 2024
2 parents d33d1f6 + 1da1cfe commit 5e0c661
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
17 changes: 14 additions & 3 deletions packages/app_center/lib/manage/manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,31 @@ class _ActionButtons extends ConsumerWidget {
ref.watch(currentlyRefreshAllSnapsProvider).isNotEmpty;
final hasInternet = updatesModel.value?.hasInternet ?? true;
final isLoading = updatesModel.isLoading || localSnapsModel.isLoading;
final isSilentlyCheckingUpdates =
ref.watch(isSilentlyiCheckingUpdatesProvider);

return Wrap(
spacing: 10,
runSpacing: 10,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
PushButton.outlined(
onPressed: isRefreshingAll || updatesModel.hasError || isLoading
onPressed: isRefreshingAll ||
updatesModel.hasError ||
isLoading ||
isSilentlyCheckingUpdates
? null
: () => ref.refresh(updatesModelProvider),
: ref.read(updatesModelProvider.notifier).silentUpdatesCheck,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(YaruIcons.sync),
isSilentlyCheckingUpdates
? const SizedBox(
width: 16,
height: 16,
child: YaruCircularProgressIndicator(strokeWidth: 3),
)
: const Icon(YaruIcons.sync),
const SizedBox(width: 8),
Flexible(
child: Text(
Expand Down
26 changes: 24 additions & 2 deletions packages/app_center/lib/manage/updates_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SnapListState with _$SnapListState {
}

final currentlyRefreshAllSnapsProvider = StateProvider<List<String>>((_) => []);
final isSilentlyiCheckingUpdatesProvider = StateProvider<bool>((_) => false);

@Riverpod(keepAlive: true)
bool hasUpdate(HasUpdateRef ref, String snapName) {
Expand All @@ -57,13 +58,34 @@ class UpdatesModel extends _$UpdatesModel {

@override
Future<SnapListState> build() async {
final result = await connectionCheck(
final result = fetchRefreshableSnaps();
return result;
}

Future<void> silentUpdatesCheck() async {
ref.read(isSilentlyiCheckingUpdatesProvider.notifier).state = true;
try {
final newSnapListState = await fetchRefreshableSnaps();
final isSameList = const ListEquality().equals(
state.valueOrNull?.snaps.toList() ?? [],
newSnapListState.snaps.toList(),
);
if (!isSameList ||
newSnapListState.hasInternet != state.valueOrNull?.hasInternet) {
state = AsyncData(newSnapListState);
}
} finally {
ref.read(isSilentlyiCheckingUpdatesProvider.notifier).state = false;
}
}

Future<SnapListState> fetchRefreshableSnaps() {
return connectionCheck(
() => _snapd
.find(filter: SnapFindFilter.refresh)
.then((snaps) => snaps.where((s) => s.name != kSnapName)),
ref,
);
return result;
}

/// Used to remove a snap from the list without reloading the whole provider.
Expand Down
2 changes: 1 addition & 1 deletion packages/app_center/lib/manage/updates_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e0c661

Please sign in to comment.