mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve updating configs.
This commit is contained in:
@@ -156,23 +156,27 @@ class _BodyState extends State<_Body> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> update(ComicSource source) async {
|
static Future<void> update(ComicSource source,
|
||||||
|
[bool showLoading = true]) async {
|
||||||
if (!source.url.isURL) {
|
if (!source.url.isURL) {
|
||||||
App.rootContext.showMessage(message: "Invalid url config");
|
App.rootContext.showMessage(message: "Invalid url config");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComicSource.remove(source.key);
|
ComicSource.remove(source.key);
|
||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
var controller = showLoadingDialog(
|
LoadingDialogController? controller;
|
||||||
App.rootContext,
|
if (showLoading) {
|
||||||
onCancel: () => cancel = true,
|
controller = showLoadingDialog(
|
||||||
barrierDismissible: false,
|
App.rootContext,
|
||||||
);
|
onCancel: () => cancel = true,
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
var res = await AppDio().get<String>(source.url,
|
var res = await AppDio().get<String>(source.url,
|
||||||
options: Options(responseType: ResponseType.plain));
|
options: Options(responseType: ResponseType.plain));
|
||||||
if (cancel) return;
|
if (cancel) return;
|
||||||
controller.close();
|
controller?.close();
|
||||||
await ComicSourceParser().parse(res.data!, source.filePath);
|
await ComicSourceParser().parse(res.data!, source.filePath);
|
||||||
await File(source.filePath).writeAsString(res.data!);
|
await File(source.filePath).writeAsString(res.data!);
|
||||||
if (ComicSource.availableUpdates.containsKey(source.key)) {
|
if (ComicSource.availableUpdates.containsKey(source.key)) {
|
||||||
@@ -551,13 +555,59 @@ class _CheckUpdatesButtonState extends State<_CheckUpdatesButton> {
|
|||||||
} else if (count == 0) {
|
} else if (count == 0) {
|
||||||
context.showMessage(message: "No updates".tl);
|
context.showMessage(message: "No updates".tl);
|
||||||
} else {
|
} else {
|
||||||
context.showMessage(message: "@c updates".tlParams({"c": count}));
|
showUpdateDialog();
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showUpdateDialog() async {
|
||||||
|
var text = ComicSource.availableUpdates.entries.map((e) {
|
||||||
|
return "${ComicSource.find(e.key)!.name}: ${e.value}";
|
||||||
|
}).join("\n");
|
||||||
|
bool doUpdate = false;
|
||||||
|
await showDialog(
|
||||||
|
context: App.rootContext,
|
||||||
|
builder: (context) {
|
||||||
|
return ContentDialog(
|
||||||
|
title: "Updates".tl,
|
||||||
|
content: Text(text).paddingHorizontal(16),
|
||||||
|
actions: [
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
doUpdate = true;
|
||||||
|
context.pop();
|
||||||
|
},
|
||||||
|
child: Text("Update".tl),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (doUpdate) {
|
||||||
|
var loadingController = showLoadingDialog(
|
||||||
|
context,
|
||||||
|
message: "Updating".tl,
|
||||||
|
withProgress: true,
|
||||||
|
);
|
||||||
|
int current = 0;
|
||||||
|
int total = ComicSource.availableUpdates.length;
|
||||||
|
try {
|
||||||
|
var shouldUpdate = ComicSource.availableUpdates.keys.toList();
|
||||||
|
for (var key in shouldUpdate) {
|
||||||
|
var source = ComicSource.find(key)!;
|
||||||
|
await _BodyState.update(source, false);
|
||||||
|
current++;
|
||||||
|
loadingController.setProgress(current / total);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
context.showMessage(message: e.toString());
|
||||||
|
}
|
||||||
|
loadingController.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Button.normal(
|
return Button.normal(
|
||||||
|
Reference in New Issue
Block a user