mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
IAP: Always check
Disable the optimization of not checking for pro mode on boot. The optimization fails and pro members cannot always get the pro features. This is not good. As a workaround, opening the but pro mode page also checks if already purchased.
This commit is contained in:
@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart' as foundation;
|
||||
|
||||
import 'package:gitjournal/analytics.dart';
|
||||
import 'package:gitjournal/iap.dart';
|
||||
import 'package:gitjournal/screens/filesystem_screen.dart';
|
||||
import 'package:gitjournal/screens/folder_listing.dart';
|
||||
import 'package:gitjournal/screens/tag_listing.dart';
|
||||
@ -96,6 +97,8 @@ class JournalApp extends StatefulWidget {
|
||||
),
|
||||
);
|
||||
|
||||
InAppPurchases.confirmProPurchase();
|
||||
|
||||
runApp(EasyLocalization(
|
||||
child: app,
|
||||
supportedLocales: [
|
||||
|
20
lib/iap.dart
20
lib/iap.dart
@ -7,17 +7,15 @@ import 'package:in_app_purchase/in_app_purchase.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
|
||||
class InAppPurchases {
|
||||
static void confirmProPurchase() async {
|
||||
static Future<void> confirmProPurchase() async {
|
||||
Log.i("Checking if ProMode should be enabled");
|
||||
|
||||
var currentDt = DateTime.now().toUtc().toIso8601String();
|
||||
var exp = Settings.instance.proExpirationDate;
|
||||
if (exp != null && exp.isNotEmpty && exp.compareTo(currentDt) > 0) {
|
||||
Log.i("Not checking PurchaseInfo as exp = $exp and cur = $currentDt");
|
||||
return;
|
||||
}
|
||||
if (exp == "-") {
|
||||
Log.d("Ignoring IAP pro check - already checked");
|
||||
return;
|
||||
}
|
||||
|
||||
if (JournalApp.isInDebugMode) {
|
||||
Log.d("Ignoring IAP pro check - debug mode");
|
||||
@ -26,15 +24,16 @@ class InAppPurchases {
|
||||
|
||||
var sub = await _subscriptionStatus();
|
||||
var isPro = sub == null ? false : sub.isPro;
|
||||
Log.i("IsPro $isPro");
|
||||
var expiryDate = sub == null ? "" : sub.expiryDate.toIso8601String();
|
||||
Log.i(sub.toString());
|
||||
|
||||
if (Settings.instance.proMode != isPro) {
|
||||
Log.i("Pro mode changed to $isPro");
|
||||
Settings.instance.proMode = isPro;
|
||||
Settings.instance.proExpirationDate = expiryDate;
|
||||
Settings.instance.save();
|
||||
} else {
|
||||
Settings.instance.proExpirationDate =
|
||||
sub != null ? sub.expiryDate.toIso8601String() : "-";
|
||||
Settings.instance.proExpirationDate = expiryDate;
|
||||
Settings.instance.save();
|
||||
}
|
||||
}
|
||||
@ -48,6 +47,7 @@ class InAppPurchases {
|
||||
} else if (Platform.isAndroid) {
|
||||
var response = await iapConn.queryPastPurchases();
|
||||
if (response.pastPurchases.isEmpty) {
|
||||
Log.i("No Past Purchases Found");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -83,4 +83,8 @@ class SubscriptionStatus {
|
||||
final DateTime expiryDate;
|
||||
|
||||
SubscriptionStatus(this.isPro, this.expiryDate);
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
"SubscriptionStatus{isPro: $isPro, expiryDate: $expiryDate}";
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/iap.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
|
||||
@ -22,8 +21,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
super.initState();
|
||||
|
||||
initializeDateFormatting();
|
||||
|
||||
InAppPurchases.confirmProPurchase();
|
||||
Future.delayed(Duration.zero, _initFolder);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:gitjournal/analytics.dart';
|
||||
import 'package:gitjournal/.env.dart';
|
||||
import 'package:gitjournal/iap.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
|
||||
import 'package:purchases_flutter/purchases_flutter.dart';
|
||||
@ -28,6 +29,11 @@ class _PurchaseScreenState extends State<PurchaseScreen> {
|
||||
}
|
||||
|
||||
Future<void> initPlatformState() async {
|
||||
await InAppPurchases.confirmProPurchase();
|
||||
if (Settings.instance.proMode) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
await Purchases.setup(
|
||||
environment['revenueCat'],
|
||||
appUserId: Settings.instance.pseudoId,
|
||||
|
@ -220,6 +220,7 @@ class Settings {
|
||||
"folderViewHeaderType": folderViewHeaderType,
|
||||
"version": version.toString(),
|
||||
"proMode": proMode.toString(),
|
||||
'proExpirationDate': proExpirationDate,
|
||||
'pseudoId': pseudoId,
|
||||
'markdownDefaultView': markdownDefaultView.toInternalString(),
|
||||
'homeScreen': homeScreen.toInternalString(),
|
||||
|
Reference in New Issue
Block a user