@nativescript-community/perms
Advanced tools
Comparing version 2.2.4 to 2.2.5
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.2.5](https://github.com/nativescript-community/perms/compare/v2.2.4...v2.2.5) (2022-02-18) | ||
**Note:** Version bump only for package @nativescript-community/perms | ||
## [2.2.4](https://github.com/nativescript-community/perms/compare/v2.2.3...v2.2.4) (2022-02-17) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@nativescript-community/perms", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "An unified permissions API for NativeScript on iOS and Android.", | ||
@@ -35,3 +35,3 @@ "main": "./permissions", | ||
"readmeFilename": "README.md", | ||
"gitHead": "807fd4af58eb989863c287aa3a187077b059c223" | ||
"gitHead": "46607999dda92d2b39b3f1e8a0fc5572069ad8b5" | ||
} |
@@ -12,5 +12,5 @@ import { CheckOptions, Permissions as PermissionsType, RequestOptions, Status } from './permissions'; | ||
export declare function check(permission: PermissionsType, options?: CheckOptions): Promise<[Status, boolean]>; | ||
export declare function request(permission: PermissionsType | string[], options?: RequestOptions): Promise<[Status, boolean] | { | ||
[permission: string]: [Status, boolean]; | ||
export declare function request(permission: PermissionsType | PermissionsType[] | string[], options?: RequestOptions): Promise<[Status, boolean] | { | ||
[permission: string]: Status; | ||
}>; | ||
export declare function checkMultiple(permissions: PermissionsType[]): Promise<any>; |
@@ -293,3 +293,10 @@ import { Trace } from '@nativescript/core'; | ||
if (Array.isArray(permission)) { | ||
permission.forEach(s => s.startsWith('android.permission.') && types.push(s)); | ||
permission.forEach(s => { | ||
if (s.startsWith('android.permission.')) { | ||
types.push(s); | ||
} | ||
else { | ||
types.push(...getNativePermissions(s, options)); | ||
} | ||
}); | ||
} | ||
@@ -296,0 +303,0 @@ else { |
@@ -41,6 +41,8 @@ export type Status = 'authorized' | 'denied' | 'limited' | 'restricted' | 'undetermined'; | ||
export function check(permission: Permissions | string[], options?: CheckOptions): Promise<[Status, boolean]>; | ||
export type Result<T> = T extends any[] ? { [k: string]: Status } : [Status, boolean]; | ||
export function request(permission: Permissions | string[], options?: RequestOptions): Promise<[Status, boolean]>; | ||
export function check<T = Permissions>(permission: T, options?: CheckOptions): Promise<Result<T>>; | ||
export function checkMultiple(permissions: Permissions[]): Promise<{ [k: string]: string }>; | ||
export function request<T = Permissions | Permissions[] | string[]>(permission: T, options?: RequestOptions): Promise<Result<T>>; | ||
export function checkMultiple<T = Permissions[]>(permissions: T): Promise<Result<T>>; |
@@ -1,2 +0,2 @@ | ||
import { CheckOptions, RequestOptions } from './permissions'; | ||
import { CheckOptions, Permissions as PermissionsType, RequestOptions } from './permissions'; | ||
export * from './permissions.common'; | ||
@@ -12,3 +12,2 @@ export declare namespace PermissionsIOS { | ||
enum NSType { | ||
Unknown = 0, | ||
Location = "location", | ||
@@ -33,7 +32,13 @@ Camera = "camera", | ||
} | ||
declare type IOSPermissionTypes = `${PermissionsIOS.NSType}`; | ||
export declare function canOpenSettings(): Promise<boolean>; | ||
export declare function openSettings(): Promise<unknown>; | ||
export declare function getTypes(): string[]; | ||
export declare function check(permission: string, options?: CheckOptions): Promise<[PermissionsIOS.Status, boolean]>; | ||
export declare function request(permission: string, options?: RequestOptions): Promise<[PermissionsIOS.Status, boolean]>; | ||
export declare function checkMultiple(permissions: string[]): Promise<any>; | ||
export declare function getTypes(): ("location" | "camera" | "microphone" | "photo" | "contacts" | "event" | "reminder" | "bluetooth" | "notification" | "backgroundRefresh" | "speechRecognition" | "mediaLibrary" | "motion")[]; | ||
declare type SingleResult = [PermissionsIOS.Status, boolean]; | ||
interface MultipleResult { | ||
[k: string]: PermissionsIOS.Status; | ||
} | ||
declare type Result<T> = T extends any[] ? MultipleResult : SingleResult; | ||
export declare function check(permission: IOSPermissionTypes, options?: CheckOptions): Promise<SingleResult>; | ||
export declare function request<T extends IOSPermissionTypes | IOSPermissionTypes[]>(permission: T, options?: RequestOptions): Promise<Result<T>>; | ||
export declare function checkMultiple(permissions: PermissionsType[]): Promise<any>; |
@@ -584,3 +584,2 @@ import { Device, Trace } from '@nativescript/core'; | ||
(function (NSType) { | ||
NSType[NSType["Unknown"] = 0] = "Unknown"; | ||
NSType["Location"] = "location"; | ||
@@ -726,3 +725,3 @@ NSType["Camera"] = "camera"; | ||
default: | ||
return Promise.reject(NSType.Unknown); | ||
return Promise.reject('unknown'); | ||
} | ||
@@ -736,3 +735,3 @@ } | ||
}; | ||
const permissionTypes = Object.keys(PermissionsIOS.NSType).map(k => PermissionsIOS.NSType[k]); | ||
const permissionTypes = Object.values(PermissionsIOS.NSType); | ||
export function canOpenSettings() { | ||
@@ -747,3 +746,3 @@ return PermissionsIOS.canOpenSettings(); | ||
} | ||
export function check(permission, options) { | ||
export async function check(permission, options) { | ||
if (Trace.isEnabled()) { | ||
@@ -756,3 +755,3 @@ CLog(CLogTypes.info, 'check', permission, options); | ||
} | ||
return Promise.resolve([PermissionsIOS.Status.Authorized, true]); | ||
return [PermissionsIOS.Status.Authorized, true]; | ||
} | ||
@@ -768,6 +767,14 @@ let type; | ||
} | ||
export function request(permission, options) { | ||
export async function request(permission, options) { | ||
if (Trace.isEnabled()) { | ||
CLog(CLogTypes.info, 'request', permission, options); | ||
} | ||
if (Array.isArray(permission)) { | ||
const grantedPermissions = {}; | ||
for (let index = 0; index < permission.length; index++) { | ||
const res = await request(permission[index], options); | ||
grantedPermissions[permission[index]] = res[0]; | ||
} | ||
return grantedPermissions; | ||
} | ||
if (permissionTypes.indexOf(permission) === -1) { | ||
@@ -777,7 +784,6 @@ if (Trace.isEnabled()) { | ||
} | ||
return Promise.resolve([PermissionsIOS.Status.Authorized, true]); | ||
return [PermissionsIOS.Status.Authorized, true]; | ||
} | ||
if (permission === 'backgroundRefresh') { | ||
const error = new Error('@nativescript-community/perms: You cannot request backgroundRefresh'); | ||
return Promise.reject(error); | ||
throw new Error('@nativescript-community/perms: You cannot request backgroundRefresh'); | ||
} | ||
@@ -784,0 +790,0 @@ let type; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
115279
1258