mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
fix: permission dialog (#1799)
* don't request photo permission on A13+ saving to system album requires no additional permission * fix permission dialog * update Signed-off-by: dom <githubaccount56556@proton.me> --------- Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -50,22 +50,24 @@ abstract final class ImageUtils {
|
||||
}
|
||||
|
||||
// 获取存储权限
|
||||
static Future<bool> requestStoragePer(BuildContext context) async {
|
||||
await Permission.storage.request();
|
||||
PermissionStatus status = await Permission.storage.status;
|
||||
static Future<bool> requestPer() async {
|
||||
final status = Platform.isAndroid
|
||||
? await Permission.storage.request()
|
||||
: await Permission.photos.request();
|
||||
if (status == PermissionStatus.denied ||
|
||||
status == PermissionStatus.permanentlyDenied) {
|
||||
if (!context.mounted) return false;
|
||||
showDialog(
|
||||
context: context,
|
||||
SmartDialog.show(
|
||||
builder: (context) {
|
||||
return const AlertDialog(
|
||||
title: Text('提示'),
|
||||
content: Text('存储权限未授权'),
|
||||
return AlertDialog(
|
||||
title: const Text('提示'),
|
||||
content: const Text('存储权限未授权'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: openAppSettings,
|
||||
child: Text('去授权'),
|
||||
onPressed: () {
|
||||
SmartDialog.dismiss();
|
||||
openAppSettings();
|
||||
},
|
||||
child: const Text('去授权'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -77,42 +79,25 @@ abstract final class ImageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取相册权限
|
||||
static Future<bool> requestPhotoPer() async {
|
||||
await Permission.photos.request();
|
||||
PermissionStatus status = await Permission.photos.status;
|
||||
if (status == PermissionStatus.denied ||
|
||||
status == PermissionStatus.permanentlyDenied) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> checkPermissionDependOnSdkInt(
|
||||
BuildContext context,
|
||||
) async {
|
||||
static Future<bool> checkPermissionDependOnSdkInt() async {
|
||||
if (Platform.isAndroid) {
|
||||
if (await Utils.sdkInt <= 32) {
|
||||
if (!context.mounted) return false;
|
||||
return requestStoragePer(context);
|
||||
if (await Utils.sdkInt < 29) {
|
||||
return requestPer();
|
||||
} else {
|
||||
return requestPhotoPer();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return requestStoragePer(context);
|
||||
return requestPer();
|
||||
}
|
||||
|
||||
static Future<bool> downloadLivePhoto({
|
||||
required BuildContext context,
|
||||
required String url,
|
||||
required String liveUrl,
|
||||
required int width,
|
||||
required int height,
|
||||
}) async {
|
||||
try {
|
||||
if (PlatformUtils.isMobile &&
|
||||
!await checkPermissionDependOnSdkInt(context)) {
|
||||
if (PlatformUtils.isMobile && !await checkPermissionDependOnSdkInt()) {
|
||||
return false;
|
||||
}
|
||||
if (!silentDownImg) SmartDialog.showLoading(msg: '正在下载');
|
||||
@@ -167,12 +152,10 @@ abstract final class ImageUtils {
|
||||
}
|
||||
|
||||
static Future<bool> downloadImg(
|
||||
BuildContext context,
|
||||
List<String> imgList, [
|
||||
CacheManager? manager,
|
||||
]) async {
|
||||
if (PlatformUtils.isMobile &&
|
||||
!await checkPermissionDependOnSdkInt(context)) {
|
||||
if (PlatformUtils.isMobile && !await checkPermissionDependOnSdkInt()) {
|
||||
return false;
|
||||
}
|
||||
CancelToken? cancelToken;
|
||||
|
||||
Reference in New Issue
Block a user