From 1b5dcdd926bc96bd95999da944d5165d48f14e55 Mon Sep 17 00:00:00 2001 From: tianjiaxing Date: Fri, 25 Jun 2021 20:36:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(App):=20setScreenBrightness=E3=80=81getScr?= =?UTF-8?q?eenBrightness=E3=80=81setKeepScreenOn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-api/src/index.ts | 1 + .../src/protocols/device/brightness.ts | 8 +++++ .../src/service/api/device/brightness.ts | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 packages/uni-api/src/protocols/device/brightness.ts create mode 100644 packages/uni-app-plus/src/service/api/device/brightness.ts diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 0eb913287..3d0fd648e 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 000000000..950d6c610 --- /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 000000000..b0820aace --- /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() + } +) -- GitLab