mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-22 06:59:21 +01:00
Refine upgrade flow in splash screen
This commit is contained in:
parent
877d50d2a2
commit
a2e0dbabe3
1 changed files with 35 additions and 30 deletions
|
@ -28,15 +28,18 @@ class _SplashState extends State<Splash> {
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||||
if (_shouldUpgrade()) {
|
_doWork();
|
||||||
_handleUpgrade();
|
|
||||||
} else {
|
|
||||||
_initTimedExit();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _doWork() async {
|
||||||
|
if (_shouldUpgrade()) {
|
||||||
|
await _handleUpgrade();
|
||||||
|
}
|
||||||
|
_initTimedExit();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
build(BuildContext context) {
|
build(BuildContext context) {
|
||||||
return AppTheme(
|
return AppTheme(
|
||||||
|
@ -90,7 +93,7 @@ class _SplashState extends State<Splash> {
|
||||||
return lastVersion < k.version;
|
return lastVersion < k.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleUpgrade() async {
|
Future<void> _handleUpgrade() async {
|
||||||
try {
|
try {
|
||||||
final lastVersion = Pref().getLastVersionOr(k.version);
|
final lastVersion = Pref().getLastVersionOr(k.version);
|
||||||
await _upgrade(lastVersion);
|
await _upgrade(lastVersion);
|
||||||
|
@ -115,41 +118,43 @@ class _SplashState extends State<Splash> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout("[_handleUpgrade] Failed while upgrade", e, stackTrace);
|
||||||
} finally {
|
} finally {
|
||||||
_initTimedExit();
|
await Pref().setLastVersion(k.version);
|
||||||
Pref().setLastVersion(k.version);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _upgrade(int lastVersion) async {
|
Future<void> _upgrade(int lastVersion) async {
|
||||||
|
bool isShowDialog = false;
|
||||||
|
void showUpdateDialog() {
|
||||||
|
if (!isShowDialog) {
|
||||||
|
isShowDialog = true;
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ProcessingDialog(
|
||||||
|
text: L10n.global().genericProcessingDialogContent,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lastVersion < 290) {
|
if (lastVersion < 290) {
|
||||||
|
showUpdateDialog();
|
||||||
await _upgrade29(lastVersion);
|
await _upgrade29(lastVersion);
|
||||||
}
|
}
|
||||||
|
if (isShowDialog) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _upgrade29(int lastVersion) async {
|
Future<void> _upgrade29(int lastVersion) async {
|
||||||
await _peformUpgrade(() async {
|
|
||||||
try {
|
|
||||||
_log.info("[_upgrade29] clearDefaultCache");
|
|
||||||
await CompatV29.clearDefaultCache();
|
|
||||||
} catch (e, stackTrace) {
|
|
||||||
_log.shout(
|
|
||||||
"[_upgrade29] Failed while clearDefaultCache", e, stackTrace);
|
|
||||||
// just leave the cache then
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _peformUpgrade(FutureOr<void> Function() fn) async {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (_) => ProcessingDialog(
|
|
||||||
text: L10n.global().genericProcessingDialogContent,
|
|
||||||
));
|
|
||||||
try {
|
try {
|
||||||
await fn();
|
_log.info("[_upgrade29] clearDefaultCache");
|
||||||
} finally {
|
await CompatV29.clearDefaultCache();
|
||||||
Navigator.of(context).pop();
|
} catch (e, stackTrace) {
|
||||||
|
_log.shout("[_upgrade29] Failed while clearDefaultCache", e, stackTrace);
|
||||||
|
// just leave the cache then
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue