未验证 提交 124163cd 编写于 作者: O openharmony_ci 提交者: Gitee

!24096 [Fix]: 电源服务文档的ArkTS适配

Merge pull request !24096 from 龙晓峰/master
......@@ -42,10 +42,10 @@ getBatteryStats(): Promise<Array&lt;BatteryStatsInfo&gt;>
```js
batteryStats.getBatteryStats()
.then(data => {
.then((data: batteryStats.BatteryStatsInfo[]) => {
console.info('battery statistics info: ' + data);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('get battery statistics failed, err: ' + err);
});
```
......@@ -77,7 +77,7 @@ getBatteryStats(callback: AsyncCallback<Array&lt;BatteryStatsInfo&gt;>): void
**示例:**
```js
batteryStats.getBatteryStats((err, data) => {
batteryStats.getBatteryStats((err: BusinessError<void>, data: batteryStats.BatteryStatsInfo[]) => {
if (typeof err === 'undefined') {
console.info('battery statistics info: ' + data);
} else {
......@@ -120,7 +120,7 @@ getAppPowerValue(uid: number): number
```js
try {
var value = batteryStats.getAppPowerValue(10021);
let value = batteryStats.getAppPowerValue(10021);
console.info('battery statistics value of app is: ' + value);
} catch(err) {
console.error('get battery statistics value of app failed, err: ' + err);
......@@ -161,7 +161,7 @@ getAppPowerPercent(uid: number): number
```js
try {
var percent = batteryStats.getAppPowerPercent(10021);
let percent = batteryStats.getAppPowerPercent(10021);
console.info('battery statistics percent of app is: ' + percent);
} catch(err) {
console.error('get battery statistics percent of app failed, err: ' + err);
......@@ -202,7 +202,7 @@ getHardwareUnitPowerValue(type: ConsumptionType): number
```js
try {
var value = batteryStats.getHardwareUnitPowerValue(batteryStats.ConsumptionType.CONSUMPTION_TYPE_SCREEN);
let value = batteryStats.getHardwareUnitPowerValue(batteryStats.ConsumptionType.CONSUMPTION_TYPE_SCREEN);
console.info('battery statistics value of hardware is: ' + value);
} catch(err) {
console.error('get battery statistics percent of hardware failed, err: ' + err);
......@@ -243,7 +243,7 @@ getHardwareUnitPowerPercent(type: ConsumptionType): number
```js
try {
var percent = batteryStats.getHardwareUnitPowerPercent(batteryStats.ConsumptionType.CONSUMPTION_TYPE_SCREEN);
let percent = batteryStats.getHardwareUnitPowerPercent(batteryStats.ConsumptionType.CONSUMPTION_TYPE_SCREEN);
console.info('battery statistics percent of hardware is: ' + percent);
} catch(err) {
console.error('get battery statistics percent of hardware failed, err: ' + err);
......
......@@ -104,7 +104,7 @@ isActive(): boolean
```js
try {
var isActive = power.isActive();
let isActive = power.isActive();
console.info('power is active: ' + isActive);
} catch(err) {
console.error('check active status failed, err: ' + err);
......@@ -206,7 +206,7 @@ getPowerMode(): DevicePowerMode
```js
try {
var mode = power.getPowerMode();
let mode = power.getPowerMode();
console.info('power mode: ' + mode);
} catch(err) {
console.error('get power mode failed, err: ' + err);
......@@ -243,7 +243,7 @@ setPowerMode(mode: DevicePowerMode, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, err => {
power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, (err: BusinessError<void>) => {
if (typeof err === 'undefined') {
console.info('set power mode to MODE_PERFORMANCE');
} else {
......@@ -322,7 +322,7 @@ isStandby(): boolean
```js
try {
var isStandby = power.isStandby();
let isStandby = power.isStandby();
console.info('device is in standby: ' + isStandby);
} catch(err) {
console.error('check isStandby failed, err: ' + err);
......@@ -372,7 +372,7 @@ isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
**示例:**
```js
power.isScreenOn((err, data) => {
power.isScreenOn((err: BusinessError<void>, data: boolean) => {
if (typeof err === 'undefined') {
console.info('screen on status is ' + data);
} else {
......@@ -400,10 +400,10 @@ isScreenOn(): Promise&lt;boolean&gt;
```js
power.isScreenOn()
.then(data => {
.then((data: boolean) => {
console.info('screen on status is ' + data);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('check screen status failed, err: ' + err);
})
```
......
......@@ -44,7 +44,7 @@ isSupported(type: RunningLockType): boolean;
```js
try {
var isSupported = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND);
let isSupported = runningLock.isSupported(runningLock.RunningLockType.BACKGROUND);
console.info('BACKGROUND type supported: ' + isSupported);
} catch(err) {
console.error('check supported failed, err: ' + err);
......@@ -72,7 +72,7 @@ create(name: string, type: RunningLockType, callback: AsyncCallback&lt;RunningLo
**示例:**
```js
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND, (err, lock) => {
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND, (err: BusinessError<void>, lock: runningLock.RunningLock) => {
if (typeof err === 'undefined') {
console.info('created running lock: ' + lock);
} else {
......@@ -108,10 +108,10 @@ create(name: string, type: RunningLockType): Promise&lt;RunningLock&gt;
```js
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
console.info('created running lock: ' + lock);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, error: ' + err);
});
```
......@@ -136,7 +136,7 @@ isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback&lt;boo
**示例:**
```js
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (err, data) => {
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND, (err: BusinessError<void>, data: boolean) => {
if (typeof err === 'undefined') {
console.info('BACKGROUND lock support status: ' + data);
} else {
......@@ -171,10 +171,10 @@ isRunningLockTypeSupported(type: RunningLockType): Promise&lt;boolean>
```js
runningLock.isRunningLockTypeSupported(runningLock.RunningLockType.BACKGROUND)
.then(data => {
.then((data: boolean) => {
console.info('BACKGROUND lock support status: ' + data);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.log('check BACKGROUND lock support status failed, err: ' + err);
});
```
......@@ -202,7 +202,7 @@ createRunningLock(name: string, type: RunningLockType, callback: AsyncCallback&l
**示例:**
```js
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND, (err, lock) => {
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND, (err: BusinessError<void>, lock: runningLock.RunningLock) => {
if (typeof err === 'undefined') {
console.info('created running lock: ' + lock);
} else {
......@@ -240,10 +240,10 @@ createRunningLock(name: string, type: RunningLockType): Promise&lt;RunningLock&g
```js
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
console.info('created running lock: ' + lock);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.log('create running lock failed, err: ' + err);
});
```
......@@ -280,7 +280,7 @@ hold(timeout: number): void
```js
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
console.info('create running lock success');
try {
lock.hold(500);
......@@ -289,7 +289,7 @@ runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
console.error('hold running lock failed, err: ' + err);
}
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, err: ' + err);
});
```
......@@ -316,7 +316,7 @@ unhold(): void
```js
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
console.info('create running lock success');
try {
lock.unhold();
......@@ -325,7 +325,7 @@ runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
console.error('unhold running lock failed, err: ' + err);
}
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, err: ' + err);
});
```
......@@ -356,16 +356,16 @@ isHolding(): boolean
```js
runningLock.create('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
console.info('create running lock success');
try {
var isHolding = lock.isHolding();
let isHolding = lock.isHolding();
console.info('check running lock holding status: ' + isHolding);
} catch(err) {
console.error('check running lock holding status failed, err: ' + err);
}
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, err: ' + err);
});
```
......@@ -392,11 +392,11 @@ lock(timeout: number): void
```js
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
lock.lock(500);
console.info('create running lock and lock success');
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, err: ' + err);
});
```
......@@ -417,11 +417,11 @@ unlock(): void
```js
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
.then((lock: runningLock.RunningLock) => {
lock.unlock();
console.info('create running lock and unlock success');
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('create running lock failed, err: ' + err);
});
```
......@@ -445,11 +445,11 @@ isUsed(): boolean
```js
runningLock.createRunningLock('running_lock_test', runningLock.RunningLockType.BACKGROUND)
.then(lock => {
var isUsed = lock.isUsed();
.then((lock: runningLock.RunningLock) => {
let isUsed = lock.isUsed();
console.info('check running lock used status: ' + isUsed);
})
.catch(err => {
.catch((err: { code: number, message: string }) => {
console.error('check running lock used status failed, err: ' + err);
});
```
......
......@@ -33,10 +33,10 @@ getStatus(options?: GetStatusOptions): void;
```js
battery.getStatus({
success: function(data) {
success: (data: BatteryResponse) => {
console.log('success get battery level:' + data.level);
},
fail: function(data, code) {
fail: (data: string, code: number) => {
console.error('fail to get battery level code:' + code + ', data: ' + data);
}
});
......
......@@ -34,10 +34,10 @@ getValue(options?: GetBrightnessOptions): void
```js
brightness.getValue({
success: function(data) {
success: (data: BrightnessResponse) => {
console.log('success get brightness value:' + data.value);
},
fail: function(data, code) {
fail: (data: string, code: number) => {
console.error('get brightness fail, code: ' + code + ', data: ' + data);
}
});
......@@ -63,10 +63,10 @@ setValue(options?: SetBrightnessOptions): void
```js
brightness.setValue({
value: 100,
success: function() {
success: () => {
console.log('handling set brightness success.');
},
fail: function(data, code) {
fail: (data: string, code: number) => {
console.error('handling set brightness value fail, code:' + code + ', data: ' + data);
}
});
......@@ -91,10 +91,10 @@ getMode(options?: GetBrightnessModeOptions): void
```js
brightness.getMode({
success: function(data) {
success: (data: BrightnessModeResponse) => {
console.log('success get mode:' + data.mode);
},
fail: function(data, code){
fail: (data: string, code: number) => {
console.error('handling get mode fail, code:' + code + ', data: ' + data);
}
});
......@@ -119,10 +119,10 @@ setMode(options?: SetBrightnessModeOptions): void
```js
brightness.setMode({
mode: 1,
success: function() {
success: () => {
console.log('handling set mode success.');
},
fail: function(data, code) {
fail: (data: string, code: number) => {
console.error('handling set mode fail, code:' + code + ', data: ' + data);
}
});
......@@ -150,10 +150,10 @@ setKeepScreenOn(options?: SetKeepScreenOnOptions): void
```js
brightness.setKeepScreenOn({
keepScreenOn: true,
success: function () {
success: () => {
console.log('handling set keep screen on success.');
},
fail: function (data, code) {
fail: (data: string, code: number) => {
console.error('handling set keep screen on fail, code:' + code + ', data: ' + data);
}
});
......
......@@ -38,7 +38,7 @@ registerThermalLevelCallback(callback: Callback&lt;ThermalLevel&gt;): void
```js
try {
thermal.registerThermalLevelCallback(level => {
thermal.registerThermalLevelCallback((level: thermal.ThermalLevel) => {
console.info('thermal level is: ' + level);
});
console.info('register thermal level callback success.');
......@@ -108,7 +108,7 @@ getLevel(): ThermalLevel
```js
try {
var level = thermal.getLevel();
let level = thermal.getLevel();
console.info('thermal level is: ' + level);
} catch(err) {
console.error('get thermal level failed, err: ' + err);
......@@ -134,7 +134,7 @@ subscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void
**示例:**
```js
thermal.subscribeThermalLevel((level) => {
thermal.subscribeThermalLevel((err: BusinessError<void>, level: thermal.ThermalLevel) => {
console.info('thermal level is: ' + level);
});
```
......@@ -182,7 +182,7 @@ getThermalLevel(): ThermalLevel
**示例:**
```js
var level = thermal.getThermalLevel();
let level = thermal.getThermalLevel();
console.info('thermal level is: ' + level);
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册