Fix backup & restore

This commit is contained in:
kodjomoustapha 2023-12-07 18:13:12 +01:00
parent f64decf8b6
commit 1aa0ddf9e6
11 changed files with 44 additions and 30 deletions

View file

@ -456,7 +456,15 @@ class MBridge {
List<dynamic> valD = [];
for (var date in val) {
if (date.toString().isNotEmpty) {
valD.add(parseChapterDate(date, dateFormat, dateFormatLocale));
valD.add(parseChapterDate(
date,
dateFormat,
dateFormatLocale,
(val) {
dateFormat = val.$1;
dateFormatLocale = val.$2;
},
));
}
}
return valD;
@ -610,8 +618,8 @@ class MBridge {
}
//Parse a chapter date to millisecondsSinceEpoch
static String parseChapterDate(
String date, String dateFormat, String dateFormatLocale) {
static String parseChapterDate(String date, String dateFormat,
String dateFormatLocale, Function((String, String)) newLocale) {
int parseRelativeDate(String date) {
final number = int.tryParse(RegExp(r"(\d+)").firstMatch(date)!.group(0)!);
if (number == null) return 0;
@ -703,6 +711,7 @@ class MBridge {
for (var locale in supportedLocales) {
for (var dateFormat in _dateFormats) {
newLocale((dateFormat, locale));
try {
initializeDateFormatting(locale);
if (WordSet(["yesterday", "يوم واحد"]).startsWith(date)) {

View file

@ -152,9 +152,9 @@ class MultiSelectListPreference {
return MultiSelectListPreference(
title: json['title'],
summary: json['summary'],
entries: json['entries'],
entryValues: json['entryValues'],
values: json['values']);
entries: json['entries']?.cast<String>(),
entryValues: json['entryValues']?.cast<String>(),
values: json['values']?.cast<String>());
}
}

View file

@ -1,5 +1,6 @@
import 'package:isar/isar.dart';
import 'package:mangayomi/eval/model/m_source.dart';
import 'package:mangayomi/sources/source_test.dart';
part 'source.g.dart';
@collection
@ -54,7 +55,7 @@ class Source {
String? additionalParams;
Source(
{this.id = 0,
{this.id = Isar.autoIncrement,
this.name = '',
this.baseUrl = '',
this.lang = '',
@ -71,9 +72,9 @@ class Source {
this.lastUsed = false,
this.apiUrl = "",
this.sourceCodeUrl = "",
this.version = "",
this.versionLast = "",
this.sourceCode = '',
this.version = "0.0.1",
this.versionLast = "0.0.1",
this.sourceCode = testSourceCode,
this.headers = '',
this.isManga = true,
this.appMinVerReq = "",

View file

@ -64,9 +64,9 @@ class ExtensionScreen extends ConsumerWidget {
child: Column(
children: [
if (useTestSourceCode)
ExtensionListTileWidget(
source: testSourceModel,
isTestSource: useTestSourceCode),
for (var e in testSourceModelList)
ExtensionListTileWidget(
source: e, isTestSource: useTestSourceCode),
GroupedListView<Source, String>(
elements: entries,
groupBy: (element) => "",

View file

@ -3,7 +3,6 @@ import 'package:mangayomi/eval/model/source_preference.dart';
import 'package:mangayomi/main.dart';
import 'package:mangayomi/models/source.dart';
import 'package:mangayomi/services/get_source_preference.dart';
import 'package:mangayomi/sources/source_test.dart';
void setPreferenceSetting(SourcePreference sourcePreference, Source source) {
final sourcePref = isar.sourcePreferences
@ -42,11 +41,11 @@ SourcePreference getSourcePreferenceEntry(String key, int sourceId) {
.sourceIdEqualTo(sourceId)
.keyEqualTo(key)
.findFirstSync();
final source =
useTestSourceCode ? testSourceModel : isar.sources.getSync(sourceId)!;
final source = isar.sources.getSync(sourceId)!;
if (sourcePreference == null) {
sourcePreference = getSourcePreference(source: source)
.firstWhere((element) => element.key == key, orElse: () => throw "Error when getting source preference");
sourcePreference = getSourcePreference(source: source).firstWhere(
(element) => element.key == key,
orElse: () => throw "Error when getting source preference");
setPreferenceSetting(sourcePreference, source);
}

View file

@ -92,12 +92,13 @@ Future fetchAnimeSourcesList(FetchAnimeSourcesListRef ref,
});
} else {
// log("update aivalable");
isar.sources.putSync(sourc..versionLast = source.version);
isar.writeTxnSync(() => isar.sources
.putSync(sourc..versionLast = source.version));
}
}
}
} else {
isar.sources.putSync(Source()
isar.writeTxnSync(() => isar.sources.putSync(Source()
..sourceCodeUrl = source.sourceCodeUrl
..id = source.id
..sourceCode = source.sourceCode
@ -115,7 +116,7 @@ Future fetchAnimeSourcesList(FetchAnimeSourcesListRef ref,
..versionLast = source.version
..isManga = source.isManga
..isFullData = source.isFullData ?? false
..appMinVerReq = source.appMinVerReq);
..appMinVerReq = source.appMinVerReq));
// log("new source");
}
}

View file

@ -94,12 +94,13 @@ Future fetchMangaSourcesList(FetchMangaSourcesListRef ref,
});
} else {
// log("update aivalable");
isar.sources.putSync(sourc..versionLast = source.version);
isar.writeTxnSync(() => isar.sources
.putSync(sourc..versionLast = source.version));
}
}
}
} else {
isar.sources.putSync(Source()
isar.writeTxnSync(() => isar.sources.putSync(Source()
..sourceCodeUrl = source.sourceCodeUrl
..id = source.id
..sourceCode = source.sourceCode
@ -117,7 +118,7 @@ Future fetchMangaSourcesList(FetchMangaSourcesListRef ref,
..versionLast = source.version
..isManga = source.isManga
..isFullData = source.isFullData ?? false
..appMinVerReq = source.appMinVerReq);
..appMinVerReq = source.appMinVerReq));
// log("new source");
}
}

View file

@ -55,7 +55,8 @@ class SourcesScreen extends ConsumerWidget {
child: Column(
children: [
if (useTestSourceCode)
SourceListTile(source: testSourceModel, isManga: isManga),
for (var e in testSourceModelList)
SourceListTile(source: e, isManga: isManga),
GroupedListView<Source, String>(
elements: entries,
groupBy: (element) => "",

View file

@ -122,7 +122,7 @@ void doRestore(DoRestoreRef ref,
if (extensionsPref != null) {
isar.sourcePreferences.putAllSync(extensionsPref);
}
print("object");
isar.settings.clearSync();
if (settings != null) {
isar.settings.putAllSync(settings);
@ -134,6 +134,7 @@ void doRestore(DoRestoreRef ref,
ref.invalidate(l10nLocaleStateProvider);
});
} catch (e) {
print(e);
botToast(e.toString());
}
BotToast.showNotification(

View file

@ -3,7 +3,7 @@ import 'package:mangayomi/models/source.dart';
//For testing purposes, set to true
const useTestSourceCode = false;
final testSourceModel = Source(
final testSourceModelList = [Source(
name: "Test Source",
// Example: https://gogoanime3.net
baseUrl: "",
@ -12,7 +12,7 @@ final testSourceModel = Source(
// Example: en
lang: "",
// Example: false for anime or true for manga
isManga: false);
isManga: false)];
const testSourceCode = r'''
import 'package:mangayomi/bridge_lib.dart';

View file

@ -4,8 +4,9 @@ import 'package:mangayomi/models/source.dart';
import 'package:mangayomi/sources/source_test.dart';
Source? getSource(String lang, String name) {
if (useTestSourceCode) {
return testSourceModel;
if (testSourceModelList.isNotEmpty && useTestSourceCode) {
return testSourceModelList
.firstWhere((element) => element.lang == lang && element.name == name);
}
try {
final sourcesList = isar.sources.filter().idIsNotNull().findAllSync();