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

chore: Update to ubuntu_lints v0.3.0 #1526

Merged
merged 2 commits into from
Dec 12, 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
9 changes: 9 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: app_center
packages:
- packages/**

command:
bootstrap:
environment:
sdk: '>=3.1.0 <4.0.0'
flutter: 3.13.9

dev_dependencies:
ubuntu_lints: ^0.3.0

scripts:
# analyze all packages
analyze: >
Expand Down
4 changes: 2 additions & 2 deletions packages/app_center/lib/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ enum ResponsiveLayoutType {

class ResponsiveLayout extends InheritedWidget {
ResponsiveLayout({
super.key,
required this.constraints,
required super.child,
super.key,
}) {
final (cardColumnCount, cardSize, snapInfoColumnCount, type) =
switch (constraints.maxWidth + kPaneWidth + 1) {
Expand Down Expand Up @@ -74,7 +74,7 @@ class ResponsiveLayout extends InheritedWidget {
}

class ResponsiveLayoutBuilder extends LayoutBuilder {
ResponsiveLayoutBuilder({super.key, required WidgetBuilder builder})
ResponsiveLayoutBuilder({required WidgetBuilder builder, super.key})
: super(
builder: (context, constraints) => ResponsiveLayout(
constraints: constraints,
Expand Down
21 changes: 10 additions & 11 deletions packages/app_center/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import 'dart:async';
import 'dart:io';

import 'package:app_center/appstream.dart';
import 'package:app_center/config.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/packagekit.dart';
import 'package:app_center/ratings.dart';
import 'package:app_center/snapd.dart';
import 'package:app_center/store.dart';
import 'package:app_center_ratings_client/app_center_ratings_client.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -14,14 +21,6 @@ import 'package:ubuntu_service/ubuntu_service.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;
import 'package:yaru_widgets/yaru_widgets.dart';

import 'appstream.dart';
import 'config.dart';
import 'l10n.dart';
import 'packagekit.dart';
import 'ratings.dart';
import 'snapd.dart';
import 'store.dart';

Future<void> main(List<String> args) async {
await YaruWindowTitleBar.ensureInitialized();

Expand Down Expand Up @@ -54,7 +53,7 @@ Future<void> main(List<String> args) async {
registerServiceInstance(config);
registerServiceInstance(ratings);

registerService(() => GitHub());
registerService(GitHub.new);
registerService(() => GtkApplicationNotifier(args));

final appstream = AppstreamService();
Expand All @@ -63,8 +62,8 @@ Future<void> main(List<String> args) async {
unawaited(appstream.init());
registerServiceInstance(appstream);

registerService(() => PackageKitClient());
registerService(() => PackageKitService(),
registerService(PackageKitClient.new);
registerService(PackageKitService.new,
dispose: (service) => service.dispose());

await initDefaultLocale();
Expand Down
13 changes: 6 additions & 7 deletions packages/app_center/lib/src/about/about_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import 'package:app_center/constants.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/src/about/about_providers.dart';
import 'package:app_center/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -7,12 +12,6 @@ import 'package:url_launcher/url_launcher_string.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '/constants.dart';
import '/l10n.dart';
import '/layout.dart';
import '/widgets.dart';
import 'about_providers.dart';

class AboutPage extends StatelessWidget {
const AboutPage({super.key});

Expand Down Expand Up @@ -120,7 +119,7 @@ class _ContributorView extends ConsumerWidget {
Text(l10n.aboutPageContributorTitle),
const SizedBox(height: 8),
state.when(
data: (contributors) => _ContributorWrap(contributors),
data: _ContributorWrap.new,
error: (error, stackTrace) => Text(error.toString()),
loading: () => Shimmer.fromColors(
baseColor: light ? kShimmerBaseLight : kShimmerBaseDark,
Expand Down
4 changes: 2 additions & 2 deletions packages/app_center/lib/src/about/about_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:package_info_plus/package_info_plus.dart';

import 'package:ubuntu_service/ubuntu_service.dart';

final contributorsProvider =
FutureProvider.autoDispose.family((ref, String repo) async {
final contributorsProvider = FutureProvider.autoDispose
.family<List<Contributor>, String>((ref, repo) async {
const designers = {'anasereijo', 'elioqoshi', 'Zoospora'};
const exclude = {'weblate'};
final contributors = await getService<GitHub>()
Expand Down
3 changes: 1 addition & 2 deletions packages/app_center/lib/src/appstream/appstream_search.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:app_center/appstream.dart';
import 'package:appstream/appstream.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ubuntu_service/ubuntu_service.dart';

import '/appstream.dart';

final appstreamSearchProvider =
StreamProvider.family<List<AppstreamComponent>, String>(
(ref, query) async* {
Expand Down
78 changes: 38 additions & 40 deletions packages/app_center/lib/src/appstream/appstream_service.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import 'dart:collection';

import 'package:app_center/l10n.dart';
import 'package:app_center/src/appstream/appstream_utils.dart';
import 'package:app_center/src/appstream/logger.dart';
import 'package:appstream/appstream.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:snowball_stemmer/snowball_stemmer.dart';

import '/l10n.dart';
import 'appstream_utils.dart';
import 'logger.dart';

@immutable
class _CachedComponent {
final AppstreamComponent component;
final String id;
final String name;
final List<String> keywords;
final List<String> summary;
final List<String> description;
final String origin;
final String package;
final List<String> mediaTypes;

_CachedComponent(
this.component,
this.id,
this.name,
this.keywords,
this.summary,
this.description,
this.origin,
this.package,
this.mediaTypes);
const _CachedComponent(
this.component,
this.id,
this.name,
this.keywords,
this.summary,
this.description,
this.origin,
this.package,
this.mediaTypes,
);

factory _CachedComponent.fromAppstream(AppstreamComponent component) {
final id = component.getId();
Expand Down Expand Up @@ -59,9 +50,18 @@ class _CachedComponent {
return _CachedComponent(component, id, name, keywords, summary, description,
origin, package, mediaTypes);
}
final AppstreamComponent component;
final String id;
final String name;
final List<String> keywords;
final List<String> summary;
final List<String> description;
final String origin;
final String package;
final List<String> mediaTypes;

int match(List<String> tokens) {
int score = _MatchScore.none.value;
var score = _MatchScore.none.value;

for (final token in tokens) {
if (id.contains(token)) {
Expand Down Expand Up @@ -113,28 +113,18 @@ enum _MatchScore {
id(1 << 7),
all(1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7);

final int value;

const _MatchScore(this.value);

final int value;
}

class _ScoredComponent {
const _ScoredComponent(this.score, this.component);
final int score;
final AppstreamComponent component;

const _ScoredComponent(this.score, this.component);
}

class AppstreamService {
final AppstreamPool _pool;
late final Future<void> _loader = _pool.load().then((_) {
_populateCache();
_initialized = true;
});

bool get initialized => _initialized;
bool _initialized = false;

// TODO: cache AppstreamPool
AppstreamService({@visibleForTesting AppstreamPool? pool})
: _pool = pool ?? AppstreamPool(),
Expand All @@ -144,6 +134,14 @@ class AppstreamService {
_populateCache();
};
}
final AppstreamPool _pool;
late final Future<void> _loader = _pool.load().then((_) {
_populateCache();
_initialized = true;
});

bool get initialized => _initialized;
bool _initialized = false;

final HashSet<_CachedComponent> _cache = HashSet<_CachedComponent>();

Expand Down Expand Up @@ -219,15 +217,15 @@ class AppstreamService {
}
// Filter out short tokens, and those containing markup
words.removeWhere(
(element) => element.length <= 1 || element.contains(RegExp(r'[<>()]')),
(element) => element.length <= 1 || element.contains(RegExp('[<>()]')),
);
// Extract only the common stems from the tokens
final algorithm =
stemmersMap[PlatformDispatcher.instance.locale.languageCode];
if (algorithm != null) {
final stemmer = SnowballStemmer(algorithm);
return words
.map((element) => stemmer.stem(element))
.map(stemmer.stem)
// Keep original tokens as well, since the stemming algorithm might
// have unintended effects. See #1305.
.followedBy(words)
Expand Down
7 changes: 3 additions & 4 deletions packages/app_center/lib/src/appstream/appstream_utils.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:ui';

import 'package:app_center/l10n.dart';
import 'package:appstream/appstream.dart';
import 'package:collection/collection.dart';

import '/l10n.dart';

extension _GetOrDefault<K, V> on Map<K, V> {
V getOrDefault(K? key, V fallback) {
if (key == null) {
Expand Down Expand Up @@ -45,7 +44,7 @@ extension LocalizedComponent on AppstreamComponent {
}

List<String> getLocalizedMediaTypes() {
final List<String> mediaTypes = [];
final mediaTypes = <String>[];

for (final provider in provides) {
if (provider is AppstreamProvidesMediatype) {
Expand All @@ -68,7 +67,7 @@ extension LocalizedComponent on AppstreamComponent {
final candidates = [fullLocale, languageCode, fallback];
final keys = keyedByLanguage.keys;

for (final String candidate in candidates) {
for (final candidate in candidates) {
if (keys.contains(candidate)) return candidate;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/app_center/lib/src/deb/deb_model.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'dart:async';

import 'package:app_center/appstream.dart';
import 'package:app_center/packagekit.dart';
import 'package:appstream/appstream.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:packagekit/packagekit.dart';
import 'package:ubuntu_service/ubuntu_service.dart';

import '/appstream.dart';
import '/packagekit.dart';

final debModelProvider =
ChangeNotifierProvider.family.autoDispose<DebModel, String>(
(ref, id) => DebModel(
Expand Down
15 changes: 7 additions & 8 deletions packages/app_center/lib/src/deb/deb_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import 'dart:async';

import 'package:app_center/appstream.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/src/deb/deb_model.dart';
import 'package:app_center/src/packagekit/packagekit_service.dart';
import 'package:app_center/widgets.dart';
import 'package:appstream/appstream.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
Expand All @@ -12,17 +18,10 @@ import 'package:url_launcher/url_launcher_string.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

import '/appstream.dart';
import '/l10n.dart';
import '/layout.dart';
import '/widgets.dart';
import '../packagekit/packagekit_service.dart';
import 'deb_model.dart';

const _kPrimaryButtonMaxWidth = 136.0;

class DebPage extends ConsumerStatefulWidget {
const DebPage({super.key, required this.id});
const DebPage({required this.id, super.key});
final String id;

@override
Expand Down
17 changes: 8 additions & 9 deletions packages/app_center/lib/src/explore/explore_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/snapd.dart';
import 'package:app_center/store.dart';
import 'package:app_center/widgets.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:snapd/snapd.dart';
import 'package:yaru_icons/yaru_icons.dart';

import '/l10n.dart';
import '/layout.dart';
import '/snapd.dart';
import '/store.dart';
import '/widgets.dart';

const kNumberOfBannerSnaps = 3;

class ExplorePage extends ConsumerWidget {
Expand Down Expand Up @@ -164,8 +163,8 @@ class _CategoryBanner extends ConsumerWidget {
.whenOrNull(data: (data) => data);
final featuredSnaps = category.featuredSnapNames != null
? category.featuredSnapNames!
.map((name) =>
snaps?.singleWhereOrNull(((snap) => snap.name == name)))
.map(
(name) => snaps?.singleWhereOrNull((snap) => snap.name == name))
.whereNotNull()
: snaps;
final l10n = AppLocalizations.of(context);
Expand All @@ -184,9 +183,9 @@ class _Banner extends StatelessWidget {
const _Banner({
required this.snaps,
required this.slogan,
required this.colors,
this.buttonLabel,
this.onPressed,
required this.colors,
});

final Iterable<Snap> snaps;
Expand Down
Loading