Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
iOS: Handle limited or no permission (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 authored Aug 29, 2023
2 parents 7a2841c + 3379b4c commit 5200972
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/generated/intl/messages_en.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@
"startBackup": "Start backup",
"noPhotosAreBeingBackedUpRightNow": "No photos are being backed up right now",
"preserveMore": "Preserve more",
"grantFullAccessPrompt": "Please allow access to all photos in the Settings app",
"openSettings": "Open Settings",
"selectMorePhotos": "Select more photos",
"existingUser": "Existing user",
"privateBackups": "Private backups",
"forYourMemories": "for your memories",
Expand Down
10 changes: 10 additions & 0 deletions lib/services/local_sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ class LocalSyncService {
PermissionState.limited.toString();
}

bool hasGrantedFullPermission() {
return (_prefs.getString(kPermissionStateKey) ?? '') ==
PermissionState.authorized.toString();
}

Future<void> onUpdatePermission(PermissionState state) async {
await _prefs.setBool(kHasGrantedPermissionsKey, true);
await _prefs.setString(kPermissionStateKey, state.toString());
}

Future<void> onPermissionGranted(PermissionState state) async {
await _prefs.setBool(kHasGrantedPermissionsKey, true);
await _prefs.setString(kPermissionStateKey, state.toString());
Expand Down
45 changes: 41 additions & 4 deletions lib/ui/home/preserve_footer_widget.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import 'dart:async';
import "dart:io";

import 'package:flutter/material.dart';
import "package:flutter/services.dart";
import "package:logging/logging.dart";
import 'package:photo_manager/photo_manager.dart';
import "package:photos/core/configuration.dart";
import "package:photos/generated/l10n.dart";
import 'package:photos/services/local_sync_service.dart';
import 'package:photos/ui/common/gradient_button.dart';
import 'package:photos/ui/settings/backup/backup_folder_selection_page.dart';
import "package:photos/utils/dialog_util.dart";
import 'package:photos/utils/navigation_util.dart';

class PreserveFooterWidget extends StatelessWidget {
Expand All @@ -17,14 +22,46 @@ class PreserveFooterWidget extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(20, 24, 20, 100),
child: GradientButton(
onTap: () async {
if (LocalSyncService.instance.hasGrantedLimitedPermissions()) {
await PhotoManager.presentLimited();
try {
final PermissionState state =
await PhotoManager.requestPermissionExtend();
await LocalSyncService.instance.onUpdatePermission(state);
} on Exception catch (e) {
Logger("PreserveFooterWidget").severe(
"Failed to request permission: ${e.toString()}",
e,
);
}
if (!LocalSyncService.instance.hasGrantedFullPermission()) {
if (Platform.isAndroid) {
await PhotoManager.openSetting();
} else {
final bool hasGrantedLimit =
LocalSyncService.instance.hasGrantedLimitedPermissions();
showChoiceActionSheet(
context,
title: S.of(context).preserveMore,
body: S.of(context).grantFullAccessPrompt,
firstButtonLabel: S.of(context).openSettings,
firstButtonOnTap: () async {
await PhotoManager.openSetting();
},
secondButtonLabel: hasGrantedLimit
? S.of(context).selectMorePhotos
: S.of(context).cancel,
secondButtonOnTap: () async {
if (hasGrantedLimit) {
await PhotoManager.presentLimited();
}
},
);
}
} else {
unawaited(
routeToPage(
context,
const BackupFolderSelectionPage(
buttonText: "Preserve",
BackupFolderSelectionPage(
buttonText: S.of(context).backup,
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/settings/backup/backup_folder_selection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {
title: const Text(""),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(
height: 0,
),
SafeArea(
child: Container(
padding: const EdgeInsets.fromLTRB(24, 32, 24, 8),
padding: const EdgeInsets.fromLTRB(24, 8, 24, 8),
child: Text(
S.of(context).selectFoldersForBackup,
textAlign: TextAlign.left,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/viewer/file/file_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class FileAppBarState extends State<FileAppBar> {
);
}
// options for files owned by the user
if (isOwnedByUser && !isFileHidden) {
if (isOwnedByUser && !isFileHidden && isFileUploaded) {
final bool isArchived =
widget.file.magicMetadata.visibility == archiveVisibility;
items.add(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: ente photos application
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.7.84+484
version: 0.7.87+487

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down

0 comments on commit 5200972

Please sign in to comment.