Skip to content
Open
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
22 changes: 16 additions & 6 deletions packages/app_center/lib/snapd/snap_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const _kChannelDropdownWidth = 220.0;
typedef SnapInfo = ({Widget label, Widget value});

class SnapPage extends ConsumerWidget {
const SnapPage({required this.snapName, super.key});
const SnapPage({required this.snapName, super.key, this.channel});

final String snapName;
final String? channel;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -48,11 +49,20 @@ class SnapPage extends ConsumerWidget {
}

return snap.when(
data: (snapData) => ResponsiveLayoutBuilder(
builder: (_) {
return _SnapView(snapData: snapData);
},
),
data: (snapData) {
if (channel != null &&
snapData.availableChannels?.containsKey(channel) == true &&
snapData.selectedChannel != channel) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(snapModelProvider(snapName).notifier).selectChannel(channel!);
});
}
return ResponsiveLayoutBuilder(
builder: (_) {
return _SnapView(snapData: snapData);
},
);
},
error: (error, stackTrace) => ErrorView(
error: error,
onRetry: () => ref.invalidate(storeSnapProvider(snapName)),
Expand Down
1 change: 1 addition & 0 deletions packages/app_center/lib/store/store_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class _StoreAppHome extends ConsumerWidget {
appBar: searchField,
body: SnapPage(
snapName: StoreRoutes.snapOf(settings)!,
channel: StoreRoutes.channelOf(settings),
),
),
),
Expand Down
6 changes: 4 additions & 2 deletions packages/app_center/lib/store/store_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ String? _parseRoute(List<String>? args) {

try {
if (args?.firstOrNull?.startsWith(_kUrlPrefix) ?? false) {
final snap = args!.first.split(_kUrlPrefix)[1];
final uri = Uri.parse(args!.first);
final snap = uri.host.isNotEmpty ? uri.host : uri.path.replaceAll('/', '');
final channel = uri.queryParameters['channel'];
if (snap.isNotEmpty) {
return StoreRoutes.namedSnap(name: snap);
return StoreRoutes.namedSnap(name: snap, channel: channel);
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/app_center/lib/store/store_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ abstract class StoreRoutes {
static String? snapOf(RouteSettings route) =>
Uri.parse(route.name ?? '').queryParameters['snap'];

static String? channelOf(RouteSettings route) =>
Uri.parse(route.name ?? '').queryParameters['channel'];

static String? queryOf(RouteSettings route) =>
Uri.parse(route.name ?? '').queryParameters['query'];

Expand All @@ -52,8 +55,11 @@ abstract class StoreRoutes {
return namedRoute(StoreRoutes.localDeb, {'local-deb': path});
}

static String namedSnap({required String name}) {
return namedRoute(StoreRoutes.snap, {'snap': name});
static String namedSnap({required String name, String? channel}) {
return namedRoute(StoreRoutes.snap, {
'snap': name,
if (channel != null) 'channel': channel,
});
}

static String namedSearch({String? query, String? category}) {
Expand Down
22 changes: 22 additions & 0 deletions packages/app_center/test/initial_route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ void main() {
verify(listener(null, StoreRoutes.namedSnap(name: 'bar'))).called(1);
});

test('snap url with channel', () {
final container = ProviderContainer(
overrides: [
commandLineProvider
.overrideWith((ref) => ['snap://bar?channel=preview/stable']),
],
);
addTearDown(container.dispose);

final listener = MockInitialRouteListener();
container.listen<String?>(
initialRouteProvider,
listener.call,
fireImmediately: true,
);

verify(listener(
null,
StoreRoutes.namedSnap(name: 'bar', channel: 'preview/stable'),
)).called(1);
});

test('local debian package', () {
final container = ProviderContainer(
overrides: [
Expand Down
12 changes: 12 additions & 0 deletions packages/app_center/test/store_routes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ void main() {
expect(StoreRoutes.routeOf(snap), equals('/snap'));
expect(StoreRoutes.isSnap(snap), isTrue);
expect(StoreRoutes.snapOf(snap), equals('foo'));
expect(StoreRoutes.channelOf(snap), isNull);
expect(StoreRoutes.isSearch(snap), isFalse);
expect(StoreRoutes.queryOf(snap), isNull);
expect(StoreRoutes.categoryOf(snap), isNull);
expect(StoreRoutes.isDeb(snap), isFalse);
expect(StoreRoutes.debOf(snap), isNull);

const snapWithChannel =
RouteSettings(name: '/snap?snap=foo&channel=latest/edge');
expect(StoreRoutes.routeOf(snapWithChannel), equals('/snap'));
expect(StoreRoutes.isSnap(snapWithChannel), isTrue);
expect(StoreRoutes.snapOf(snapWithChannel), equals('foo'));
expect(StoreRoutes.channelOf(snapWithChannel), equals('latest/edge'));

const search = RouteSettings(name: '/search?query=bar&category=qux');
expect(StoreRoutes.routeOf(search), equals('/search'));
expect(StoreRoutes.isSnap(search), isFalse);
Expand Down Expand Up @@ -64,6 +72,10 @@ void main() {
);

expect(StoreRoutes.namedSnap(name: 'foo'), equals('/snap?snap=foo'));
expect(
StoreRoutes.namedSnap(name: 'foo', channel: 'latest/edge'),
equals('/snap?snap=foo&channel=latest%2Fedge'),
);
expect(
StoreRoutes.namedSearch(query: 'bar', category: 'qux'),
equals('/search?query=bar&category=qux'),
Expand Down
Loading