diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 0eb913287b989cd4726dee74bea4d90f62188b2b..3d0fd648ea3364e8f1159db209dfd7f21740ed97 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -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' diff --git a/packages/uni-api/src/protocols/device/brightness.ts b/packages/uni-api/src/protocols/device/brightness.ts new file mode 100644 index 0000000000000000000000000000000000000000..950d6c610b3ce9d4ce88ecb44769546469b7ed4e --- /dev/null +++ b/packages/uni-api/src/protocols/device/brightness.ts @@ -0,0 +1,8 @@ +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 diff --git a/packages/uni-app-plus/src/service/api/device/brightness.ts b/packages/uni-app-plus/src/service/api/device/brightness.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0820aace98cba6a5a7f328532545f79b70751cd --- /dev/null +++ b/packages/uni-app-plus/src/service/api/device/brightness.ts @@ -0,0 +1,35 @@ +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_GET_SCREEN_BRIGHTNESS, + (_, { resolve }) => { + const value = plus.screen.getBrightness(false) + resolve({ value }) + } + ) + +export const setScreenBrightness = + defineAsyncApi( + API_SET_SCREEN_BRIGHTNESS, + (options, { resolve }) => { + plus.screen.setBrightness(options.value, false) + resolve() + } + ) + +export const setKeepScreenOn = defineAsyncApi( + API_SET_KEEP_SCREEN_ON, + (options, { resolve }) => { + plus.device.setWakelock(!!options.keepScreenOn) + resolve() + } +)