improve code

This commit is contained in:
nyne
2024-10-02 16:45:25 +08:00
parent 63aa4ee8b0
commit 20dfbf5125
3 changed files with 17 additions and 3 deletions

View File

@@ -324,7 +324,7 @@ class DownloadManager {
where illust_id = ?;
''', [illust.illustId]);
for(var image in images) {
File(image["path"] as String).deleteIfExists();
File(image["path"] as String).deleteIgnoreError();
}
_db.execute('''
delete from images

View File

@@ -12,6 +12,14 @@ extension FSExt on FileSystemEntity {
}
}
Future<void> deleteIgnoreError() async {
try {
await delete();
} catch (e) {
// ignore
}
}
int get size {
if (this is File) {
return (this as File).lengthSync();

View File

@@ -8,8 +8,14 @@ import 'package:url_launcher/url_launcher_string.dart';
Future<String> getLatestVersion() async {
var dio = AppDio();
var res = await dio
.get("https://api.github.com/repos/wgh136/pixes/releases/latest");
return (res.data["tag_name"] as String).replaceFirst("v", "");
.get("https://raw.githubusercontent.com/wgh136/pixes/refs/heads/master/pubspec.yaml");
var lines = (res.data as String).split("\n");
for (var line in lines) {
if (line.startsWith("version:")) {
return line.split(":")[1].split('+')[0].trim();
}
}
throw "Failed to get latest version";
}
/// Compare two versions.