1 | import { __awaiter } from '../../node_modules/.pnpm/registry.npmjs.org_tslib@1.14.1/node_modules/tslib/tslib.es6.js';
|
2 | import { temporarilyNotSupport } from '../../utils/index.js';
|
3 | import { MethodHandler } from '../../utils/handler.js';
|
4 |
|
5 |
|
6 | const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
|
7 | const getBatteryInfo = ({ success, fail, complete } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
8 | var _a;
|
9 | const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
|
10 | try {
|
11 |
|
12 | const battery = yield ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
|
13 | return handle.success({
|
14 | isCharging: battery.charging,
|
15 | level: Number(battery.level || 0) * 100
|
16 | });
|
17 | }
|
18 | catch (error) {
|
19 | return handle.fail({
|
20 | errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
|
21 | });
|
22 | }
|
23 | });
|
24 |
|
25 | export { getBatteryInfo, getBatteryInfoSync };
|
26 |
|