more
This commit is contained in:
parent
9b6528064e
commit
4f131de97d
10 changed files with 103 additions and 33 deletions
|
|
@ -168,4 +168,18 @@ class $MSource implements MSource, $Instance {
|
|||
|
||||
@override
|
||||
set additionalParams(String? additionalParams) {}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => {
|
||||
'apiUrl': apiUrl,
|
||||
'baseUrl': baseUrl,
|
||||
'dateFormat': dateFormat,
|
||||
'dateFormatLocale': dateFormatLocale,
|
||||
'hasCloudflare': hasCloudflare,
|
||||
'id': id,
|
||||
'isFullData': isFullData,
|
||||
'lang': lang,
|
||||
'name': name,
|
||||
'additionalParams': additionalParams
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,13 +40,25 @@ class MManga {
|
|||
description: json['description'],
|
||||
author: json['author'],
|
||||
artist: json['artist'],
|
||||
status: json['status'],
|
||||
genre: json['genre'] ?? [],
|
||||
status: switch (json['status'] as int?) {
|
||||
0 => Status.ongoing,
|
||||
1 => Status.completed,
|
||||
2 => Status.onHiatus,
|
||||
3 => Status.canceled,
|
||||
4 => Status.publishingFinished,
|
||||
_ => Status.unknown,
|
||||
},
|
||||
genre:
|
||||
(json['genre'] as List?)?.map((e) => e.toString()).toList() ?? [],
|
||||
chapters: json['chapters'] != null
|
||||
? (json['chapters'] as List)
|
||||
.map((e) => MChapter.fromJson(e))
|
||||
.toList()
|
||||
: []);
|
||||
: json['episodes'] != null
|
||||
? (json['episodes'] as List)
|
||||
.map((e) => MChapter.fromJson(e))
|
||||
.toList()
|
||||
: []);
|
||||
}
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
|
|
|
|||
|
|
@ -30,4 +30,17 @@ class MSource {
|
|||
this.dateFormatLocale,
|
||||
this.apiUrl,
|
||||
this.additionalParams});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'apiUrl': apiUrl,
|
||||
'baseUrl': baseUrl,
|
||||
'dateFormat': dateFormat,
|
||||
'dateFormatLocale': dateFormatLocale,
|
||||
'hasCloudflare': hasCloudflare,
|
||||
'id': id,
|
||||
'isFullData': isFullData,
|
||||
'lang': lang,
|
||||
'name': name,
|
||||
'additionalParams': additionalParams
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class SourcePreference {
|
|||
|
||||
factory SourcePreference.fromJson(Map<String, dynamic> json) {
|
||||
return SourcePreference(
|
||||
id: json['id'],
|
||||
id: json['id'] ?? Isar.autoIncrement,
|
||||
sourceId: json['sourceId'],
|
||||
key: json['key'],
|
||||
checkBoxPreference: json['checkBoxPreference'] != null
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ class Element {
|
|||
}
|
||||
attr(attr) {
|
||||
return sendMessage(
|
||||
"attr",
|
||||
"ele_attr",
|
||||
JSON.stringify([attr, this.key])
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,34 +8,36 @@ class JsPreferences {
|
|||
JsPreferences(this.runtime, this.source);
|
||||
|
||||
init() {
|
||||
runtime.onMessage('getPreferenceValue', (dynamic args) {
|
||||
runtime.onMessage('get', (dynamic args) {
|
||||
return getPreferenceValue(source!.id!, args[0]);
|
||||
});
|
||||
runtime.onMessage('getPrefStringValue', (dynamic args) {
|
||||
runtime.onMessage('getString', (dynamic args) {
|
||||
return getSourcePreferenceStringValue(source!.id!, args[0], args[1]);
|
||||
});
|
||||
runtime.onMessage('setPrefStringValue', (dynamic args) {
|
||||
runtime.onMessage('setString', (dynamic args) {
|
||||
return setSourcePreferenceStringValue(source!.id!, args[0], args[1]);
|
||||
});
|
||||
|
||||
runtime.evaluate('''
|
||||
function getPreferenceValue(key) {
|
||||
return = sendMessage(
|
||||
"getPreferenceValue",
|
||||
JSON.stringify([key])
|
||||
);
|
||||
}
|
||||
function getPrefStringValue(key,defaultValue) {
|
||||
return sendMessage(
|
||||
"getPrefStringValue",
|
||||
JSON.stringify([key,defaultValue])
|
||||
);
|
||||
}
|
||||
function setPrefStringValue(key,defaultValue) {
|
||||
return sendMessage(
|
||||
"setPrefStringValue",
|
||||
JSON.stringify([key,defaultValue])
|
||||
);
|
||||
class SharedPreferences {
|
||||
get(key) {
|
||||
return sendMessage(
|
||||
"get",
|
||||
JSON.stringify([key])
|
||||
);
|
||||
}
|
||||
getString(key, defaultValue) {
|
||||
return sendMessage(
|
||||
"getString",
|
||||
JSON.stringify([key, defaultValue])
|
||||
);
|
||||
}
|
||||
setString(key, defaultValue) {
|
||||
return sendMessage(
|
||||
"setString",
|
||||
JSON.stringify([key, defaultValue])
|
||||
);
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,11 @@ class JsExtensionService {
|
|||
JsUtils(runtime).init();
|
||||
JsPreferences(runtime, source).init();
|
||||
|
||||
runtime.evaluate(r'''
|
||||
runtime.evaluate('''
|
||||
class MProvider {
|
||||
get source() {
|
||||
return JSON.parse('${jsonEncode(source!.toMSource().toJson())}');
|
||||
}
|
||||
async getPopular(page) {
|
||||
throw new Error("getPopular not implemented");
|
||||
}
|
||||
|
|
@ -93,7 +96,6 @@ var extention = new DefaultExtension();
|
|||
final res = (await runtime.handlePromise(await runtime
|
||||
.evaluateAsync('jsonStringify(() => extention.getDetail("$url"))')))
|
||||
.stringResult;
|
||||
|
||||
return MManga.fromJson(jsonDecode(res));
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +136,7 @@ var extention = new DefaultExtension();
|
|||
.evaluate('JSON.stringify(extention.getSourcePreferences())')
|
||||
.stringResult;
|
||||
return (jsonDecode(res) as List)
|
||||
.map((e) => SourcePreference.fromJson(e))
|
||||
.map((e) => SourcePreference.fromJson(e)..sourceId = source!.id)
|
||||
.toList();
|
||||
} catch (_) {
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:convert';
|
||||
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||
import 'package:js_packer/js_packer.dart';
|
||||
import 'package:mangayomi/eval/dart/model/m_bridge.dart';
|
||||
|
|
@ -32,14 +31,36 @@ class JsUtils {
|
|||
runtime.onMessage('unpackJs', (dynamic args) {
|
||||
return JSPacker(args[0]).unpack() ?? "";
|
||||
});
|
||||
runtime.onMessage('parseDates', (dynamic args) {
|
||||
return jsonEncode(MBridge.parseDates(args[0], args[1], args[2]));
|
||||
});
|
||||
|
||||
runtime.evaluate('''
|
||||
console.log = function (message) {
|
||||
if (typeof message === "object") {
|
||||
message = JSON.stringify(message);
|
||||
}
|
||||
sendMessage("log", JSON.stringify([message.toString()]));
|
||||
};
|
||||
function substringAfter(text, pattern) {
|
||||
const startIndex = text.indexOf(pattern);
|
||||
if (startIndex === -1) return text.substring(0);
|
||||
|
||||
const start = startIndex + pattern.length;
|
||||
return text.substring(start);
|
||||
}
|
||||
function substringBefore(text, pattern) {
|
||||
const endIndex = text.indexOf(pattern);
|
||||
if (endIndex === -1) return text.substring(0);
|
||||
|
||||
return text.substring(0, endIndex);
|
||||
}
|
||||
function substringBeforeLast(text, pattern) {
|
||||
const endIndex = text.lastIndexOf(pattern);
|
||||
if (endIndex === -1) return text.substring(0);
|
||||
|
||||
return text.substring(0, endIndex);
|
||||
}
|
||||
function substringAfterLast(text, pattern) {
|
||||
return text.split(pattern).pop();
|
||||
}
|
||||
function cryptoHandler(text, iv, secretKeyString, encrypt) {
|
||||
return sendMessage(
|
||||
"cryptoHandler",
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ Future fetchAnimeSourcesList(FetchAnimeSourcesListRef ref,
|
|||
..isManga = source.isManga
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage
|
||||
..additionalParams = source.additionalParams ?? "");
|
||||
});
|
||||
// log("successfully installed or updated");
|
||||
|
|
@ -89,6 +90,7 @@ Future fetchAnimeSourcesList(FetchAnimeSourcesListRef ref,
|
|||
..isManga = source.isManga
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage
|
||||
..additionalParams = source.additionalParams ?? "");
|
||||
});
|
||||
} else {
|
||||
|
|
@ -116,7 +118,8 @@ Future fetchAnimeSourcesList(FetchAnimeSourcesListRef ref,
|
|||
..versionLast = source.version
|
||||
..isManga = source.isManga
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq);
|
||||
..appMinVerReq = source.appMinVerReq
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage);
|
||||
// log("new source");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ Future fetchMangaSourcesList(FetchMangaSourcesListRef ref,
|
|||
..isManga = source.isManga
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage
|
||||
..additionalParams = source.additionalParams ?? "");
|
||||
});
|
||||
// log("successfully installed or updated");
|
||||
|
|
@ -91,6 +92,7 @@ Future fetchMangaSourcesList(FetchMangaSourcesListRef ref,
|
|||
..isManga = source.isManga
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage
|
||||
..additionalParams = source.additionalParams ?? "");
|
||||
});
|
||||
} else {
|
||||
|
|
@ -117,6 +119,7 @@ Future fetchMangaSourcesList(FetchMangaSourcesListRef ref,
|
|||
..version = source.version
|
||||
..versionLast = source.version
|
||||
..isManga = source.isManga
|
||||
..sourceCodeLanguage = source.sourceCodeLanguage
|
||||
..isFullData = source.isFullData ?? false
|
||||
..appMinVerReq = source.appMinVerReq);
|
||||
// log("new source");
|
||||
|
|
|
|||
Loading…
Reference in a new issue