Skip to content

Commit

Permalink
Fix backup & restore
Browse files Browse the repository at this point in the history
  • Loading branch information
kodjodevf committed Dec 7, 2023
1 parent f64decf commit 1aa0ddf
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 30 deletions.
15 changes: 12 additions & 3 deletions lib/eval/model/m_bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/eval/model/source_preference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
}
}

Expand Down
9 changes: 5 additions & 4 deletions lib/models/source.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,7 +55,7 @@ class Source {
String? additionalParams;

Source(
{this.id = 0,
{this.id = Isar.autoIncrement,
this.name = '',
this.baseUrl = '',
this.lang = '',
Expand All @@ -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 = "",
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/browse/extension/extension_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) => "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/browse/sources/sources_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) => "",
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/more/backup_and_restore/providers/restore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -134,6 +134,7 @@ void doRestore(DoRestoreRef ref,
ref.invalidate(l10nLocaleStateProvider);
});
} catch (e) {
print(e);
botToast(e.toString());
}
BotToast.showNotification(
Expand Down
4 changes: 2 additions & 2 deletions lib/sources/source_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions lib/sources/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1aa0ddf

Please sign in to comment.