UNPKG

1.07 kBJavaScriptView Raw
1import { __awaiter } from '../../node_modules/.pnpm/registry.npmjs.org_tslib@1.14.1/node_modules/tslib/tslib.es6.js';
2import { temporarilyNotSupport } from '../../utils/index.js';
3import { MethodHandler } from '../../utils/handler.js';
4
5// 电量
6const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
7const 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 // @ts-ignore
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
25export { getBatteryInfo, getBatteryInfoSync };
26//# sourceMappingURL=battery.js.map