mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 15:30:40 +00:00
[mob] Add additional logs & error handling on permission grant screen
This commit is contained in:
parent
d7a2883b5c
commit
cc2b0a610f
@ -2,11 +2,13 @@ import "dart:async";
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import "package:logging/logging.dart";
|
||||||
import 'package:photo_manager/photo_manager.dart';
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
import "package:photos/generated/l10n.dart";
|
import "package:photos/generated/l10n.dart";
|
||||||
import 'package:photos/services/sync_service.dart';
|
import 'package:photos/services/sync_service.dart';
|
||||||
import "package:photos/theme/ente_theme.dart";
|
import "package:photos/theme/ente_theme.dart";
|
||||||
import "package:photos/utils/debouncer.dart";
|
import "package:photos/utils/debouncer.dart";
|
||||||
|
import "package:photos/utils/dialog_util.dart";
|
||||||
import "package:photos/utils/email_util.dart";
|
import "package:photos/utils/email_util.dart";
|
||||||
import "package:photos/utils/photo_manager_util.dart";
|
import "package:photos/utils/photo_manager_util.dart";
|
||||||
import "package:styled_text/styled_text.dart";
|
import "package:styled_text/styled_text.dart";
|
||||||
@ -20,6 +22,7 @@ class GrantPermissionsWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _GrantPermissionsWidgetState extends State<GrantPermissionsWidget> {
|
class _GrantPermissionsWidgetState extends State<GrantPermissionsWidget> {
|
||||||
final _debouncer = Debouncer(const Duration(milliseconds: 500));
|
final _debouncer = Debouncer(const Duration(milliseconds: 500));
|
||||||
|
final Logger _logger = Logger("_GrantPermissionsWidgetState");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -124,42 +127,55 @@ class _GrantPermissionsWidgetState extends State<GrantPermissionsWidget> {
|
|||||||
key: const ValueKey("grantPermissionButton"),
|
key: const ValueKey("grantPermissionButton"),
|
||||||
child: Text(S.of(context).grantPermission),
|
child: Text(S.of(context).grantPermission),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final state = await requestPhotoMangerPermissions();
|
try {
|
||||||
if (state == PermissionState.authorized ||
|
final state = await requestPhotoMangerPermissions();
|
||||||
state == PermissionState.limited) {
|
_logger.info("Permission state: $state");
|
||||||
await SyncService.instance.onPermissionGranted(state);
|
if (state == PermissionState.authorized ||
|
||||||
} else if (state == PermissionState.denied) {
|
state == PermissionState.limited) {
|
||||||
final AlertDialog alert = AlertDialog(
|
await SyncService.instance.onPermissionGranted(state);
|
||||||
title: Text(S.of(context).pleaseGrantPermissions),
|
} else if (state == PermissionState.denied) {
|
||||||
content: Text(
|
final AlertDialog alert = AlertDialog(
|
||||||
S.of(context).enteCanEncryptAndPreserveFilesOnlyIfYouGrant,
|
title: Text(S.of(context).pleaseGrantPermissions),
|
||||||
),
|
content: Text(
|
||||||
actions: [
|
S.of(context).enteCanEncryptAndPreserveFilesOnlyIfYouGrant,
|
||||||
TextButton(
|
|
||||||
child: Text(
|
|
||||||
S.of(context).ok,
|
|
||||||
style: Theme.of(context).textTheme.titleMedium!.copyWith(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context, rootNavigator: true).pop('dialog');
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
PhotoManager.openSetting();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
actions: [
|
||||||
);
|
TextButton(
|
||||||
// ignore: unawaited_futures
|
child: Text(
|
||||||
showDialog(
|
S.of(context).ok,
|
||||||
context: context,
|
style:
|
||||||
builder: (BuildContext context) {
|
Theme.of(context).textTheme.titleMedium!.copyWith(
|
||||||
return alert;
|
fontSize: 14,
|
||||||
},
|
fontWeight: FontWeight.w700,
|
||||||
barrierColor: Colors.black12,
|
),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true)
|
||||||
|
.pop('dialog');
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
PhotoManager.openSetting();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
// ignore: unawaited_futures
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
barrierColor: Colors.black12,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw Exception("Unknown permission state: $state");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
_logger.severe(
|
||||||
|
"Failed to request permission: ${e.toString()}",
|
||||||
|
e,
|
||||||
);
|
);
|
||||||
|
showGenericErrorDialog(context: context, error: e).ignore();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user