Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix: auto update

Prediditb809f28838b5
diff --git a/lib/pages/init_page.dart b/lib/pages/init_page.dart
index 6e1ab818..1a87ef7b 100644
--- a/lib/pages/init_page.dart
+++ b/lib/pages/init_page.dart
@@ -16,6 +16,7 @@ import 'package:kazumi/pages/plugin_editor/plugin_update_actions.dart';
import 'package:kazumi/services/download/background_download_service.dart';
import 'package:kazumi/services/platform/windows_shortcut.dart';
import 'package:kazumi/services/platform/platform_environment_service.dart';
+import 'package:kazumi/services/update/startup_update_check.dart';
import 'package:kazumi/navigation.dart';
class InitPage extends StatefulWidget {
@@ -82,13 +83,14 @@ class _InitPageState extends State<InitPage> {
if (!mounted) {
return;
}
+ final updateController = myController;
+ unawaited(runStartupUpdateCheck(
+ isEnabled: () => GStorage.getSetting(SettingsKeys.autoUpdate),
+ checkForUpdate: () async {
+ await updateController.checkUpdate(type: 'auto');
+ },
+ ));
_startDefaultPage();
- // delay to ensure that the default page is fully loaded
- await Future.delayed(const Duration(milliseconds: 500));
- if (!mounted) {
- return;
- }
- _update();
}
void _setupBackgroundDownloadNavigation() {
@@ -296,13 +298,6 @@ class _InitPageState extends State<InitPage> {
}
}
- Future<void> _update() async {
- bool autoUpdate = await GStorage.getSetting(SettingsKeys.autoUpdate);
- if (autoUpdate) {
- myController.checkUpdate(type: 'auto');
- }
- }
-
Future<void> _pluginUpdate() async {
final checkOnStartup =
GStorage.getSetting(SettingsKeys.checkPluginUpdateOnStartup);
diff --git a/lib/pages/onboarding/onboarding_page.dart b/lib/pages/onboarding/onboarding_page.dart
index 5798d255..e634b2b0 100644
--- a/lib/pages/onboarding/onboarding_page.dart
+++ b/lib/pages/onboarding/onboarding_page.dart
@@ -13,6 +13,7 @@ import 'package:kazumi/pages/onboarding/steps/update_source_step.dart';
import 'package:kazumi/plugins/plugins_controller.dart';
import 'package:kazumi/services/logging/logger.dart';
import 'package:kazumi/services/storage/storage.dart';
+import 'package:kazumi/services/update/startup_update_check.dart';
class OnboardingPage extends StatefulWidget {
const OnboardingPage({
@@ -136,12 +137,12 @@ class _OnboardingPageState extends State<OnboardingPage> {
void _finish() {
final myController = widget.myController;
- // delay to ensure that the default page is fully loaded
- unawaited(Future.delayed(const Duration(milliseconds: 500)).then((_) {
- if (GStorage.getSetting(SettingsKeys.autoUpdate)) {
- myController.checkUpdate(type: 'auto');
- }
- }));
+ unawaited(runStartupUpdateCheck(
+ isEnabled: () => GStorage.getSetting(SettingsKeys.autoUpdate),
+ checkForUpdate: () async {
+ await myController.checkUpdate(type: 'auto');
+ },
+ ));
context.navigate(GStorage.getSetting(SettingsKeys.defaultStartupPage));
}
diff --git a/lib/services/update/startup_update_check.dart b/lib/services/update/startup_update_check.dart
new file mode 100644
index 00000000..6dbde22f
--- /dev/null
+++ b/lib/services/update/startup_update_check.dart
@@ -0,0 +1,19 @@
+import 'dart:async';
+
+const startupUpdateCheckDelay = Duration(milliseconds: 500);
+
+/// Runs the startup update check independently from the page that scheduled it.
+///
+/// Startup pages are normally disposed as soon as they navigate to the app
+/// shell, so this work must not depend on their [State.mounted] value.
+Future<void> runStartupUpdateCheck({
+ required bool Function() isEnabled,
+ required Future<void> Function() checkForUpdate,
+ Duration delay = startupUpdateCheckDelay,
+}) async {
+ await Future<void>.delayed(delay);
+ if (!isEnabled()) {
+ return;
+ }
+ await checkForUpdate();
+}