mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Only check if subscription is valid if it has expired
This way we avoid extra network access.
This commit is contained in:
17
lib/iap.dart
17
lib/iap.dart
@ -6,10 +6,18 @@ import 'package:gitjournal/.env.dart';
|
||||
|
||||
class InAppPurchases {
|
||||
static void confirmProPurchase() async {
|
||||
// FIXME: Only check this if pro mode is expired
|
||||
var currentDt = DateTime.now().toUtc().toIso8601String();
|
||||
var exp = Settings.instance.proExpirationDate;
|
||||
if (exp.isNotEmpty && exp.compareTo(currentDt) > 0) {
|
||||
print("Not checking PurchaseInfo as exp = $exp and cur = $currentDt");
|
||||
return;
|
||||
}
|
||||
|
||||
//Purchases.setDebugLogsEnabled(true);
|
||||
await Purchases.setup(environment['revenueCat']);
|
||||
Purchases.setDebugLogsEnabled(false);
|
||||
await Purchases.setup(
|
||||
environment['revenueCat'],
|
||||
appUserId: Settings.instance.pseudoId,
|
||||
);
|
||||
|
||||
PurchaserInfo purchaserInfo = await Purchases.getPurchaserInfo();
|
||||
print("Got PurchaserInfo $purchaserInfo");
|
||||
@ -20,6 +28,9 @@ class InAppPurchases {
|
||||
Log.i("Pro mode changed to $isPro");
|
||||
Settings.instance.proMode = isPro;
|
||||
Settings.instance.save();
|
||||
} else {
|
||||
Settings.instance.proExpirationDate = purchaserInfo.latestExpirationDate;
|
||||
Settings.instance.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,8 @@ class PurchaseButton extends StatelessWidget {
|
||||
var isPro = purchaserInfo.entitlements.all["pro"].isActive;
|
||||
if (isPro) {
|
||||
Settings.instance.proMode = true;
|
||||
Settings.instance.proExpirationDate =
|
||||
purchaserInfo.latestExpirationDate;
|
||||
Settings.instance.save();
|
||||
|
||||
getAnalytics().logEvent(
|
||||
|
@ -35,6 +35,7 @@ class Settings {
|
||||
int version = 0;
|
||||
|
||||
bool proMode = false;
|
||||
String proExpirationDate = "";
|
||||
|
||||
String _pseudoId;
|
||||
String get pseudoId => _pseudoId;
|
||||
@ -76,6 +77,8 @@ class Settings {
|
||||
|
||||
version = pref.getInt("settingsVersion") ?? version;
|
||||
proMode = pref.getBool("proMode") ?? proMode;
|
||||
proExpirationDate =
|
||||
pref.getString("proExpirationDate") ?? proExpirationDate;
|
||||
|
||||
_pseudoId = pref.getString("pseudoId");
|
||||
if (_pseudoId == null) {
|
||||
@ -103,6 +106,7 @@ class Settings {
|
||||
"markdownDefaultView", markdownDefaultView.toInternalString());
|
||||
pref.setBool("showNoteSummary", showNoteSummary);
|
||||
pref.setString("folderViewHeaderType", folderViewHeaderType);
|
||||
pref.setString("proExpirationDate", proExpirationDate);
|
||||
pref.setInt("settingsVersion", version);
|
||||
pref.setBool("proMode", proMode);
|
||||
|
||||
|
Reference in New Issue
Block a user