-
Notifications
You must be signed in to change notification settings - Fork 109
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 away snap model from old provider style #1660
Conversation
2489a36
to
6f591ab
Compare
b2de44b
to
5946480
Compare
89dccdb
to
8fed937
Compare
// TODO: Do we really need a try-catch here, don't we want to go into | ||
// the AsyncError in all cases? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're handling the case where the snap isn't locally installed, but it's available in the store (SnapdClient
throws an exception when it receives a 4xx status from snapd).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a very smooth way of dealing with a 4xx, maybe we should fix that in the snapdclient at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all our dart client libraries for HTTP APIs do it that way at the moment.
In the subiquity client we've got this:
if (response.statusCode != 200) {
throw SubiquityException(method, response.statusCode, str);
}
But if you think it's worth improving this, I'm up for it :)
Maybe until we sort out the diff --git a/packages/app_center/lib/src/widgets/app_card.dart b/packages/app_center/lib/src/widgets/app_card.dart
index 365bf709..5948faec 100644
--- a/packages/app_center/lib/src/widgets/app_card.dart
+++ b/packages/app_center/lib/src/widgets/app_card.dart
@@ -75,6 +75,7 @@ class AppCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return YaruBanner(
+ color: Theme.of(context).cardColor,
padding: const EdgeInsets.all(kCardSpacing),
onTap: onTap,
child: Flex( P.S. We'd need a corresponding change for the |
|
5abe153
to
26b715d
Compare
enum SnapAction { | ||
cancel, | ||
install, | ||
open, | ||
remove, | ||
switchChannel, | ||
update; | ||
|
||
String label(AppLocalizations l10n) => switch (this) { | ||
cancel => l10n.snapActionCancelLabel, | ||
install => l10n.snapActionInstallLabel, | ||
open => l10n.snapActionOpenLabel, | ||
remove => l10n.snapActionRemoveLabel, | ||
switchChannel => l10n.snapActionSwitchChannelLabel, | ||
update => l10n.snapActionUpdateLabel, | ||
}; | ||
|
||
IconData? get icon => switch (this) { | ||
update => YaruIcons.refresh, | ||
remove => YaruIcons.trash, | ||
_ => null, | ||
}; | ||
|
||
VoidCallback? callback(SnapModel model, [SnapLauncher? launcher]) => | ||
switch (this) { | ||
cancel => model.cancel, | ||
install => model.storeSnap != null ? model.install : null, | ||
open => launcher?.isLaunchable ?? false ? launcher!.open : null, | ||
remove => model.remove, | ||
switchChannel => model.storeSnap != null ? model.refresh : null, | ||
update => model.storeSnap != null ? model.refresh : null, | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a final nitpick/question, since it came up in the meeting with Innes as well: to me this feels like UI specific code (maybe icons/l10n more than the actions and corresponding callbacks). Should we keep (some of) this in snap_page.dart
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't remember why I moved it now, it should maybe even get its own file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, I think this is the first big step towards a massive improvement of the overall state management and code structure!
381e159
to
a87a41f
Compare
This migrates away from the custom
ChangeNotifierProvider
approach.It also makes sure that futures aren't completed until the polling of the changeId has returned which makes the the structure slightly cleaner.
Things that are left to consider:
With a refactor this big I'm sure that some bugs have been introduced, so make sure to test a lot if you continue working on this!