Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate manage snaps providers #1737

Merged
merged 20 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/app_center/lib/manage/manage_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ManageModel extends _$ManageModel {
Future<ManageSnapsData> build() async {
final installedSnaps = await _snapd.getSnaps();
final refreshableSnapNames =
(await ref.watch(updatesModelProvider.future)).snapNames;
(await ref.watch(updatesModelProvider.future).onError((_, __) => []))
.snapNames;
return ManageSnapsData(
installedSnaps: installedSnaps,
refreshableSnapNames: refreshableSnapNames,
Expand Down
2 changes: 1 addition & 1 deletion packages/app_center/lib/manage/manage_model.g.dart

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

9 changes: 5 additions & 4 deletions packages/app_center/lib/manage/manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ class _ActionButtons extends ConsumerWidget {
),
),
PushButton.elevated(
onPressed:
!updatesInProgress && (updatesModel.value?.isNotEmpty ?? false)
? ref.read(updatesModelProvider.notifier).updateAll
: null,
onPressed: ref.watch(updatesModelProvider).whenOrNull(
data: (updates) => updates.isNotEmpty && updateChangeId == null
? ref.read(updatesModelProvider.notifier).updateAll
: null,
),
child: updateChangeId != null
? Consumer(
builder: (context, ref, child) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app_center/lib/snapd/snap_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SnapModel extends _$SnapModel {
} on SnapdException catch (e) {
// Since the snap is just not installed when 'snap-not-found is thrown we
// can ignore this exception.
if (e.kind != 'snap-not-found') rethrow;
if (e.kind != 'snap-not-found' && e.kind != null) rethrow;
spydon marked this conversation as resolved.
Show resolved Hide resolved
}

final storeSnap = await ref
Expand Down
2 changes: 1 addition & 1 deletion packages/app_center/lib/snapd/snap_model.g.dart

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

9 changes: 6 additions & 3 deletions packages/app_center/lib/snapd/updates_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ final updateChangeIdProvider = StateProvider<String?>((_) => null);
@Riverpod(keepAlive: true)
bool hasUpdate(HasUpdateRef ref, String snapName) {
final updatesModel = ref.watch(updatesModelProvider);
return updatesModel.value?.any((s) => s.name == snapName) ?? false;
return updatesModel.whenOrNull(
data: (snaps) => snaps.any((s) => s.name == snapName),
) ??
false;
}

@Riverpod(keepAlive: true)
Expand All @@ -25,8 +28,8 @@ class UpdatesModel extends _$UpdatesModel {
Future<Iterable<Snap>> build() {
try {
return _snapd.find(filter: SnapFindFilter.refresh);
} on SnapdException catch (e) {
ref.read(errorStreamControllerProvider).add(e);
} on SnapdException catch (_) {
// TODO: Should we ignore all SnapdExceptions here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, with the new error handling setup, we probably shouldn't catch any errors at all here, and let them be handled by the custom error view (like here) or the top-level error dialog

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it won't work when we don't have internet though, will it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah very good point - I'm obviously contradicting myself here :D
But we need to somehow inform the user that we couldn't fetch updates due to network issues.

return Future.value([]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/app_center/lib/snapd/updates_model.g.dart

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

12 changes: 7 additions & 5 deletions packages/app_center/lib/store/store_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ final pages = <StorePage>[
title: Text(ManagePage.label(context)),
trailing: Consumer(
builder: (context, ref, child) {
final availableUpdates =
ref.watch(updatesModelProvider).value?.length ?? 0;
return availableUpdates > 0
? Badge(label: Text('$availableUpdates'))
: const SizedBox.shrink();
return ref.watch(updatesModelProvider).when(
data: (updates) => updates.isNotEmpty
? Badge(label: Text('${updates.length}'))
: const SizedBox.shrink(),
loading: SizedBox.shrink,
error: (_, __) => const SizedBox.shrink(),
);
},
),
),
Expand Down
Loading