From a165425095deecf3863918a7aa597f13432c2ff9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 13 Nov 2022 12:01:31 +0200 Subject: [PATCH 1/4] Add support for LetsEncrypt to older Android phones --- lib/main.dart | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index 705f82aa123..7218b059b1a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ // Dart imports: import 'dart:async'; import 'dart:convert'; +import 'dart:io'; // Flutter imports: import 'package:flutter/foundation.dart'; @@ -61,8 +62,45 @@ import 'package:window_manager/window_manager.dart'; import 'package:invoiceninja_flutter/utils/web_stub.dart' if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart'; +// https://github.com/dart-lang/io/issues/83#issuecomment-940617222 +const isrgRootX1 = '''-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw +TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh +cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 +WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu +ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY +MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc +h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ +0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U +A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW +T8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bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq +4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA +mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d +emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= +-----END CERTIFICATE----- +'''; + void main({bool isTesting = false}) async { WidgetsFlutterBinding.ensureInitialized(); + SecurityContext.defaultContext.setTrustedCertificatesBytes( + Uint8List.fromList(isrgRootX1.codeUnits), + ); if (isDesktopOS()) { await windowManager.ensureInitialized(); From 4127ea8700879655dc994a09dec66e03320582c2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 13 Nov 2022 17:04:30 +0200 Subject: [PATCH 2/4] Android IAP --- lib/ui/app/upgrade_dialog.dart | 33 ++++++++++++++++++--------------- lib/utils/platforms.dart | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/ui/app/upgrade_dialog.dart b/lib/ui/app/upgrade_dialog.dart index ec4f41e24a2..3765b6b6291 100644 --- a/lib/ui/app/upgrade_dialog.dart +++ b/lib/ui/app/upgrade_dialog.dart @@ -126,22 +126,25 @@ class _UpgradeDialogState extends State { final List stack = []; if (_queryProductError == null) { stack.add( - Scrollbar( - thumbVisibility: true, - controller: _scrollController, - child: ListView( + Container( + width: double.maxFinite, + child: Scrollbar( + thumbVisibility: true, controller: _scrollController, - children: [ - if (Platform.isIOS) - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: Text( - 'Payment will be charged to iTunes Account at confirmation of purchase. Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period. Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal. Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user\'s Account Settings after purchase.', - style: TextStyle(fontSize: 12, color: Colors.grey), + child: ListView( + controller: _scrollController, + children: [ + if (Platform.isIOS) + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: Text( + 'Payment will be charged to iTunes Account at confirmation of purchase. Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period. Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal. Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user\'s Account Settings after purchase.', + style: TextStyle(fontSize: 12, color: Colors.grey), + ), ), - ), - _buildProductList(), - ], + _buildProductList(), + ], + ), ), ), ); @@ -292,7 +295,7 @@ class _UpgradeDialogState extends State { final data = { 'inapp_transaction_id': purchaseDetails.purchaseID, 'key': state.account.key, - 'plan': purchaseDetails.productID, + 'plan': purchaseDetails.productID.replaceAll('-', '_'), 'plan_paid': (int.parse(purchaseDetails.transactionDate) / 1000).floor(), }; diff --git a/lib/utils/platforms.dart b/lib/utils/platforms.dart index a218df8a42f..d314cf3796e 100644 --- a/lib/utils/platforms.dart +++ b/lib/utils/platforms.dart @@ -37,7 +37,7 @@ bool supportsInAppPurchase() { return false; } - return isIOS(); + return isIOS() || isAndroid(); } bool isDesktopOS() => isMacOS() || isWindows() || isLinux(); From d5dfb5b14746cb200778551698e48e959a31b7d2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 13 Nov 2022 17:15:20 +0200 Subject: [PATCH 3/4] Fix for cert already set --- lib/main.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 7218b059b1a..15a72e04b8d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -98,9 +98,14 @@ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= void main({bool isTesting = false}) async { WidgetsFlutterBinding.ensureInitialized(); - SecurityContext.defaultContext.setTrustedCertificatesBytes( - Uint8List.fromList(isrgRootX1.codeUnits), - ); + + try { + SecurityContext.defaultContext.setTrustedCertificatesBytes( + Uint8List.fromList(isrgRootX1.codeUnits), + ); + } catch (e) { + // Ignore CERT_ALREADY_IN_HASH_TABLE + } if (isDesktopOS()) { await windowManager.ensureInitialized(); From 45a9d70301547d0bd670ea41f4608ecb9ca5969d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 13 Nov 2022 17:15:45 +0200 Subject: [PATCH 4/4] Adjust review app widget --- lib/ui/app/review_app.dart | 74 ++++++++------------------------------ 1 file changed, 14 insertions(+), 60 deletions(-) diff --git a/lib/ui/app/review_app.dart b/lib/ui/app/review_app.dart index 697a3a5d973..90e66a7c4df 100644 --- a/lib/ui/app/review_app.dart +++ b/lib/ui/app/review_app.dart @@ -4,7 +4,6 @@ import 'package:flutter_redux/flutter_redux.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart'; -import 'package:invoiceninja_flutter/ui/app/menu_drawer.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:invoiceninja_flutter/utils/app_review.dart'; @@ -18,17 +17,6 @@ class ReviewApp extends StatefulWidget { } class _ReviewAppState extends State { - bool _likesTheApp; - - @override - void initState() { - super.initState(); - - if (isApple()) { - _likesTheApp = true; - } - } - @override Widget build(BuildContext context) { final localization = AppLocalization.of(context); @@ -38,11 +26,6 @@ class _ReviewAppState extends State { return SizedBox(); } - // TODO remove this code - if (isWindows()) { - return SizedBox(); - } - return Padding( padding: const EdgeInsets.only(top: 8), child: FormCard( @@ -50,13 +33,7 @@ class _ReviewAppState extends State { children: [ SizedBox(height: 12), Text( - isApple() - ? localization.wouldYouRateTheApp - : _likesTheApp == null - ? localization.areYouEnjoyingTheApp - : _likesTheApp == true - ? localization.wouldYouRateIt - : localization.wouldYouTellUsMore, + localization.wouldYouRateTheApp, style: Theme.of(context).textTheme.subtitle1, textAlign: TextAlign.center, ), @@ -65,40 +42,25 @@ class _ReviewAppState extends State { children: [ TextButton( onPressed: () async { - if (_likesTheApp == null) { - setState(() { - _likesTheApp = true; - }); + // TODO remove this code: https://github.com/britannio/in_app_review/issues/56 + if (isAndroid()) { + AppReview.openStoreListing(); + } else if (await AppReview.isAvailable()) { + AppReview.requestReview(); + } else if (kIsWeb || isLinux()) { + launchUrl(Uri.parse(getRateAppURL(context))); } else { - if (_likesTheApp == true) { - // TODO remove this code: https://github.com/britannio/in_app_review/issues/56 - if (isAndroid()) { - AppReview.openStoreListing(); - } else if (await AppReview.isAvailable()) { - AppReview.requestReview(); - } else if (kIsWeb || isLinux()) { - launchUrl(Uri.parse(getRateAppURL(context))); - } else { - AppReview.openStoreListing(); - } - } else { - showDialog( - context: context, - builder: (BuildContext context) => ContactUsDialog(), - ); - } - - store.dispatch(DismissReviewAppPermanently()); + AppReview.openStoreListing(); } + + store.dispatch(DismissReviewAppPermanently()); }, child: ConstrainedBox( constraints: const BoxConstraints(minWidth: 100), child: Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: Text( - _likesTheApp == null - ? localization.yesItsGreat - : localization.sureHappyTo, + localization.sureHappyTo, textAlign: TextAlign.center, ), ), @@ -106,22 +68,14 @@ class _ReviewAppState extends State { ), TextButton( onPressed: () async { - if (_likesTheApp == null) { - setState(() { - _likesTheApp = false; - }); - } else { - store.dispatch(DismissReviewAppPermanently()); - } + store.dispatch(DismissReviewAppPermanently()); }, child: ConstrainedBox( constraints: const BoxConstraints(minWidth: 100), child: Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: Text( - _likesTheApp == null - ? localization.notSoMuch - : localization.noNotNow, + localization.noNotNow, textAlign: TextAlign.center, ), ),