From 31db8c166928c89a8cd1dff5fb71e131daffa219 Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Mon, 26 Aug 2024 20:26:40 +0900 Subject: [PATCH] fix: open MiAuth in app if iOS (#369) --- lib/repository/miauth_repository.dart | 3 +-- lib/util/launch_url.dart | 12 ++++++++---- lib/view/page/login_page.dart | 10 +++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/repository/miauth_repository.dart b/lib/repository/miauth_repository.dart index 77384e3f..6f94a059 100644 --- a/lib/repository/miauth_repository.dart +++ b/lib/repository/miauth_repository.dart @@ -56,8 +56,7 @@ class MiAuthRepository { { 'name': 'Aria', 'permission': _permissions.map((e) => e.value).join(','), - if (defaultTargetPlatform - case TargetPlatform.android || TargetPlatform.iOS) + if (defaultTargetPlatform == TargetPlatform.android) 'callback': 'aria://aria/miauth', }, ); diff --git a/lib/util/launch_url.dart b/lib/util/launch_url.dart index 88d04373..8c06f3c9 100644 --- a/lib/util/launch_url.dart +++ b/lib/util/launch_url.dart @@ -1,11 +1,15 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:url_launcher/url_launcher.dart' as launcher; +import 'package:url_launcher/url_launcher.dart' as url_launcher; import '../provider/general_settings_notifier_provider.dart'; -Future launchUrl(WidgetRef ref, Uri url) { - return launcher.launchUrl( +Future launchUrl( + WidgetRef ref, + Uri url, { + url_launcher.LaunchMode? mode, +}) { + return url_launcher.launchUrl( url, - mode: ref.read(generalSettingsNotifierProvider).launchMode, + mode: mode ?? ref.read(generalSettingsNotifierProvider).launchMode, ); } diff --git a/lib/view/page/login_page.dart b/lib/view/page/login_page.dart index ae3fa161..e5c6c116 100644 --- a/lib/view/page/login_page.dart +++ b/lib/view/page/login_page.dart @@ -1,10 +1,12 @@ import 'dart:ui'; import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:url_launcher/url_launcher.dart' hide launchUrl; import '../../i18n/strings.g.dart'; import '../../provider/miauth_notifier_provider.dart'; @@ -25,7 +27,13 @@ class LoginPage extends HookConsumerWidget { .toLowerCase(); final url = ref.read(miAuthNotifierProvider.notifier).buildMiAuthUrl(trimmed); - launchUrl(ref, url); + launchUrl( + ref, + url, + mode: defaultTargetPlatform == TargetPlatform.iOS + ? LaunchMode.inAppWebView + : null, + ); ref.context.push('/login/authenticate'); }