Store first run time

This commit is contained in:
Ming Ming 2022-05-17 19:32:19 +08:00
parent 3d81fb39a6
commit 770d4527da
2 changed files with 11 additions and 0 deletions

View file

@ -193,6 +193,11 @@ class Pref {
value,
(key, value) => provider.setBool(key, value));
int? getFirstRunTime() => provider.getInt(PrefKey.firstRunTime);
int getFirstRunTimeOr(int def) => getFirstRunTime() ?? def;
Future<bool> setFirstRunTime(int value) => _set<int>(
PrefKey.firstRunTime, value, (key, value) => provider.setInt(key, value));
Future<bool> _set<T>(PrefKey key, T value,
Future<bool> Function(PrefKey key, T value) setFn) async {
if (await setFn(key, value)) {
@ -485,6 +490,7 @@ enum PrefKey {
enhanceMaxWidth,
enhanceMaxHeight,
hasShownEnhanceInfo,
firstRunTime,
// account pref
isEnableFaceRecognitionApp,
@ -545,6 +551,8 @@ extension on PrefKey {
return "enhanceMaxHeight";
case PrefKey.hasShownEnhanceInfo:
return "hasShownEnhanceInfo";
case PrefKey.firstRunTime:
return "firstRunTime";
// account pref
case PrefKey.isEnableFaceRecognitionApp:

View file

@ -41,6 +41,9 @@ class _SplashState extends State<Splash> {
}
Future<void> _doWork() async {
if (Pref().getFirstRunTime() == null) {
await Pref().setFirstRunTime(DateTime.now().millisecondsSinceEpoch);
}
if (_shouldUpgrade()) {
await _handleUpgrade();
}