From 24b9bcd86ec1148bd9e3a0a195a2bd3d34e6ad49 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 25 Jan 2025 16:26:24 +0800 Subject: [PATCH] fix #155 --- lib/pages/comic_source_page.dart | 47 ++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/pages/comic_source_page.dart b/lib/pages/comic_source_page.dart index ff394ff..bdbb94c 100644 --- a/lib/pages/comic_source_page.dart +++ b/lib/pages/comic_source_page.dart @@ -19,8 +19,7 @@ class ComicSourcePage extends StatefulWidget { return 0; } var dio = AppDio(); - var res = await dio.get( - "https://raw.githubusercontent.com/venera-app/venera-configs/master/index.json"); + var res = await dio.get(appdata.settings['comicSourceListUrl']); if (res.statusCode != 200) { return -1; } @@ -299,9 +298,9 @@ class _BodyState extends State<_Body> { } } context.to(() => _EditFilePage(source.filePath, () async { - await ComicSource.reload(); - setState(() {}); - })); + await ComicSource.reload(); + setState(() {}); + })); } static Future update(ComicSource source) async { @@ -419,7 +418,8 @@ class _BodyState extends State<_Body> { } void help() { - launchUrlString("https://github.com/venera-app/venera/blob/master/doc/comic_source.md"); + launchUrlString( + "https://github.com/venera-app/venera/blob/master/doc/comic_source.md"); } Future handleAddSource(String url) async { @@ -521,18 +521,29 @@ class _ComicSourceListState extends State<_ComicSourceList> { var key = json![index]["key"]; var action = currentKey.contains(key) ? const Icon(Icons.check, size: 20).paddingRight(8) - : Tooltip( - message: "Add", - child: Button.icon( - color: context.colorScheme.primary, - icon: const Icon(Icons.add), - onPressed: () async { - await widget.onAdd( - "https://raw.githubusercontent.com/venera-app/venera-configs/master/${json![index]["fileName"]}"); - setState(() {}); - }, - ), - ); + : Button.filled( + child: Text("Add".tl), + onPressed: () async { + var fileName = json![index]["fileName"]; + var url = json![index]["url"]; + if (url == null || !(url.toString()).isURL) { + var listUrl = + appdata.settings['comicSourceListUrl'] as String; + if (listUrl + .replaceFirst("https://", "") + .replaceFirst("http://", "") + .contains("/")) { + url = + listUrl.substring(0, listUrl.lastIndexOf("/") + 1) + + fileName; + } else { + url = '$listUrl/$fileName'; + } + } + await widget.onAdd(url); + setState(() {}); + }, + ).fixHeight(32); return ListTile( title: Text(json![index]["name"]),