From 93c9d14fe2ff3d226704d97e6471b5311e1b30a3 Mon Sep 17 00:00:00 2001 From: wgh19 Date: Wed, 15 May 2024 19:48:48 +0800 Subject: [PATCH] fix ui --- lib/appdata.dart | 6 ++++-- lib/foundation/image_provider.dart | 4 ++++ lib/pages/image_page.dart | 20 ++++++++++++++++---- lib/utils/io.dart | 8 ++++---- pubspec.yaml | 8 ++++---- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/appdata.dart b/lib/appdata.dart index 76ce75e..6069325 100644 --- a/lib/appdata.dart +++ b/lib/appdata.dart @@ -18,7 +18,7 @@ class _Appdata { "downloadSubPath": r"/${id}-p${index}.${ext}", "tagsWeight": "", "useTranslatedNameForDownload": false, - "maxDownloadParallels": 3 + "maxParallels": 3 }; bool lock = false; @@ -54,7 +54,9 @@ class _Appdata { if (settingsFile.existsSync()) { var json = jsonDecode(await settingsFile.readAsString()); for (var key in json.keys) { - settings[key] = json[key]; + if(json[key] != null) { + settings[key] = json[key]; + } } } if (settings["downloadPath"] == null) { diff --git a/lib/foundation/image_provider.dart b/lib/foundation/image_provider.dart index 19da40c..6ef5346 100644 --- a/lib/foundation/image_provider.dart +++ b/lib/foundation/image_provider.dart @@ -148,6 +148,10 @@ class CachedImageProvider extends BaseImageProvider { @override Future load(StreamController chunkEvents) async{ + chunkEvents.add(const ImageChunkEvent( + cumulativeBytesLoaded: 0, + expectedTotalBytes: 1, + )); var cached = await CacheManager().findCache(key); if(cached != null) { chunkEvents.add(const ImageChunkEvent( diff --git a/lib/pages/image_page.dart b/lib/pages/image_page.dart index f744418..f07997e 100644 --- a/lib/pages/image_page.dart +++ b/lib/pages/image_page.dart @@ -118,13 +118,25 @@ class _ImagePageState extends State with WindowListener { return File(res); } + String getExtensionName() { + var fileName = widget.url.split('/').last; + if(fileName.contains('.')){ + return '.${fileName.split('.').last}'; + } + return '.jpg'; + } + void showMenu() { menuController.showFlyout(builder: (context) => MenuFlyout( items: [ MenuFlyoutItem(text: Text("Save to".tl), onPressed: () async{ var file = await getFile(); if(file != null){ - saveFile(file); + var fileName = file.path.split('/').last; + if(!fileName.contains('.')){ + fileName += getExtensionName(); + } + saveFile(file, fileName); } }), MenuFlyoutItem(text: Text("Share".tl), onPressed: () async{ @@ -133,12 +145,12 @@ class _ImagePageState extends State with WindowListener { var fileName = file.path.split('/').last; String ext; if(!fileName.contains('.')){ - ext = 'jpg'; - fileName += '.jpg'; + ext = getExtensionName(); + fileName += getExtensionName(); } else { ext = file.path.split('.').last; } - var mediaType = switch(ext){ + var mediaType = switch(ext.replaceFirst('.', "")){ 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', diff --git a/lib/utils/io.dart b/lib/utils/io.dart index 5085131..51af035 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -50,11 +50,11 @@ String bytesToText(int bytes) { } } -void saveFile(File file) async{ +void saveFile(File file, [String? name]) async{ if(App.isDesktop) { var fileName = file.path.split('/').last; final FileSaveLocation? result = - await getSaveLocation(suggestedName: fileName); + await getSaveLocation(suggestedName: name ?? fileName); if (result == null) { return; } @@ -62,10 +62,10 @@ void saveFile(File file) async{ final Uint8List fileData = await file.readAsBytes(); String mimeType = 'image/${fileName.split('.').last}'; final XFile textFile = XFile.fromData( - fileData, mimeType: mimeType, name: fileName); + fileData, mimeType: mimeType, name: name ?? fileName); await textFile.saveTo(result.path); } else { - final params = SaveFileDialogParams(sourceFilePath: file.path); + final params = SaveFileDialogParams(sourceFilePath: file.path, fileName: name); await FlutterFileDialog.saveFile(params: params); } } \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 309d081..4bd885c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -107,7 +107,7 @@ flutter: # see https://flutter.dev/custom-fonts/#from-packages # font used for building windows application - fonts: - - family: font - fonts: - - asset: assets/SourceHanSansSC-Regular.otf \ No newline at end of file + #fonts: + # - family: font + # fonts: + # - asset: assets/SourceHanSansSC-Regular.otf \ No newline at end of file