Skip to content

Commit

Permalink
Merge branch 'main' into fix/missing-package-info
Browse files Browse the repository at this point in the history
  • Loading branch information
BLKKKBVSIK authored Dec 29, 2023
2 parents 509ffb3 + d03c93a commit e80f371
Show file tree
Hide file tree
Showing 70 changed files with 689 additions and 519 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
flutter 3.16.0-stable
flutter 3.16.4-stable
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,22 @@ Translations are managed using [Weblate](https://hosted.weblate.org/projects/ubu

[Install Flutter](https://flutter.dev/docs/get-started/install/linux) - the currently used version is specified in `.tool-versions`. If you're using [asdf](https://asdf-vm.com/) to manage your Flutter SDK, you can simply run `asdf install` to install the required version.

Even though this repo currently consists of only a single package we provide a [Melos](https://docs.page/invertase/melos) configuration to make it straightforward to execute common tasks.
Install the [Flutter Linux prerequisites](https://docs.flutter.dev/get-started/install/linux#linux-prerequisites)

We provide a [Melos](https://docs.page/invertase/melos) configuration to make it straightforward to execute common tasks.

Install Melos:
```
dart pub global activate melos
```

Bootstrap the monorepo:
```
melos bootstrap
```

`melos bootstrap` connects all the local packages/apps to each other with the help of `pubspec_overrides.yaml` files, and it also runs `pub get` in all packages/apps.

### Building and running the binaries

You can run the application with
Expand Down
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.16.4

dev_dependencies:
ubuntu_lints: ^0.3.0

scripts:
# analyze all packages
analyze: >
Expand Down
2 changes: 1 addition & 1 deletion packages/app_center/assets/app-center.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Type=Application
Version=1.0
Exec=snap-store %U
Icon=software-store
Icon=bin/data/flutter_assets/assets/app-center.png
Terminal=false
Categories=System;Utility;PackageManager;SoftwareManagement;Network;Settings;
Keywords=Ubuntu;Applications;Apps;Store;Software;Snaps;
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
Loading

0 comments on commit e80f371

Please sign in to comment.