mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Improve init
This commit is contained in:
@@ -3,8 +3,11 @@ import 'dart:ui';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:venera/foundation/history.dart';
|
||||||
|
|
||||||
import 'appdata.dart';
|
import 'appdata.dart';
|
||||||
|
import 'favorites.dart';
|
||||||
|
import 'local.dart';
|
||||||
|
|
||||||
export "widget_utils.dart";
|
export "widget_utils.dart";
|
||||||
export "context.dart";
|
export "context.dart";
|
||||||
@@ -51,6 +54,14 @@ class _App {
|
|||||||
|
|
||||||
BuildContext get rootContext => rootNavigatorKey.currentContext!;
|
BuildContext get rootContext => rootNavigatorKey.currentContext!;
|
||||||
|
|
||||||
|
final Appdata data = appdata;
|
||||||
|
|
||||||
|
final HistoryManager history = HistoryManager();
|
||||||
|
|
||||||
|
final LocalFavoritesManager favorites = LocalFavoritesManager();
|
||||||
|
|
||||||
|
final LocalManager local = LocalManager();
|
||||||
|
|
||||||
void rootPop() {
|
void rootPop() {
|
||||||
rootNavigatorKey.currentState?.maybePop();
|
rootNavigatorKey.currentState?.maybePop();
|
||||||
}
|
}
|
||||||
@@ -66,6 +77,10 @@ class _App {
|
|||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
cachePath = (await getApplicationCacheDirectory()).path;
|
cachePath = (await getApplicationCacheDirectory()).path;
|
||||||
dataPath = (await getApplicationSupportDirectory()).path;
|
dataPath = (await getApplicationSupportDirectory()).path;
|
||||||
|
await data.init();
|
||||||
|
await history.init();
|
||||||
|
await favorites.init();
|
||||||
|
await local.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
Function? _forceRebuildHandler;
|
Function? _forceRebuildHandler;
|
||||||
|
@@ -6,8 +6,8 @@ import 'package:venera/foundation/app.dart';
|
|||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
|
|
||||||
class _Appdata {
|
class Appdata {
|
||||||
final _Settings settings = _Settings();
|
final Settings settings = Settings();
|
||||||
|
|
||||||
var searchHistory = <String>[];
|
var searchHistory = <String>[];
|
||||||
|
|
||||||
@@ -110,10 +110,10 @@ class _Appdata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final appdata = _Appdata();
|
final appdata = Appdata();
|
||||||
|
|
||||||
class _Settings with ChangeNotifier {
|
class Settings with ChangeNotifier {
|
||||||
_Settings();
|
Settings();
|
||||||
|
|
||||||
final _data = <String, dynamic>{
|
final _data = <String, dynamic>{
|
||||||
'comicDisplayMode': 'detailed', // detailed, brief
|
'comicDisplayMode': 'detailed', // detailed, brief
|
||||||
|
@@ -4,10 +4,7 @@ import 'package:rhttp/rhttp.dart';
|
|||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
import 'package:venera/foundation/cache_manager.dart';
|
import 'package:venera/foundation/cache_manager.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
import 'package:venera/foundation/favorites.dart';
|
|
||||||
import 'package:venera/foundation/history.dart';
|
|
||||||
import 'package:venera/foundation/js_engine.dart';
|
import 'package:venera/foundation/js_engine.dart';
|
||||||
import 'package:venera/foundation/local.dart';
|
|
||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/network/cookie_jar.dart';
|
import 'package:venera/network/cookie_jar.dart';
|
||||||
import 'package:venera/pages/comic_source_page.dart';
|
import 'package:venera/pages/comic_source_page.dart';
|
||||||
@@ -32,25 +29,18 @@ extension _FutureInit<T> on Future<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await Rhttp.init();
|
|
||||||
await SAFTaskWorker().init().wait();
|
|
||||||
await AppTranslation.init().wait();
|
|
||||||
await appdata.init().wait();
|
|
||||||
await App.init().wait();
|
await App.init().wait();
|
||||||
await HistoryManager().init().wait();
|
|
||||||
await TagsTranslation.readData().wait();
|
|
||||||
await LocalFavoritesManager().init().wait();
|
|
||||||
SingleInstanceCookieJar("${App.dataPath}/cookie.db");
|
SingleInstanceCookieJar("${App.dataPath}/cookie.db");
|
||||||
await JsEngine().init().wait();
|
var futures = [
|
||||||
await ComicSource.init().wait();
|
Rhttp.init(),
|
||||||
await LocalManager().init().wait();
|
SAFTaskWorker().init().wait(),
|
||||||
|
AppTranslation.init().wait(),
|
||||||
|
TagsTranslation.readData().wait(),
|
||||||
|
JsEngine().init().then((_) => ComicSource.init()).wait(),
|
||||||
|
];
|
||||||
|
await Future.wait(futures);
|
||||||
CacheManager().setLimitSize(appdata.settings['cacheSize']);
|
CacheManager().setLimitSize(appdata.settings['cacheSize']);
|
||||||
if (appdata.settings['searchSources'] == null) {
|
_checkOldConfigs();
|
||||||
appdata.settings['searchSources'] = ComicSource.all()
|
|
||||||
.where((e) => e.searchPageData != null)
|
|
||||||
.map((e) => e.key)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
if (App.isAndroid) {
|
if (App.isAndroid) {
|
||||||
handleLinks();
|
handleLinks();
|
||||||
}
|
}
|
||||||
@@ -59,6 +49,15 @@ Future<void> init() async {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _checkOldConfigs() {
|
||||||
|
if (appdata.settings['searchSources'] == null) {
|
||||||
|
appdata.settings['searchSources'] = ComicSource.all()
|
||||||
|
.where((e) => e.searchPageData != null)
|
||||||
|
.map((e) => e.key)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _checkAppUpdates() async {
|
Future<void> _checkAppUpdates() async {
|
||||||
var lastCheck = appdata.implicitData['lastCheckUpdate'] ?? 0;
|
var lastCheck = appdata.implicitData['lastCheckUpdate'] ?? 0;
|
||||||
var now = DateTime.now().millisecondsSinceEpoch;
|
var now = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
Reference in New Issue
Block a user