Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function setScreenBrightness (opts = {}) {
let res = {errMsg: 'setScreenBrightness:ok'}
const isObject = shouleBeObject(opts)
if (!isObject.res) {
res = {errMsg: `setScreenBrightness${isObject.msg}`}
console.error(res.errMsg)
return Promise.reject(res)
}
const {value, success, fail, complete}: any = opts
await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS)
const {status} = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS)
if (status === 'granted') {
try {
await (Brightness as any).setSystemBrightnessAsync(value)
return successHandler(success, complete)(res)
} catch (e) {
res.errMsg = `setScreenBrightness:fail invalid ${e}`
return errorHandler(fail, complete)(res)
}
}
}
export async function getScreenBrightness (opts = {}) {
let res = {errMsg: 'getScreenBrightness:ok'} as any
const isObject = shouleBeObject(opts)
if (!isObject.res) {
res = {errMsg: `getScreenBrightness${isObject.msg}`}
console.error(res.errMsg)
return Promise.reject(res)
}
const {success, fail, complete}: any = opts
await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS)
const {status} = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS)
if (status === 'granted') {
try {
res.num = await (Brightness as any).getBrightnessAsync()
return successHandler(success, complete)(res)
} catch (e) {
res.errMsg = `getScreenBrightness:fail invalid ${e}`
return errorHandler(fail, complete)(res)
}
}
}
export async function askAsyncPermissions (PermissionsType) {
const {status} = await Permissions.askAsync(PermissionsType)
return status
}