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

feat(manage): show progress in 'update all' button #1333

Merged
merged 5 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/snapd.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'src/snapd/snap_category_enum.dart';
export 'src/snapd/snap_l10n.dart';
export 'src/snapd/snap_launcher.dart';
export 'src/snapd/snap_model.dart';
export 'src/snapd/snapd_service.dart';
Expand Down
17 changes: 0 additions & 17 deletions lib/src/detail/detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,3 @@ class _ChannelDropdownEntry extends StatelessWidget {
);
}
}

extension SnapdChangeL10n on SnapdChange {
String? localize(AppLocalizations l10n) => switch (kind) {
'install-snap' => l10n.snapActionInstallingLabel,
'remove-snap' => l10n.snapActionRemovingLabel,
_ => null,
};
}

extension SnapConfinementL10n on SnapConfinement {
String localize(AppLocalizations l10n) => switch (this) {
SnapConfinement.classic => l10n.snapConfinementClassic,
SnapConfinement.devmode => l10n.snapConfinementDevmode,
SnapConfinement.strict => l10n.snapConfinementStrict,
_ => name,
};
}
1 change: 1 addition & 0 deletions lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"snapActionRemovingLabel": "Uninstalling",
"snapActionSwitchChannelLabel": "Switch Channel",
"snapActionUpdateLabel": "Update",
"snapActionUpdatingLabel": "Updating",
"snapCategoryArtAndDesign": "Art and Design",
"snapCategoryBooksAndReference": "Books and Reference",
"snapCategoryDefaultButtonLabel": "Discover more",
Expand Down
62 changes: 47 additions & 15 deletions lib/src/manage/manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class _ManageView extends ConsumerWidget {
}
}

// TODO: refactor/generalize - similar to `_SnapActionButtons`
class _ActionButtons extends ConsumerWidget {
const _ActionButtons();

Expand All @@ -152,7 +153,8 @@ class _ActionButtons extends ConsumerWidget {
mainAxisSize: MainAxisSize.min,
children: [
PushButton.outlined(
onPressed: ref.read(updatesModelProvider).refresh,
onPressed:
updatesModel.activeChangeId != null ? null : updatesModel.refresh,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -170,23 +172,53 @@ class _ActionButtons extends ConsumerWidget {
),
const SizedBox(width: 8),
PushButton.elevated(
onPressed: updatesModel.refreshableSnapNames.isNotEmpty
onPressed: updatesModel.refreshableSnapNames.isNotEmpty &&
!updatesModel.state.isLoading
? ref.read(updatesModelProvider).updateAll
: null,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(YaruIcons.download),
const SizedBox(width: 8),
Flexible(
child: Text(
l10n.managePageUpdateAllLabel,
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: updatesModel.activeChangeId != null
? Consumer(
builder: (context, ref, child) {
final change = ref

Choose a reason for hiding this comment

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

Another honest question: change can never be null if updatesModel.activeChangeId is not null, can it?

Choose a reason for hiding this comment

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

Just to double check my understanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's null while the changeProvider, which gives an AsyncValue<SnapdChange>, is fetching the data from snapd

.watch(changeProvider(updatesModel.activeChangeId))
.whenOrNull(data: (data) => data);
return Row(
children: [
SizedBox.square(
dimension: 16,
child: YaruCircularProgressIndicator(
value: change?.progress,
strokeWidth: 2,
),
),
if (change != null) ...[
const SizedBox(width: 8),
Flexible(
child: Text(
change.localize(l10n) ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
]
],
);
},
)
: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(YaruIcons.download),
const SizedBox(width: 8),
Flexible(
child: Text(
l10n.managePageUpdateAllLabel,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
),
),
],
);
Expand Down
21 changes: 21 additions & 0 deletions lib/src/snapd/snap_l10n.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:snapd/snapd.dart';

import '/l10n.dart';

extension SnapdChangeL10n on SnapdChange {
String? localize(AppLocalizations l10n) => switch (kind) {
'install-snap' => l10n.snapActionInstallingLabel,
'refresh-snap' => l10n.snapActionUpdatingLabel,
'remove-snap' => l10n.snapActionRemovingLabel,
_ => null,
};
}

extension SnapConfinementL10n on SnapConfinement {
String localize(AppLocalizations l10n) => switch (this) {
SnapConfinement.classic => l10n.snapConfinementClassic,
SnapConfinement.devmode => l10n.snapConfinementDevmode,
SnapConfinement.strict => l10n.snapConfinementStrict,
_ => name,
};
}
2 changes: 2 additions & 0 deletions test/detail_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,6 @@ void main() {
expect(find.text(tester.l10n.snapActionInstallLabel), findsNothing);
expect(find.byType(YaruCircularProgressIndicator), findsOneWidget);
});

// TODO: test loading states with snap change in progress
}
2 changes: 2 additions & 0 deletions test/manage_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void main() {
await tester.tap(openButton);
verify(snapLauncher.open()).called(1);
});

// TODO: test loading states with snap change in progress
}

extension on CommonFinders {
Expand Down
1 change: 1 addition & 0 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ MockUpdatesModel createMockUpdatesModel(
when(model.hasUpdate(any)).thenAnswer((i) =>
refreshableSnapNames?.contains(i.positionalArguments.single) ?? false);
when(model.state).thenReturn(AsyncValue.data(() {}()));
when(model.activeChangeId).thenReturn(null);
return model;
}

Expand Down