ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

luzader opened this issue · comments

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.

Looking into this

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

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.

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

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.