这是indexloc提供的服务,不要输入任何密码
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
2 changes: 2 additions & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
aboutAria: "About Aria"
accessToken: "Access token"
accessTokenUpdated: "Successfully updated an access token"
accountAdded: "Successfully added an account"
acknowledgements(rich): "Aria is a fork of {miria}.\nLocalization of Aria is based on localization files of {misskey}.\nWe would like to show our appreciation to all contributers of these projects."
addTab: "Add tab"
alwaysExpandCw: "Always expand content warning"
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 57341 (1849 per locale)
/// Strings: 57343 (1849 per locale)

// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class TranslationsAriaEnUs {
// Translations
String get aboutAria => 'About Aria';
String get accessToken => 'Access token';
String get accessTokenUpdated => 'Successfully updated an access token';
String get accountAdded => 'Successfully added an account';
TextSpan acknowledgements({required InlineSpan miria, required InlineSpan misskey}) => TextSpan(children: [
const TextSpan(text: 'Aria is a fork of '),
miria,
Expand Down
19 changes: 12 additions & 7 deletions lib/provider/accounts_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ class AccountsNotifier extends _$AccountsNotifier {
.setStringList(_key, state.map((e) => jsonEncode(e)).toList());
}

Future<void> login(Account account, String token, String userId) async {
Future<({bool added})> login(
Account account,
String token,
String userId,
) async {
await ref.read(tokensNotifierProvider.notifier).add(account, token);
await ref.read(userIdsNotifierProvider.notifier).add(account, userId);
if (state.contains(account)) return;
if (state.contains(account)) {
return (added: false);
}
state = {...state, account}.toList();
await _save();
return (added: true);
}

Future<bool> loginWithToken(String host, String token) async {
Future<({bool added})> loginWithToken(String host, String token) async {
if (kDebugMode) {
if (host.startsWith('localhost')) {
final i = await ref
Expand All @@ -50,15 +57,14 @@ class AccountsNotifier extends _$AccountsNotifier {
Uri.http(host, 'api/i'),
data: {'i': token},
);
await login(
return login(
Account(
host: host.toLowerCase(),
username: i.data!['username'] as String,
),
token,
i.data!['id'] as String,
);
return true;
}
}
final i = await ref
Expand All @@ -67,15 +73,14 @@ class AccountsNotifier extends _$AccountsNotifier {
Uri.https(host, 'api/i'),
data: {'i': token},
);
await login(
return login(
Account(
host: host.toLowerCase(),
username: i.data!['username'] as String,
),
token,
i.data!['id'] as String,
);
return true;
}

Future<void> remove(Account account) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/accounts_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions lib/provider/miauth_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ class MiAuthNotifier extends _$MiAuthNotifier {
return url;
}

Future<bool> check() async {
Future<({bool success, bool? added})> check() async {
if (state == null) {
return true;
return (success: true, added: null);
}
final result = await ref
.read(miAuthRepositoryProvider)
.check(state!.host, state!.sessionId);
if (result == null) {
return false;
if (result case (final token, final user)) {
final result = await ref
.read(accountsNotifierProvider.notifier)
.login(
Account(host: state!.host.toLowerCase(), username: user.username),
token,
user.id,
);
state = null;
return (success: true, added: result.added);
} else {
return (success: false, added: null);
}
final (token, user) = result;
await ref
.read(accountsNotifierProvider.notifier)
.login(
Account(host: state!.host.toLowerCase(), username: user.username),
token,
user.id,
);
state = null;
return true;
}
}
2 changes: 1 addition & 1 deletion lib/provider/miauth_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions lib/provider/share_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'package:collection/collection.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../i18n/strings.g.dart';
import '../model/account.dart';
import '../model/post_file.dart';
import '../util/show_toast.dart';
import 'accounts_notifier_provider.dart';
import 'api/attaches_notifier_provider.dart';
import 'file_system_provider.dart';
Expand Down Expand Up @@ -37,9 +39,16 @@ class ShareNotifier extends _$ShareNotifier {
final url = Uri.parse(sharedFiles.single.path);
if (url.scheme == 'aria') {
if (url.path == '/miauth') {
final succeeded =
final result =
await ref.read(miAuthNotifierProvider.notifier).check();
if (succeeded) {
if (result.added case final added?) {
showToast(
context: null,
message:
added ? t.aria.accountAdded : t.aria.accessTokenUpdated,
);
}
if (result.success) {
return '/timelines';
} else {
return '/login/authenticate';
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/share_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lib/repository/miauth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class MiAuthRepository {
final url = Uri.https(host, 'miauth/$sessionId', {
'name': 'Aria',
'permission': _permissions.map((e) => e.value).join(','),
if (defaultTargetPlatform
case TargetPlatform.android || TargetPlatform.iOS)
if (defaultTargetPlatform == TargetPlatform.android)
'callback': 'aria://aria/miauth',
});
return (sessionId, url);
Expand Down
16 changes: 13 additions & 3 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../i18n/strings.g.dart';
import '../model/account.dart';
import '../model/tab_settings.dart';
import '../provider/boot_state_provider.dart';
Expand All @@ -12,6 +15,7 @@ import '../provider/push_notification_notifier_provider.dart';
import '../provider/receive_sharing_intent_provider.dart';
import '../provider/share_notifier_provider.dart';
import '../util/safe_parse_double.dart';
import '../util/show_toast.dart';
import '../view/page/about_aria_page.dart';
import '../view/page/about_misskey_page.dart';
import '../view/page/announcements_page.dart';
Expand Down Expand Up @@ -133,10 +137,16 @@ GoRouter router(Ref ref) {
),
GoRoute(
path: '/miauth',
redirect: (_, _) async {
final succeeded =
redirect: (context, _) async {
final result =
await ref.read(miAuthNotifierProvider.notifier).check();
if (succeeded) {
if (result.added case final added?) {
showToast(
context: context.mounted ? context : null,
message: added ? t.aria.accountAdded : t.aria.accessTokenUpdated,
);
}
if (result.success) {
return '/timelines';
} else {
return '/login/authenticate';
Expand Down
2 changes: 1 addition & 1 deletion lib/router/router.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions lib/util/copy_text.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

import '../i18n/strings.g.dart';
import 'show_toast.dart';

void copyToClipboard(BuildContext context, String text) {
Clipboard.setData(ClipboardData(text: text));
if (defaultTargetPlatform case TargetPlatform.android || TargetPlatform.iOS) {
Fluttertoast.showToast(msg: t.aria.copied);
} else {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(t.aria.copied)));
}
Future<void> copyToClipboard(BuildContext context, String text) async {
await Clipboard.setData(ClipboardData(text: text));
showToast(context: context.mounted ? context : null, message: t.aria.copied);
}
14 changes: 2 additions & 12 deletions lib/util/future_with_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

import '../view/dialog/error_message_dialog.dart';
import 'show_toast.dart';

Future<T?> futureWithDialog<T>(
BuildContext context,
Expand Down Expand Up @@ -41,16 +40,7 @@ Future<T?> futureWithDialog<T>(
entry?.remove();
} catch (_) {}
if (message != null) {
if (defaultTargetPlatform
case TargetPlatform.android || TargetPlatform.iOS) {
await Fluttertoast.showToast(msg: message);
} else {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
}
}
showToast(context: context.mounted ? context : null, message: message);
}
return result;
} catch (e, st) {
Expand Down
12 changes: 12 additions & 0 deletions lib/util/show_toast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

void showToast({required BuildContext? context, required String message}) {
if (defaultTargetPlatform case TargetPlatform.android || TargetPlatform.iOS) {
Fluttertoast.showToast(msg: message).ignore();
} else if (context != null) {
final snackBar = SnackBar(content: Text(message));
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}
12 changes: 10 additions & 2 deletions lib/view/page/authenticate_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../../i18n/strings.g.dart';
import '../../provider/miauth_notifier_provider.dart';
import '../../util/copy_text.dart';
import '../../util/future_with_dialog.dart';
import '../../util/show_toast.dart';
import '../dialog/message_dialog.dart';

class AuthenticatePage extends ConsumerWidget {
Expand Down Expand Up @@ -37,12 +38,19 @@ class AuthenticatePage extends ConsumerWidget {
body: Center(
child: ElevatedButton(
onPressed: () async {
final succeeded = await futureWithDialog(
final result = await futureWithDialog(
context,
ref.read(miAuthNotifierProvider.notifier).check(),
);
if (!context.mounted) return;
if (succeeded ?? false) {
if (result?.added case final added?) {
showToast(
context: context.mounted ? context : null,
message:
added ? t.aria.accountAdded : t.aria.accessTokenUpdated,
);
}
if (result?.success ?? false) {
context.go('/timelines');
} else {
await showMessageDialog(context, t.misskey.loginFailed);
Expand Down
2 changes: 1 addition & 1 deletion lib/view/page/settings/import_export_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ImportExportPage extends ConsumerWidget {
_export(ref),
);
if (!context.mounted) return;
copyToClipboard(context, jsonEncode(data));
await copyToClipboard(context, jsonEncode(data));
},
),
],
Expand Down
8 changes: 7 additions & 1 deletion lib/view/page/token_login_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:ui';

import 'package:collection/collection.dart';
Expand All @@ -13,6 +14,7 @@ import '../../provider/accounts_notifier_provider.dart';
import '../../provider/misskey_servers_provider.dart';
import '../../util/future_with_dialog.dart';
import '../../util/punycode.dart';
import '../../util/show_toast.dart';
import '../dialog/misskey_server_list_dialog.dart';
import '../widget/image_widget.dart';
import '../widget/misskey_server_autocomplete.dart';
Expand All @@ -33,9 +35,13 @@ class TokenLoginPage extends HookConsumerWidget {
.first,
).toLowerCase();
if (!ref.context.mounted) return;
await ref
final result = await ref
.read(accountsNotifierProvider.notifier)
.loginWithToken(trimmed, token);
showToast(
context: ref.context.mounted ? ref.context : null,
message: result.added ? t.aria.accountAdded : t.aria.accessTokenUpdated,
);
if (!ref.context.mounted) return;
ref.context.go('/timelines');
}
Expand Down
Loading