提交 1b5dcdd9 编写于 作者: inkwalk's avatar inkwalk

feat(App): setScreenBrightness、getScreenBrightness、setKeepScreenOn

上级 2d45beca
......@@ -30,6 +30,7 @@ export * from './protocols/device/compass'
export * from './protocols/device/vibrate'
export * from './protocols/device/bluetooth'
export * from './protocols/device/ibeacon'
export * from './protocols/device/brightness'
export * from './protocols/storage/storage'
......
export const API_GET_SCREEN_BRIGHTNESS = 'getScreenBrightness'
export type API_TYPE_GET_SCREEN_BRIGHTNESS = typeof uni.getScreenBrightness
export const API_SET_SCREEN_BRIGHTNESS = 'setScreenBrightness'
export type API_TYPE_SET_SCREEN_BRIGHTNESS = typeof uni.setScreenBrightness
export const API_SET_KEEP_SCREEN_ON = 'setKeepScreenOn'
export type API_TYPE_SET_KEEP_SCREEN_ON = typeof uni.setKeepScreenOn
import {
defineAsyncApi,
API_GET_SCREEN_BRIGHTNESS,
API_TYPE_GET_SCREEN_BRIGHTNESS,
API_SET_SCREEN_BRIGHTNESS,
API_TYPE_SET_SCREEN_BRIGHTNESS,
API_SET_KEEP_SCREEN_ON,
API_TYPE_SET_KEEP_SCREEN_ON,
} from '@dcloudio/uni-api'
export const getScreenBrightness =
defineAsyncApi<API_TYPE_GET_SCREEN_BRIGHTNESS>(
API_GET_SCREEN_BRIGHTNESS,
(_, { resolve }) => {
const value = plus.screen.getBrightness(false)
resolve({ value })
}
)
export const setScreenBrightness =
defineAsyncApi<API_TYPE_SET_SCREEN_BRIGHTNESS>(
API_SET_SCREEN_BRIGHTNESS,
(options, { resolve }) => {
plus.screen.setBrightness(options.value, false)
resolve()
}
)
export const setKeepScreenOn = defineAsyncApi<API_TYPE_SET_KEEP_SCREEN_ON>(
API_SET_KEEP_SCREEN_ON,
(options, { resolve }) => {
plus.device.setWakelock(!!options.keepScreenOn)
resolve()
}
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册