Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #98 from MXCzkEVM/email_launch_fix
Browse files Browse the repository at this point in the history
Email launch fix
  • Loading branch information
reasje authored Oct 19, 2023
2 parents 120dc34 + 6a4a74d commit 0f7420c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
3 changes: 2 additions & 1 deletion assets/flutter_i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,6 @@
"removing_account": "Removing account",
"removing_account_warning": "Are you sure you want to remove this account?",
"remove": "Remove",
"duplicate_account_import_notice": "The account you are trying to import is a duplicate"
"duplicate_account_import_notice": "The account you are trying to import is a duplicate",
"unable_to_launch_email_app": "Unable to launch email app"
}
2 changes: 2 additions & 0 deletions lib/common/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class Urls {

static const String iOSUrl =
'https://apps.apple.com/us/app/axs-decentralized-wallet/id6460891587';

static const String emailApp = 'mailto:';
}
21 changes: 21 additions & 0 deletions lib/common/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import 'package:datadashwallet/common/common.dart';
import 'package:url_launcher/url_launcher.dart';

export 'formatter.dart';
export 'permission.dart';
export 'validation.dart';

class Utils {
static Future<bool> isEmailAppAvailable() async {
final url = Uri.parse(Urls.emailApp);

return await canLaunchUrl(url);
}

static Future<void> launchEmailApp() async {
final url = Uri.parse(Urls.emailApp);

if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'unable_to_launch_email_app';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ class SplashStoragePage extends SplashBasePage {
icon: MxcIcons.email,
iconSize: 18,
title: FlutterI18n.translate(context, 'email_secured_storage'),
onTap: () => Navigator.of(context).push(
route.featureDialog(
EmailRecoveryPhrasePage(
settingsFlow: settingsFlow,
),
),
),
onTap: ref.watch(state).isEmailAppAvailable == true
? () => Navigator.of(context).push(
route.featureDialog(
EmailRecoveryPhrasePage(
settingsFlow: settingsFlow,
),
),
)
: null,
),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SplashStoragePresenter extends SplashBasePresenter<SplashBaseState> {
@override
void initState() {
super.initState();

isInstallApps();
checkEmailAppAvailability();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,25 @@ abstract class RecoveryPhraseBasePresenter<T extends RecoveryPhraseBaseState>
);

try {
MailerResponse sendResult = await FlutterMailer.send(email);
// only [ios] can return sent | saved | cancelled
// [android] will return android there is no way of knowing on android
// if the intent was sent saved or even cancelled.
if (MailerResponse.cancelled != sendResult) {
nextProcess(settingsFlow, res['phrases']);
bool canSend = await FlutterMailer.canSendMail();

if (Platform.isIOS && !canSend) {
await Utils.launchEmailApp();
} else {
MailerResponse sendResult = await FlutterMailer.send(email);
// only [ios] can return sent | saved | cancelled
// [android] will return android there is no way of knowing on android
// if the intent was sent saved or even cancelled.
if (MailerResponse.cancelled != sendResult) {
nextProcess(settingsFlow, res['phrases']);
}
}
} catch (e, s) {
addError(e, s);
if (e == 'unable_to_launch_email_app') {
addError(translate('unable_to_launch_email_app'));
} else {
addError(e, s);
}
}
}
}
9 changes: 4 additions & 5 deletions lib/features/splash/splash_base/splash_base_presenter.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../../common/common.dart';
import '../../../core/core.dart';
import 'package:appinio_social_share/appinio_social_share.dart';
import 'package:flutter_mailer/flutter_mailer.dart';
Expand All @@ -16,11 +17,9 @@ abstract class SplashBasePresenter<T extends SplashBaseState>
notify(() => state.applist = applist);
}

Future<void> isInstallEmail() async {
final result = await FlutterMailer.canSendMail() ||
await FlutterMailer.isAppInstalled('mailto:');

notify(() => state.isInstallEmail = result);
void checkEmailAppAvailability() async {
final isEmailAppAvailable = await Utils.isEmailAppAvailable();
notify(() => state.isEmailAppAvailable = isEmailAppAvailable);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/features/splash/splash_base/splash_base_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import 'package:equatable/equatable.dart';

class SplashBaseState with EquatableMixin {
Map applist = {};
bool isInstallEmail = false;
bool isEmailAppAvailable = false;

bool animate = false;

@override
List<Object?> get props => [applist, isInstallEmail, animate];
List<Object?> get props =>
[applist, animate, isEmailAppAvailable];
}

0 comments on commit 0f7420c

Please sign in to comment.