diff --git a/lib/appdata.dart b/lib/appdata.dart index 4b1bf0a..90243da 100644 --- a/lib/appdata.dart +++ b/lib/appdata.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:pixes/utils/io.dart'; import 'foundation/app.dart'; import 'network/models.dart'; @@ -43,12 +44,13 @@ class _Appdata { } } - String get downloadPath => settings["downloadPath"]; - Future get _defaultDownloadPath async{ if(App.isAndroid) { - var externalStoragePaths = await getExternalStorageDirectories(type: StorageDirectory.downloads); - var res = externalStoragePaths?.first.path; + String? downloadPath = "/storage/emulated/0/download"; + if (!Directory(downloadPath).havePermission()) { + downloadPath = null; + } + var res = downloadPath; res ??= (await getExternalStorageDirectory())!.path; return "$res/pixes"; } else if (App.isWindows){ @@ -58,7 +60,7 @@ class _Appdata { } } else if (App.isMacOS || App.isLinux) { var downloadPath = (await getDownloadsDirectory())?.path; - if(downloadPath != null) { + if(downloadPath != null && Directory(downloadPath).havePermission()) { return "$downloadPath/pixes"; } } diff --git a/lib/network/download.dart b/lib/network/download.dart index ea4314e..e9fe25c 100644 --- a/lib/network/download.dart +++ b/lib/network/download.dart @@ -113,18 +113,19 @@ class DownloadingTask { static String _generateFilePath(Illust illust, int index, String ext) { final String downloadPath = appdata.settings["downloadPath"]; - final String subPathPatten = appdata.settings["downloadSubPath"]; + String subPathPatten = appdata.settings["downloadSubPath"]; final tags = appdata.settings["useTranslatedNameForDownload"] == false ? illust.tags.map((e) => e.name).toList() : illust.tags.map((e) => e.translatedName ?? e.name).toList(); final tagsWeight = (appdata.settings["tagsWeight"] as String).split(' '); tags.sort((a, b) => tagsWeight.indexOf(a) - tagsWeight.indexOf(b)); - subPathPatten.replaceAll(r"${id}", illust.id.toString()); - subPathPatten.replaceAll(r"${title}", illust.title); - subPathPatten.replaceAll(r"${author}", illust.author.name); - subPathPatten.replaceAll(r"${ext}", ext); + subPathPatten = subPathPatten.replaceAll(r"${id}", illust.id.toString()); + subPathPatten = subPathPatten.replaceAll(r"${title}", illust.title); + subPathPatten = subPathPatten.replaceAll(r"${author}", illust.author.name); + subPathPatten = subPathPatten.replaceAll(r"${index}", index.toString()); + subPathPatten = subPathPatten.replaceAll(r"${ext}", ext); for(int i=0; i { } Widget buildImage(double width, double height, int index) { - File? downloadFile; - if(widget.illust.downloaded) { - downloadFile = DownloadManager().getImage(widget.illust.id, index); - } - if (index == 0) { return Text( widget.illust.title, @@ -86,6 +81,10 @@ class _IllustPageState extends State { ).paddingVertical(8).paddingHorizontal(12); } index--; + File? downloadFile; + if(widget.illust.downloaded) { + downloadFile = DownloadManager().getImage(widget.illust.id, index); + } if (index == widget.illust.images.length) { return const SizedBox( height: _kBottomBarHeight, @@ -107,6 +106,7 @@ class _IllustPageState extends State { ? widget.illust.images[index].original : "file://${downloadFile.path}"), child: Image( + key: ValueKey(index), image: downloadFile == null ? CachedImageProvider(widget.illust.images[index].large) as ImageProvider : FileImage(downloadFile) as ImageProvider, diff --git a/lib/pages/image_page.dart b/lib/pages/image_page.dart index 86b8238..71aea2f 100644 --- a/lib/pages/image_page.dart +++ b/lib/pages/image_page.dart @@ -53,9 +53,9 @@ class _ImagePageState extends State with WindowListener{ @override Widget build(BuildContext context) { - return ColoredBox( - color: FluentTheme.of(context).micaBackgroundColor.withOpacity(1), - child: Stack( + return ScaffoldPage( + padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), + content: Stack( children: [ Positioned.fill(child: PhotoView( backgroundDecoration: const BoxDecoration( @@ -82,7 +82,8 @@ class _ImagePageState extends State with WindowListener{ const Expanded( child: DragToMoveArea(child: SizedBox.expand(),), ), - WindowButtons(key: ValueKey(windowButtonKey),), + if(App.isDesktop) + WindowButtons(key: ValueKey(windowButtonKey),), ], ), ), diff --git a/lib/utils/io.dart b/lib/utils/io.dart index ca097e7..89e747c 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -21,6 +21,18 @@ extension FSExt on FileSystemEntity { } } +extension DirectoryExt on Directory { + bool havePermission() { + if(!existsSync()) return false; + try { + listSync(); + return true; + } catch (e) { + return false; + } + } +} + String bytesToText(int bytes) { if(bytes < 1024) { return "$bytes B";