All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xpenatan.gdx.backends.teavm.TeaPermissions Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package com.github.xpenatan.gdx.backends.teavm;

import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;

public class TeaPermissions {

  /** Returns the user permission status for a given API via the Permissions API
   * @param permission the permission, see w3c for all
   *           permissions
   * @param result handler of permission result */
  @JSBody(params = {"permission", "result"}, script =
          "if (\"permissions\" in navigator) {\n" +
          "    navigator.permissions.query({\n" +
          "        name: permission\n" +
          "    }).then(function (permissionStatus) {\n" +
          "        if (permissionStatus.state === 'granted') {\n" +
          "            result.granted();\n" +
          "        } else if (permissionStatus.state === 'denied') {\n" +
          "            result.denied();\n" +
          "        } else if (permissionStatus.state === 'prompt') {\n" +
          "            result.prompt();\n" +
          "        }\n" +
          "        permissionStatus.onchange = function() {\n" +
          "            if (permissionStatus.state === 'granted') {\n" +
          "                result.granted();\n" +
          "            } else if (permissionStatus.state === 'denied') {\n" +
          "                result.denied();\n" +
          "            } else if (permissionStatus.state === 'prompt') {\n" +
          "                result.prompt();\n" +
          "            }\n" +
          "       };\n" +
          "    });\n" +
          "} else {\n" +
          "    result.granted();\n" +
          "}")
  public native static void queryPermission (String permission, TeaPermissionResult result);

  /** See status-of-a-permission for more information */
  public interface TeaPermissionResult extends JSObject {
    /** the permission to access the feature is granted without asking the user */
    void granted ();

    /** accessing the feature is not allowed */
    void denied ();

    /** the user will be asked on permission if the feature is tried to access */
    void prompt ();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy