beeware / beeware/toga

Modify Camera and Location APIs to automatically ask for permission on demand

Open
#4,471 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

### What is the problem or limitation you are having?

The current documented idiom for using the Camera API is to ask for permission prior to first use:
```
async def take_photo(self, widget, **kwargs):
try:
if not self.camera.has_permission:
await self.camera.request_permission()

image = await self.camera.take_photo()
except PermissionError:
await self.main_window.dialog(toga.ErrorDialog(...))
```
(Similar idioms are used for location service requests).

This works, but is a little complicated as every usage of `take_photo()` effectively needs to be prefaced by a call to check permissions.

It also technically allows for permission requests to be made independent of the actual device request, which is contrary to the HIG for both iOS and Android, which recommend making permission requests as close to the first actual usage as possible.

### Describe the solution you'd like

The APIs on the Camera and Location service that require permissions should be automatically perform that permission request - the usage idiom should be something similar to:
```
async def take_photo(self, widget, **kwargs):
try:
image = await self.camera.take_photo()
except PermissionError:
await self.main_window.dialog(toga.ErrorDialog(...))
```

This could be achieved through use of a decorator on the hardware service APIs.

### Describe alternatives you've considered

Maintain the status quo.

### Additional context

The APIs to explicitly request permissions should be retained, if for no other reason that requesting *background* location permissions is something that requires an explicit request that will be independent of a specific location service.

It may be possible to simplify some of the backends, as they will no longer need to have in-implemenation checks that permission exists. For example `_impl.take_photo()` will no longer need to perform a permission check, because the wrapper method on the public interface will be confirming that permission exists.

Contributor guide

Open the contributing guide

Research direction

Start with the public Camera and Location service APIs and trace how their permission checks reach backend methods such as `_impl.take_photo()`. Compare the proposed decorator approach with the existing explicit permission methods, including the separate background-location case. Done means permission-dependent calls request access on demand, preserve explicit requests where needed, and support the simplified usage idiom.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.