mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Impl saveFile on Windows platform
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart';
|
||||
import '../api/client.dart';
|
||||
import '../api/gallery.dart';
|
||||
import '../globals.dart';
|
||||
@@ -45,6 +46,7 @@ class Thumbnail extends StatefulWidget {
|
||||
enum _ThumbnailMenu {
|
||||
copyImage,
|
||||
copyImgUrl,
|
||||
saveAs,
|
||||
}
|
||||
|
||||
class _Thumbnail extends State<Thumbnail> {
|
||||
@@ -55,6 +57,7 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
bool _showNsfw = false;
|
||||
String? _uri;
|
||||
CancelToken? _cancel;
|
||||
String? _fileName;
|
||||
Future<void> _fetchData() async {
|
||||
try {
|
||||
_cancel = CancelToken();
|
||||
@@ -106,6 +109,7 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
_fileId = widget._fileId;
|
||||
_showNsfw = false;
|
||||
_uri = null;
|
||||
_fileName = "${basenameWithoutExtension(widget._pMeta.name)}_thumb";
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -133,6 +137,13 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
_log.warning("Failed to copy image url to clipboard:", err);
|
||||
}
|
||||
break;
|
||||
case _ThumbnailMenu.saveAs:
|
||||
try {
|
||||
await platformPath.saveFile(_fileName!, "image/jpeg", _data!);
|
||||
} catch (err) {
|
||||
_log.warning("Failed to save image:", err);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +171,9 @@ class _Thumbnail extends State<Thumbnail> {
|
||||
PopupMenuItem(
|
||||
value: _ThumbnailMenu.copyImgUrl,
|
||||
child: Text(AppLocalizations.of(context)!.copyImgUrl)),
|
||||
PopupMenuItem(
|
||||
value: _ThumbnailMenu.saveAs,
|
||||
child: Text(AppLocalizations.of(context)!.saveAs)),
|
||||
];
|
||||
return list;
|
||||
}));
|
||||
|
||||
@@ -35,5 +35,6 @@
|
||||
"none": "none",
|
||||
"sortByGid": "Sort by gallery id",
|
||||
"asc": "Ascending",
|
||||
"desc": "Descending"
|
||||
"desc": "Descending",
|
||||
"saveAs": "Save As"
|
||||
}
|
||||
|
||||
@@ -35,5 +35,6 @@
|
||||
"none": "无",
|
||||
"sortByGid": "按画廊ID排序",
|
||||
"asc": "升序",
|
||||
"desc": "降序"
|
||||
"desc": "降序",
|
||||
"saveAs": "另存为"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ final Logger _log = Logger("platformPath");
|
||||
|
||||
class Path {
|
||||
static const platform = MethodChannel("lifegpc.eh_downloader_flutter/path");
|
||||
static const _safChannel=MethodChannel("lifegpc.eh_downloader_flutter/saf");
|
||||
static const _safChannel = MethodChannel("lifegpc.eh_downloader_flutter/saf");
|
||||
String? _currentExe;
|
||||
bool _currentExeLoaded = false;
|
||||
|
||||
@@ -28,7 +28,10 @@ class Path {
|
||||
}
|
||||
|
||||
/// 保存文件
|
||||
static Future<void> saveFile(String filenameWithoutExtension,String mimeType,Uint8List bytes,{String dir=""}) async{
|
||||
return _safChannel.invokeMethod("saveFile",[filenameWithoutExtension,dir,mimeType,bytes]);
|
||||
Future<void> saveFile(
|
||||
String filenameWithoutExtension, String mimeType, Uint8List bytes,
|
||||
{String dir = ""}) async {
|
||||
return _safChannel.invokeMethod(
|
||||
"saveFile", [filenameWithoutExtension, dir, mimeType, bytes]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user