Skip to content
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
26 changes: 23 additions & 3 deletions .github/workflows/pull_request_tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
name: Pull request tests

permissions:
contents: write

on: pull_request

jobs:
dart-analysis:
name: Dart analysis
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version-file: pubspec.yaml

- name: Generate source files
run: |
flutter gen-l10n
dart run build_runner build

# Switch back once https://github.com/dart-lang/sdk/issues/60236 is released
# - name: Analyze Dart
# uses: zgosalvez/github-actions-analyze-dart@v3
- name: Analyze Dart
run: dart format -o none --set-exit-if-changed .

test-android-build:
name: Test android build
runs-on: ubuntu-latest
Expand Down
56 changes: 32 additions & 24 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
include: package:very_good_analysis/analysis_options.yaml

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
formatter:
# Keep formatting consistent by automating trailing commas.
trailing_commas: automate

analyzer:
exclude:
- lib/**.g.dart

errors:
# Needed for build runner annotations (i.e., freezed, json_serializable).
invalid_annotation_target: ignore
# We don't need to document every single public member.
public_member_api_docs: ignore
# There is no auto fix for this.
sort_pub_dependencies: ignore

# Ignore for now.
avoid_dynamic_calls: ignore
avoid_catches_without_on_clauses: ignore
avoid_positional_boolean_parameters: ignore
argument_type_not_assignable: ignore
unawaited_futures: ignore
discarded_futures: ignore
parameter_assignments: ignore
lines_longer_than_80_chars: ignore
for_in_of_invalid_type: ignore
not_iterable_spread: ignore
deprecated_member_use: ignore
join_return_with_assignment: ignore
avoid_equals_and_hash_code_on_mutable_classes: ignore
return_of_invalid_type_from_closure: ignore
not_map_spread: ignore
unused_local_variable: ignore
non_bool_condition: ignore
invalid_assignment: ignore
1 change: 0 additions & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
synthetic-package: false
9 changes: 4 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:interstellar/src/app.dart';
import 'package:interstellar/src/controller/controller.dart';
import 'package:interstellar/src/controller/database/database.dart';
import 'package:interstellar/src/utils/http_client.dart';
import 'package:interstellar/src/init_push_notifications.dart';
import 'package:interstellar/src/utils/globals.dart';
import 'package:interstellar/src/utils/http_client.dart';
import 'package:interstellar/src/utils/utils.dart';
import 'package:interstellar/src/widgets/markdown/drafts_controller.dart';
import 'package:media_kit/media_kit.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';

import 'src/app.dart';
import 'src/init_push_notifications.dart';

void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
Expand All @@ -35,7 +34,7 @@ void main(List<String> args) async {
.reduce((a, b) => Size(min(a.width, b.width), min(a.height, b.height)));
final minWindowSize = screenSize / 8;

WindowOptions windowOptions = WindowOptions(minimumSize: minWindowSize);
final windowOptions = WindowOptions(minimumSize: minWindowSize);

windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
Expand Down
38 changes: 19 additions & 19 deletions lib/src/api/api.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:interstellar/src/api/bookmark.dart';
import 'package:interstellar/src/api/client.dart';
import 'package:interstellar/src/api/comments.dart';
import 'package:interstellar/src/api/domains.dart';
import 'package:interstellar/src/api/community_moderation.dart';
import 'package:interstellar/src/api/community.dart';
import 'package:interstellar/src/api/community_moderation.dart';
import 'package:interstellar/src/api/domains.dart';
import 'package:interstellar/src/api/feed.dart';
import 'package:interstellar/src/api/images.dart';
import 'package:interstellar/src/api/messages.dart';
Expand All @@ -18,6 +18,22 @@ import 'package:interstellar/src/utils/globals.dart';
import 'package:interstellar/src/utils/utils.dart';

class API {
API(this.client)
: comments = APIComments(client),
domains = MbinAPIDomains(client),
threads = APIThreads(client),
community = APICommunity(client),
communityModeration = APICommunityModeration(client),
feed = APIFeed(client),
messages = APIMessages(client),
moderation = APIModeration(client),
notifications = APINotifications(client),
microblogs = MbinAPIMicroblogs(client),
search = APISearch(client),
users = APIUsers(client),
bookmark = APIBookmark(client),
images = APIImages(client);

final ServerClient client;

final APIComments comments;
Expand All @@ -34,22 +50,6 @@ class API {
final APIUsers users;
final APIBookmark bookmark;
final APIImages images;

API(this.client)
: comments = APIComments(client),
domains = MbinAPIDomains(client),
threads = APIThreads(client),
community = APICommunity(client),
communityModeration = APICommunityModeration(client),
feed = APIFeed(client),
messages = APIMessages(client),
moderation = APIModeration(client),
notifications = APINotifications(client),
microblogs = MbinAPIMicroblogs(client),
search = APISearch(client),
users = APIUsers(client),
bookmark = APIBookmark(client),
images = APIImages(client);
}

Future<ServerSoftware?> getServerSoftware(String server) async {
Expand All @@ -59,7 +59,7 @@ Future<ServerSoftware?> getServerSoftware(String server) async {

try {
return ServerSoftware.values.byName(
((response.bodyJson['software'] as JsonMap)['name'] as String)
((response.bodyJson['software']! as JsonMap)['name']! as String)
.toLowerCase(),
);
} catch (_) {
Expand Down
24 changes: 12 additions & 12 deletions lib/src/api/bookmark.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:interstellar/src/api/client.dart';
import 'package:interstellar/src/controller/server.dart';
import 'package:interstellar/src/models/bookmark_list.dart';
import 'package:interstellar/src/models/comment.dart';
import 'package:interstellar/src/models/post.dart';
import 'package:interstellar/src/utils/models.dart';
import 'package:interstellar/src/utils/utils.dart';
import 'package:interstellar/src/models/comment.dart';

enum BookmarkListSubject {
thread,
Expand Down Expand Up @@ -34,10 +34,10 @@ enum BookmarkListSubject {
}

class APIBookmark {
final ServerClient client;

APIBookmark(this.client);

final ServerClient client;

Future<(List<Object>, String?)> list({String? list, String? page}) async {
switch (client.software) {
case ServerSoftware.mbin:
Expand All @@ -47,10 +47,10 @@ class APIBookmark {
final response = await client.get(path, queryParams: query);

final json = response.bodyJson;
final itemList = json['items'] as List<dynamic>;
final itemList = json['items']! as List<dynamic>;
final items = itemList
.map((item) {
var itemType = item['itemType'];
final itemType = item['itemType'];
if (itemType == 'entry') {
return PostModel.fromMbinEntry(item as JsonMap);
} else if (itemType == 'post') {
Expand All @@ -65,7 +65,7 @@ class APIBookmark {

return (
items,
mbinCalcNextPaginationPage(json['pagination'] as JsonMap),
mbinCalcNextPaginationPage(json['pagination']! as JsonMap),
);

case ServerSoftware.lemmy:
Expand All @@ -86,13 +86,13 @@ class APIBookmark {

final postJson = postResponse.bodyJson;
postJson['next_page'] = lemmyCalcNextIntPage(
postJson['posts'] as List<dynamic>,
postJson['posts']! as List<dynamic>,
page,
);

final commentJson = commentResponse.bodyJson;
commentJson['next_page'] = lemmyCalcNextIntPage(
commentJson['comments'] as List<dynamic>,
commentJson['comments']! as List<dynamic>,
page,
);

Expand Down Expand Up @@ -189,7 +189,7 @@ class APIBookmark {

final response = await client.put(path);

return optionalStringList((response.bodyJson['bookmarks']));
return optionalStringList(response.bodyJson['bookmarks']);

case ServerSoftware.lemmy:
final path = switch (subjectType) {
Expand Down Expand Up @@ -246,7 +246,7 @@ class APIBookmark {

final response = await client.put(path);

return optionalStringList((response.bodyJson['bookmarks']));
return optionalStringList(response.bodyJson['bookmarks']);

case ServerSoftware.lemmy:
throw Exception('Bookmark lists not on Lemmy');
Expand All @@ -266,7 +266,7 @@ class APIBookmark {

final response = await client.delete(path);

return optionalStringList((response.bodyJson['bookmarks']));
return optionalStringList(response.bodyJson['bookmarks']);

case ServerSoftware.lemmy:
final path = switch (subjectType) {
Expand Down Expand Up @@ -323,7 +323,7 @@ class APIBookmark {

final response = await client.delete(path);

return optionalStringList((response.bodyJson['bookmarks']));
return optionalStringList(response.bodyJson['bookmarks']);

case ServerSoftware.lemmy:
throw Exception('Bookmark lists not on Lemmy');
Expand Down
20 changes: 10 additions & 10 deletions lib/src/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import 'package:interstellar/src/controller/server.dart';
import 'package:interstellar/src/utils/utils.dart';

class ServerClient {
http.Client httpClient;
ServerSoftware software;
String domain;
List<(String, int)>? _langCodeIdPairs;

ServerClient({
required this.httpClient,
required this.software,
required this.domain,
});

http.Client httpClient;
ServerSoftware software;
String domain;
List<(String, int)>? _langCodeIdPairs;

Future<http.Response> get(
String path, {
Map<String, String>? headers,
Expand Down Expand Up @@ -65,7 +65,7 @@ class ServerClient {
JsonMap? body,
Map<String, String?>? queryParams,
}) async {
var request = http.Request(
final request = http.Request(
method,
Uri.https(
domain,
Expand All @@ -80,7 +80,7 @@ class ServerClient {
}
if (headers != null) request.headers.addAll(headers);

return await sendRequest(request);
return sendRequest(request);
}

Future<http.Response> sendRequest(http.BaseRequest request) async {
Expand All @@ -98,7 +98,7 @@ class ServerClient {
Map<String, String>.from(
Map.fromEntries(
queryParams.entries.where(
(e) => (e.value != null && e.value!.isNotEmpty),
(e) => e.value != null && e.value!.isNotEmpty,
),
),
);
Expand Down Expand Up @@ -133,15 +133,15 @@ class ServerClient {

final json = response.bodyJson;

allLanguages = json['all_languages'] as List<dynamic>;
allLanguages = json['all_languages']! as List<dynamic>;

case ServerSoftware.piefed:
final response = await get('/site');

final json = response.bodyJson;

allLanguages =
(json['site'] as JsonMap)['all_languages'] as List<dynamic>;
(json['site']! as JsonMap)['all_languages']! as List<dynamic>;
}

_langCodeIdPairs = allLanguages
Expand Down
Loading