Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@capacitor/filesystem] Successful Filesystem.requestPermissions prompt never resolves due to missing case in callback #2075

Closed
luzader opened this issue Apr 9, 2024 · 5 comments
Assignees

Comments

@luzader
Copy link

luzader commented Apr 9, 2024

Bug Report

Plugin(s)

filesystem

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 5.7.4
  @capacitor/core: 5.7.4
  @capacitor/android: 5.7.4
  @capacitor/ios: 5.7.4

Installed Dependencies:

  @capacitor/cli: 5.6.0
  @capacitor/core: 5.6.0
  @capacitor/ios: 5.6.0
  @capacitor/android: 5.6.0

Platform(s)

Android 10 and earlier

Current Behavior

A call to Filesystem.requestPermissions() which displays a prompt, that the user then accepts neither resolves nor rejects.

Expected Behavior

The call should resolve with the PermissionStatus object.

Code Reproduction

try {
const result = await Filesystem.requestPermissions()
} catch {
console.error("This message will never print.")
}
console.error("This message will never print if a prompt was displayed and the user touched 'allow'.")

Other Technical Details

When calling Filesystem.requestPermissions() directly (and not implicitly because of some other call), the proper permissions prompt is displayed (when state is "prompt" or "prompt-with-rationale" on Android 10 and earlier) and the permission is granted correctly but the javascript call never resolves. This is because the switch statement in permissionCallback just falls through, because there's no case for "requestPermissions":

Fixable by adding:

          case "requestPermissions":
            JSObject permissionsResultJSON = new JSObject();
            permissionsResultJSON.put(PUBLIC_STORAGE, "granted");
            call.resolve(permissionsResultJSON);
              break;

(Or by calling this.requestPermissions(call) though this is recursion, or by an equivalent refactoring.)
It looks like this bug applies to all 5.x and 6.x releases and main.

Additional Context

In our application it is very nice to prompt the user to allow filesystem permissions when they first touch "export", rather than after they have already filled out the subsequent dialog.

@IT-MikeS
Copy link
Contributor

Looking into this

@IT-MikeS IT-MikeS self-assigned this Apr 10, 2024
@jcesarmobile
Copy link
Member

Are you sure you are using latest version of @capacitor/filesystem?
this was (supposedly) fixed in version 5.2.1 and 6.0.0-rc.0

@luzader
Copy link
Author

luzader commented Apr 11, 2024

Good call. We were on 5.2.0, upgrading to 5.2.1 fixes this.
The correct code path goes through the base class (I guess?), which I neglected to check.
Close as invalid or whichever status is customary. Sorry for the noise.

@jcesarmobile
Copy link
Member

Yeah, the Plugin class already handles requestPermissions() callbacks, so no need to add a new case in the plugins switch.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
Copy link

ionitron-bot bot commented Apr 26, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants