This commit is contained in:
wgh19
2024-05-15 19:48:48 +08:00
parent 6c02bf65ab
commit 93c9d14fe2
5 changed files with 32 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ class _Appdata {
"downloadSubPath": r"/${id}-p${index}.${ext}",
"tagsWeight": "",
"useTranslatedNameForDownload": false,
"maxDownloadParallels": 3
"maxParallels": 3
};
bool lock = false;
@@ -54,9 +54,11 @@ class _Appdata {
if (settingsFile.existsSync()) {
var json = jsonDecode(await settingsFile.readAsString());
for (var key in json.keys) {
if(json[key] != null) {
settings[key] = json[key];
}
}
}
if (settings["downloadPath"] == null) {
settings["downloadPath"] = await _defaultDownloadPath;
}

View File

@@ -148,6 +148,10 @@ class CachedImageProvider extends BaseImageProvider<CachedImageProvider> {
@override
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async{
chunkEvents.add(const ImageChunkEvent(
cumulativeBytesLoaded: 0,
expectedTotalBytes: 1,
));
var cached = await CacheManager().findCache(key);
if(cached != null) {
chunkEvents.add(const ImageChunkEvent(

View File

@@ -118,13 +118,25 @@ class _ImagePageState extends State<ImagePage> 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<ImagePage> 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',

View File

@@ -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);
}
}

View File

@@ -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
#fonts:
# - family: font
# fonts:
# - asset: assets/SourceHanSansSC-Regular.otf