Skip to content

Commit

Permalink
Merge branch 'main' into track-active-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
codinesh authored Jan 3, 2024
2 parents e374be4 + 9499f9a commit d105773
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/app_center/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ const kShimmerBaseLight = Color.fromARGB(120, 228, 228, 228);
const kShimmerBaseDark = Color.fromARGB(255, 51, 51, 51);
const kShimmerHighLightLight = Color.fromARGB(200, 247, 247, 247);
const kShimmerHighLightDark = Color.fromARGB(255, 57, 57, 57);

const kCircularProgressIndicatorHeight = 16.0;
2 changes: 1 addition & 1 deletion packages/app_center/lib/src/deb/deb_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DebModel extends ChangeNotifier {
AsyncValue<void> _state;

PackageKitPackageInfo? packageInfo;
bool get isInstalled => packageInfo!.info == PackageKitInfo.installed;
bool get isInstalled => packageInfo?.info == PackageKitInfo.installed;

Stream<PackageKitServiceError> get errorStream => packageKit.errorStream;

Expand Down
10 changes: 7 additions & 3 deletions packages/app_center/lib/src/deb/deb_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:app_center/appstream.dart';
import 'package:app_center/constants.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/src/deb/deb_model.dart';
Expand Down Expand Up @@ -79,7 +80,7 @@ class _DebView extends StatelessWidget {
final debInfos = <AppInfo>[
(
label: l10n.snapPageVersionLabel,
value: Text(debModel.packageInfo!.packageId.version)
value: Text(debModel.packageInfo?.packageId.version ?? '')
),
if (debModel.component.urls.isNotEmpty)
(
Expand Down Expand Up @@ -173,7 +174,7 @@ class _DebActionButtons extends ConsumerWidget {
.whenOrNull(data: (data) => data);
return Center(
child: SizedBox.square(
dimension: 16,
dimension: kCircularProgressIndicatorHeight,
child: YaruCircularProgressIndicator(
value: (transaction?.percentage ?? 0) / 100.0,
strokeWidth: 2,
Expand All @@ -195,7 +196,10 @@ class _DebActionButtons extends ConsumerWidget {
mainAxisSize: MainAxisSize.min,
overflowButtonSpacing: 8,
children: [
primaryActionButton,
if (debModel.packageInfo != null)
primaryActionButton
else
Text(l10n.debPageErrorNoPackageInfo),
if (debModel.activeTransactionId != null) cancelButton
].whereNotNull().toList(),
);
Expand Down
3 changes: 2 additions & 1 deletion packages/app_center/lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
"type": "int"
}
}
}
},
"debPageErrorNoPackageInfo": "No package information found"


}
23 changes: 20 additions & 3 deletions packages/app_center/lib/src/manage/manage_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:app_center/constants.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/snapd.dart';
Expand Down Expand Up @@ -282,7 +283,7 @@ class _ActionButtons extends ConsumerWidget {
loading: () => (
l10n.managePageCheckingForUpdates,
const SizedBox(
height: 24,
height: kCircularProgressIndicatorHeight,
child: YaruCircularProgressIndicator(
strokeWidth: 4,
),
Expand All @@ -291,6 +292,9 @@ class _ActionButtons extends ConsumerWidget {
error: (_, __) => ('', const SizedBox.shrink()),
);

final updatesInprogress = updatesModel.refreshableSnapNames.isNotEmpty &&
!updatesModel.state.isLoading &&
updatesModel.activeChangeId != null;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down Expand Up @@ -328,7 +332,7 @@ class _ActionButtons extends ConsumerWidget {
return Row(
children: [
SizedBox.square(
dimension: 16,
dimension: kCircularProgressIndicatorHeight,
child: YaruCircularProgressIndicator(
value: change?.progress,
strokeWidth: 2,
Expand Down Expand Up @@ -361,6 +365,19 @@ class _ActionButtons extends ConsumerWidget {
],
),
),
const SizedBox(width: 8),
PushButton.outlined(
onPressed: updatesInprogress
? () => ref
.read(updatesModelProvider)
.cancelChange(updatesModel.activeChangeId!)
: null,
child: Text(
l10n.snapActionCancelLabel,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
);
}
Expand Down Expand Up @@ -562,7 +579,7 @@ class _ManageSnapTile extends ConsumerWidget {
return Row(
children: [
SizedBox.square(
dimension: 16,
dimension: kCircularProgressIndicatorHeight,
child: YaruCircularProgressIndicator(
value: change?.progress,
strokeWidth: 2,
Expand Down
11 changes: 9 additions & 2 deletions packages/app_center/lib/src/packagekit/packagekit_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,20 @@ class PackageKitService {
String name, [
@visibleForTesting String? architecture,
]) async {
final arch = architecture ?? await _getNativeArchitecture();
final possibleArchs = [
architecture ?? await _getNativeArchitecture(),
'all'
];
PackageKitPackageInfo? info;
await _createTransaction(
action: (transaction) => transaction.resolve([name]),
listener: (event) {
if (event is PackageKitPackageEvent && event.packageId.arch == arch) {
if (event is PackageKitPackageEvent &&
possibleArchs.contains(event.packageId.arch)) {
info = event;
} else {
log.error(
'Couldn\'t resolve package $name with architectures $possibleArchs');
}
},
).then(waitTransaction);
Expand Down
3 changes: 2 additions & 1 deletion packages/app_center/lib/src/snapd/snap_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:app_center/constants.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/ratings.dart';
Expand Down Expand Up @@ -328,7 +329,7 @@ class _SnapActionButtons extends ConsumerWidget {
return Row(
children: [
SizedBox.square(
dimension: 16,
dimension: kCircularProgressIndicatorHeight,
child: YaruCircularProgressIndicator(
value: change?.progress,
strokeWidth: 2,
Expand Down
22 changes: 22 additions & 0 deletions packages/app_center/lib/src/snapd/updates_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,26 @@ class UpdatesModel extends ChangeNotifier {
_activeChangeId = null;
await refresh();
}

Future<void> cancelChange(String changeId) async {
if (changeId.isEmpty) return;

try {
final changeDetails = await snapd.getChange(changeId);

// If the change is already completed, ignore silently.
// If it wouldn't be ignored, an error would be displayed to the user,
// which might be confusing.
if (changeDetails.ready) {
return;
}

final abortChange = await snapd.abortChange(changeId);
await snapd.waitChange(abortChange.id);
_activeChangeId = null;
notifyListeners();
} on SnapdException catch (e) {
_handleError(e);
}
}
}
28 changes: 28 additions & 0 deletions packages/app_center/test/manage_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,34 @@ void main() {
);
});

testWidgets('cancel refresh all', (tester) async {
final mockUpdatesModel = createMockUpdatesModel(
refreshableSnapNames: refreshableSnaps.map((snap) => snap.name),
isBusy: true,
);

await tester.pumpApp(
(_) => ProviderScope(
overrides: [
launchProvider.overrideWith((_, __) => createMockSnapLauncher()),
manageModelProvider.overrideWith(
(_) => createMockManageModel(
refreshableSnaps: refreshableSnaps,
),
),
snapModelProvider.overrideWith((_, __) => snapModel),
updatesModelProvider.overrideWith((_) => mockUpdatesModel),
],
child: const ManagePage(),
),
);
await tester.pump();

final cancelButton = find.buttonWithText(tester.l10n.snapActionCancelLabel);
expect(cancelButton, findsOneWidget);
expect(cancelButton, isEnabled);
});

testWidgets('error dialog', (tester) async {
await tester.pumpApp(
(_) => ProviderScope(
Expand Down
23 changes: 23 additions & 0 deletions packages/app_center/test/packagekit_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ void main() {
final info = await packageKit.resolve('foo', 'amd64');
expect(info!.packageId.arch, equals('amd64'));
});

test('architecture \'all\'', () async {
final mockTransaction = createMockPackageKitTransaction(
events: const [
PackageKitPackageEvent(
info: PackageKitInfo.available,
packageId: PackageKitPackageId(
name: 'foo',
version: '1.0',
arch: 'all',
),
summary: 'summary',
),
],
);
final mockClient =
createMockPackageKitClient(transaction: mockTransaction);
final packageKit =
PackageKitService(dbus: createMockDbusClient(), client: mockClient);
await packageKit.activateService();
final info = await packageKit.resolve('foo', 'all');
expect(info!.packageId.arch, equals('all'));
});
});

test('cancel', () async {
Expand Down
10 changes: 10 additions & 0 deletions packages/app_center/test/test_utils.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,16 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel {
returnValueForMissingStub: _i14.Future<void>.value(),
) as _i14.Future<void>);

@override
_i14.Future<void> cancelChange(String? changeId) => (super.noSuchMethod(
Invocation.method(
#cancelChange,
[changeId],
),
returnValue: _i14.Future<void>.value(),
returnValueForMissingStub: _i14.Future<void>.value(),
) as _i14.Future<void>);

@override
void addListener(_i15.VoidCallback? listener) => super.noSuchMethod(
Invocation.method(
Expand Down

0 comments on commit d105773

Please sign in to comment.