mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
home page
This commit is contained in:
@@ -144,7 +144,7 @@ class RandomCategoryPartWithRuntimeData extends BaseCategoryPart {
|
||||
}
|
||||
|
||||
CategoryData getCategoryDataWithKey(String key) {
|
||||
for (var source in ComicSource.sources) {
|
||||
for (var source in ComicSource._sources) {
|
||||
if (source.categoryData?.key == key) {
|
||||
return source.categoryData!;
|
||||
}
|
||||
|
@@ -43,13 +43,31 @@ typedef GetThumbnailLoadingConfigFunc = Map<String, dynamic> Function(
|
||||
String imageKey)?;
|
||||
|
||||
class ComicSource {
|
||||
static List<ComicSource> sources = [];
|
||||
static final List<ComicSource> _sources = [];
|
||||
|
||||
static final List<Function> _listeners = [];
|
||||
|
||||
static void addListener(Function listener) {
|
||||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
static void removeListener(Function listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
|
||||
static void notifyListeners() {
|
||||
for (var listener in _listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
static List<ComicSource> all() => List.from(_sources);
|
||||
|
||||
static ComicSource? find(String key) =>
|
||||
sources.firstWhereOrNull((element) => element.key == key);
|
||||
_sources.firstWhereOrNull((element) => element.key == key);
|
||||
|
||||
static ComicSource? fromIntKey(int key) =>
|
||||
sources.firstWhereOrNull((element) => element.key.hashCode == key);
|
||||
_sources.firstWhereOrNull((element) => element.key.hashCode == key);
|
||||
|
||||
static Future<void> init() async {
|
||||
final path = "${App.dataPath}/comic_source";
|
||||
@@ -62,7 +80,7 @@ class ComicSource {
|
||||
try {
|
||||
var source = await ComicSourceParser()
|
||||
.parse(await entity.readAsString(), entity.absolute.path);
|
||||
sources.add(source);
|
||||
_sources.add(source);
|
||||
} catch (e, s) {
|
||||
Log.error("ComicSource", "$e\n$s");
|
||||
}
|
||||
@@ -71,9 +89,20 @@ class ComicSource {
|
||||
}
|
||||
|
||||
static Future reload() async {
|
||||
sources.clear();
|
||||
_sources.clear();
|
||||
JsEngine().runCode("ComicSource.sources = {};");
|
||||
await init();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
static void add(ComicSource source) {
|
||||
_sources.add(source);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
static void remove(String key) {
|
||||
_sources.removeWhere((element) => element.key == key);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Name of this source.
|
||||
@@ -123,7 +152,7 @@ class ComicSource {
|
||||
|
||||
var data = <String, dynamic>{};
|
||||
|
||||
bool get isLogin => data["account"] != null;
|
||||
bool get isLogged => data["account"] != null;
|
||||
|
||||
final String filePath;
|
||||
|
||||
|
@@ -105,7 +105,7 @@ class ComicSourceParser {
|
||||
throw ComicSourceParseException("minAppVersion $minAppVersion is required");
|
||||
}
|
||||
}
|
||||
for(var source in ComicSource.sources){
|
||||
for(var source in ComicSource.all()){
|
||||
if(source.key == key){
|
||||
throw ComicSourceParseException("key($key) already exists");
|
||||
}
|
||||
@@ -188,8 +188,7 @@ class ComicSourceParser {
|
||||
ComicSource.sources.$_key.account.login(${jsonEncode(account)},
|
||||
${jsonEncode(pwd)})
|
||||
""");
|
||||
var source = ComicSource.sources
|
||||
.firstWhere((element) => element.key == _key);
|
||||
var source = ComicSource.find(_key!)!;
|
||||
source.data["account"] = <String>[account, pwd];
|
||||
source.saveData();
|
||||
return const Res(true);
|
||||
@@ -461,7 +460,7 @@ class ComicSourceParser {
|
||||
final bool multiFolder = _getValue("favorites.multiFolder");
|
||||
|
||||
Future<Res<T>> retryZone<T>(Future<Res<T>> Function() func) async{
|
||||
if(!ComicSource.find(_key!)!.isLogin){
|
||||
if(!ComicSource.find(_key!)!.isLogged){
|
||||
return const Res.error("Not login");
|
||||
}
|
||||
var res = await func();
|
||||
|
Reference in New Issue
Block a user