mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +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 {
|
class InAppPurchases {
|
||||||
static void confirmProPurchase() async {
|
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);
|
Purchases.setDebugLogsEnabled(false);
|
||||||
await Purchases.setup(environment['revenueCat']);
|
await Purchases.setup(
|
||||||
|
environment['revenueCat'],
|
||||||
|
appUserId: Settings.instance.pseudoId,
|
||||||
|
);
|
||||||
|
|
||||||
PurchaserInfo purchaserInfo = await Purchases.getPurchaserInfo();
|
PurchaserInfo purchaserInfo = await Purchases.getPurchaserInfo();
|
||||||
print("Got PurchaserInfo $purchaserInfo");
|
print("Got PurchaserInfo $purchaserInfo");
|
||||||
@ -20,6 +28,9 @@ class InAppPurchases {
|
|||||||
Log.i("Pro mode changed to $isPro");
|
Log.i("Pro mode changed to $isPro");
|
||||||
Settings.instance.proMode = isPro;
|
Settings.instance.proMode = isPro;
|
||||||
Settings.instance.save();
|
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;
|
var isPro = purchaserInfo.entitlements.all["pro"].isActive;
|
||||||
if (isPro) {
|
if (isPro) {
|
||||||
Settings.instance.proMode = true;
|
Settings.instance.proMode = true;
|
||||||
|
Settings.instance.proExpirationDate =
|
||||||
|
purchaserInfo.latestExpirationDate;
|
||||||
Settings.instance.save();
|
Settings.instance.save();
|
||||||
|
|
||||||
getAnalytics().logEvent(
|
getAnalytics().logEvent(
|
||||||
|
@ -35,6 +35,7 @@ class Settings {
|
|||||||
int version = 0;
|
int version = 0;
|
||||||
|
|
||||||
bool proMode = false;
|
bool proMode = false;
|
||||||
|
String proExpirationDate = "";
|
||||||
|
|
||||||
String _pseudoId;
|
String _pseudoId;
|
||||||
String get pseudoId => _pseudoId;
|
String get pseudoId => _pseudoId;
|
||||||
@ -76,6 +77,8 @@ class Settings {
|
|||||||
|
|
||||||
version = pref.getInt("settingsVersion") ?? version;
|
version = pref.getInt("settingsVersion") ?? version;
|
||||||
proMode = pref.getBool("proMode") ?? proMode;
|
proMode = pref.getBool("proMode") ?? proMode;
|
||||||
|
proExpirationDate =
|
||||||
|
pref.getString("proExpirationDate") ?? proExpirationDate;
|
||||||
|
|
||||||
_pseudoId = pref.getString("pseudoId");
|
_pseudoId = pref.getString("pseudoId");
|
||||||
if (_pseudoId == null) {
|
if (_pseudoId == null) {
|
||||||
@ -103,6 +106,7 @@ class Settings {
|
|||||||
"markdownDefaultView", markdownDefaultView.toInternalString());
|
"markdownDefaultView", markdownDefaultView.toInternalString());
|
||||||
pref.setBool("showNoteSummary", showNoteSummary);
|
pref.setBool("showNoteSummary", showNoteSummary);
|
||||||
pref.setString("folderViewHeaderType", folderViewHeaderType);
|
pref.setString("folderViewHeaderType", folderViewHeaderType);
|
||||||
|
pref.setString("proExpirationDate", proExpirationDate);
|
||||||
pref.setInt("settingsVersion", version);
|
pref.setInt("settingsVersion", version);
|
||||||
pref.setBool("proMode", proMode);
|
pref.setBool("proMode", proMode);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user