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

fix: correctly install/refresh classic snaps #1352

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions lib/src/detail/detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ enum SnapAction {
VoidCallback? callback(SnapModel model, [SnapLauncher? launcher]) =>
switch (this) {
cancel => model.cancel,
install => model.install,
install => model.storeSnap != null ? model.install : null,
open => launcher?.isLaunchable ?? false ? launcher!.open : null,
remove => model.remove,
switchChannel => model.refresh,
update => model.refresh,
switchChannel => model.storeSnap != null ? model.refresh : null,
update => model.storeSnap != null ? model.refresh : null,
};
}

Expand Down
24 changes: 20 additions & 4 deletions lib/src/snapd/snap_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,27 @@ class SnapModel extends ChangeNotifier {
await snapd.abortChange(activeChangeId!);
}

Future<void> install() =>
_snapAction(() => snapd.install(snapName, channel: selectedChannel));
Future<void> install() {
assert(storeSnap?.channels[selectedChannel] != null,
'install() should not be called before the store snap is available');
return _snapAction(() => snapd.install(
snapName,
channel: selectedChannel,
classic: storeSnap!.channels[selectedChannel]!.confinement ==
SnapConfinement.classic,
));
}

Future<void> refresh() =>
_snapAction(() => snapd.refresh(snapName, channel: selectedChannel));
Future<void> refresh() {
assert(storeSnap?.channels[selectedChannel] != null,
'remove() should not be called before the store snap is available');
return _snapAction(() => snapd.refresh(
snapName,
channel: selectedChannel,
classic: storeSnap!.channels[selectedChannel]!.confinement ==
SnapConfinement.classic,
));
}

Future<void> remove() => _snapAction(() => snapd.remove(snapName));
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 1.0.0-alpha
publish_to: 'none'

environment:
sdk: '3.0.5'
flutter: '3.10.5'
sdk: '^3.0.6'
flutter: '^3.10.6'

dependencies:
args: ^2.4.2
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: git
parts:
flutter-git:
source: https://github.com/flutter/flutter.git
source-tag: 3.10.5
source-tag: 3.10.6
source-depth: 1
plugin: nil
override-build: |
Expand Down
31 changes: 25 additions & 6 deletions test/snap_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ void main() {

await model.install();

verify(service.install('testsnap', channel: 'latest/stable')).called(1);
verify(service.install(
'testsnap',
channel: 'latest/stable',
classic: false,
)).called(1);
});
test('non-default channel', () async {
final service = createMockSnapdService(
Expand All @@ -111,7 +115,11 @@ void main() {
model.selectedChannel = 'latest/edge';
await model.install();

verify(service.install('testsnap', channel: 'latest/edge')).called(1);
verify(service.install(
'testsnap',
channel: 'latest/edge',
classic: true,
)).called(1);
});
});

Expand All @@ -126,7 +134,11 @@ void main() {

await model.refresh();

verify(service.refresh('testsnap', channel: 'latest/edge')).called(1);
verify(service.refresh(
'testsnap',
channel: 'latest/edge',
classic: true,
)).called(1);
});
test('switch channel', () async {
final service = createMockSnapdService(
Expand All @@ -139,7 +151,11 @@ void main() {
model.selectedChannel = 'latest/stable';
await model.refresh();

verify(service.refresh('testsnap', channel: 'latest/stable')).called(1);
verify(service.refresh(
'testsnap',
channel: 'latest/stable',
classic: false,
)).called(1);
});
});

Expand All @@ -164,8 +180,11 @@ void main() {
final changeCompleter = Completer();
final notifyCompleter = Completer();

when(service.install(any, channel: anyNamed('channel')))
.thenAnswer((_) async => 'changeId');
when(service.install(
any,
channel: anyNamed('channel'),
classic: anyNamed('classic'),
)).thenAnswer((_) async => 'changeId');
when(service.waitChange('changeId'))
.thenAnswer((_) async => await changeCompleter.future);
when(service.abortChange('changeId')).thenAnswer((_) async {
Expand Down
14 changes: 10 additions & 4 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ MockSnapdService createMockSnapdService({
kind: 'snap-not-found',
));
}
when(service.install(any, channel: anyNamed('channel')))
.thenAnswer((_) async => 'id');
when(service.refresh(any, channel: anyNamed('channel')))
.thenAnswer((_) async => 'id');
when(service.install(
any,
channel: anyNamed('channel'),
classic: anyNamed('classic'),
)).thenAnswer((_) async => 'id');
when(service.refresh(
any,
channel: anyNamed('channel'),
classic: anyNamed('classic'),
)).thenAnswer((_) async => 'id');
when(service.remove(any)).thenAnswer((_) async => 'id');
when(service.find(filter: SnapFindFilter.refresh))
.thenAnswer((_) async => refreshableSnaps ?? []);
Expand Down