Initial commit

This commit is contained in:
2026-03-16 10:37:46 +08:00
commit c052a67816
508 changed files with 22987 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts';
import IntentFilter from 'android.content.IntentFilter';
import Intent from 'android.content.Intent';
import { GetBatteryInfoFailImpl } from '../unierror';
/**
* 异步获取电量
*/
export const getBatteryInfo: GetBatteryInfo = function (options: GetBatteryInfoOptions) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager;
const level = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res: GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: isCharging
};
options.success?.(res);
options.complete?.(res);
}
else {
let res = new GetBatteryInfoFailImpl(1001);
options.fail?.(res);
options.complete?.(res);
}
};
/**
* 同步获取电量
*/
export const getBatteryInfoSync: GetBatteryInfoSync = function (): GetBatteryInfoResult {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager;
const level = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
let batteryStatus = context.registerReceiver(null, ifilter);
let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
const res: GetBatteryInfoResult = {
level: level,
isCharging: isCharging
};
return res;
}
else {
/**
* 无有效上下文
*/
const res: GetBatteryInfoResult = {
level: -1,
isCharging: false
};
return res;
}
};
//# sourceMappingURL=index.uts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.uts","sourceRoot":"","sources":["uni_modules/uni-getbatteryinfo/utssdk/app-android/index.uts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,yBAAyB,CAAC;AAC9C,OAAO,cAAc,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACzI,OAAO,YAAY,MAAM,8BAA8B,CAAC;AACxD,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,EAAG,cAAc,GAAG,UAAU,OAAO,EAAG,qBAAqB;IACtF,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;IAC3C,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CACtC,OAAO,CAAC,eAAe,CACxB,IAAI,cAAc,CAAC;QACpB,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,CAClC,cAAc,CAAC,yBAAyB,CACzC,CAAC;QAEF,IAAI,OAAO,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QAC9D,IAAI,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,MAAM,GAAG,aAAa,EAAE,WAAW,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;QACzE,IAAI,UAAU,GAAG,MAAM,IAAI,cAAc,CAAC,uBAAuB,IAAI,MAAM,IAAI,cAAc,CA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ACvB,CAAC;QACF,OAAO,GAAG,CAAC;KACZ;SACI;QACH;;WAEG;QACH,MAAM,GAAG,EAAG,oBAAoB,GAAG;YACjC,KAAK,EAAE,CAAC,CAAC;YACT,UAAU,EAAE,KAAK;SAClB,CAAC;QACF,OAAO,GAAG,CAAC;KACZ;AACH,CAAC,CAAA","sourcesContent":["import Context from \"android.content.Context\";\r\nimport BatteryManager from \"android.os.BatteryManager\";\r\n\r\nimport { GetBatteryInfo, GetBatteryInfoOptions, GetBatteryInfoSuccess, GetBatteryInfoResult, GetBatteryInfoSync } from '../interface.uts'\r\nimport IntentFilter from 'android.content.IntentFilter';\r\nimport Intent from 'android.content.Intent';\r\n\r\nimport { GetBatteryInfoFailImpl } from '../unierror';\r\n\r\n/**\r\n * 异步获取电量\r\n */\r\nexport const getBatteryInfo : GetBatteryInfo = function (options : GetBatteryInfoOptions) {\r\n const context = UTSAndroid.getAppContext();\r\n if (context != null) {\r\n const manager = context.getSystemService(\r\n Context.BATTERY_SERVICE\r\n ) as BatteryManager;\r\n const level = manager.getIntProperty(\r\n BatteryManager.BATTERY_PROPERTY_CAPACITY\r\n );\r\n\r\n let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);\r\n let batteryStatus = context.registerReceiver(null, ifilter);\r\n let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);\r\n let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;\r\n\r\n const res : GetBatteryInfoSuccess = {\r\n errMsg: 'getBatteryInfo:ok',\r\n level,\r\n isCharging: isCharging\r\n }\r\n options.success?.(res)\r\n options.complete?.(res)\r\n } else {\r\n let res = new GetBatteryInfoFailImpl(1001);\r\n options.fail?.(res)\r\n options.complete?.(res)\r\n }\r\n}\r\n\r\n/**\r\n * 同步获取电量\r\n */\r\nexport const getBatteryInfoSync : GetBatteryInfoSync = function () : GetBatteryInfoResult {\r\n const context = UTSAndroid.getAppContext();\r\n if (context != null) {\r\n const manager = context.getSystemService(\r\n Context.BATTERY_SERVICE\r\n ) as BatteryManager;\r\n const level = manager.getIntProperty(\r\n BatteryManager.BATTERY_PROPERTY_CAPACITY\r\n );\r\n\r\n let ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);\r\n let batteryStatus = context.registerReceiver(null, ifilter);\r\n let status = batteryStatus?.getIntExtra(BatteryManager.EXTRA_STATUS, -1);\r\n let isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;\r\n\r\n const res : GetBatteryInfoResult = {\r\n level: level,\r\n isCharging: isCharging\r\n };\r\n return res;\r\n }\r\n else {\r\n /**\r\n * 无有效上下文\r\n */\r\n const res : GetBatteryInfoResult = {\r\n level: -1,\r\n isCharging: false\r\n };\r\n return res;\r\n }\r\n}\r\n"]}

View File

@@ -0,0 +1,131 @@
export type GetBatteryInfoSuccess = {
errMsg: string;
/**
* 设备电量范围1 - 100
*/
level: number;
/**
* 是否正在充电中
*/
isCharging: boolean;
};
export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success?: (res: GetBatteryInfoSuccess) => void;
/**
* 接口调用失败的回调函数
*/
fail?: (res: UniError) => void;
/**
* 接口调用成功的回调
*/
complete?: (res: any) => void;
};
export type GetBatteryInfoResult = {
/**
* 设备电量范围1 - 100
*/
level: number;
/**
* 是否正在充电中
*/
isCharging: boolean;
};
/**
* 错误码
* - 1001 getAppContext is null
*/
export type GetBatteryInfoErrorCode = 1001;
/**
* GetBatteryInfo 的错误回调参数
*/
export interface GetBatteryInfoFail extends IUniError {
errCode: GetBatteryInfoErrorCode;
}
;
/**
* 获取电量信息
* @param {GetBatteryInfoOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.11
*
* @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
* @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
*/
export type GetBatteryInfo = (options: GetBatteryInfoOptions) => void;
export type GetBatteryInfoSync = () => GetBatteryInfoResult;
interface Uni {
/**
* 获取电池电量信息
* @description 获取电池电量信息
* @param {GetBatteryInfoOptions} options
* @example
* ```typescript
* uni.getBatteryInfo({
* success(res) {
* __f__('log','at uni_modules/uni-getbatteryinfo/utssdk/interface.uts:78',res);
* }
* })
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.6.11",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
getBatteryInfo(options: GetBatteryInfoOptions): void;
/**
* 同步获取电池电量信息
* @description 获取电池电量信息
* @example
* ```typescript
* uni.getBatteryInfo()
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "3.6.11",
* "unixVer": "4.11"
* }
* },
* "web": {
* "uniVer": "3.6.11",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
getBatteryInfoSync(): GetBatteryInfoResult;
}
//# sourceMappingURL=interface.uts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interface.uts","sourceRoot":"","sources":["uni_modules/uni-getbatteryinfo/utssdk/interface.uts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAG,MAAM,CAAC;IAChB;;MAEE;IACF,KAAK,EAAG,MAAM,CAAC;IACf;;MAEE;IACF,UAAU,EAAG,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC;;UAEG;IACH,OAAQ,CAAC,EAAE,CAAC,GAAG,EAAG,qBAAqB,KAAK,IAAI,CAAA;IAChD;;UAEG;IACH,IAAK,CAAC,EAAE,CAAC,GAAG,EAAG,QAAQ,KAAK,IAAI,CAAA;IAChC;;UAEG;IACH,QAAS,CAAC,EAAE,CAAC,GAAG,EAAG,GAAG,KAAK,IAAI,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAClC;;MAEE;IACF,KAAK,EAAG,MAAM,CAAC;IACf;;MAEE;IACF,UAAU,EAAG,OAAO,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAE;AAC5C;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,OAAO,EAAG,uBAAuB,CAAA;CAClC;AAAA,CAAC;AAEF;;;;;;;;;;;EAWE;AACF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAG,qBAAqB,KAAK,IAAI,CAAA;AAGtE,MAAM,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAA;AAE3D,UAAU,GAAG;IAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,cAAc,CAAE,OAAO,EAAG,qBAAqB,GAAI,IAAI,CAAC;IACxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,kBAAkB,IAAG,oBAAoB,CAAA;CAEzC","sourcesContent":["export type GetBatteryInfoSuccess = {\n\terrMsg : string,\n\t/**\n\t* 设备电量范围1 - 100\n\t*/\n\tlevel : number,\n\t/**\n\t* 是否正在充电中\n\t*/\n\tisCharging : boolean\n}\n\nexport type GetBatteryInfoOptions = {\n\t/**\n\t\t* 接口调用结束的回调函数(调用成功、失败都会执行)\n\t\t*/\n\tsuccess ?: (res : GetBatteryInfoSuccess) => void\n\t/**\n\t\t* 接口调用失败的回调函数\n\t\t*/\n\tfail ?: (res : UniError) => void\n\t/**\n\t\t* 接口调用成功的回调\n\t\t*/\n\tcomplete ?: (res : any) => void\n}\n\nexport type GetBatteryInfoResult = {\n\t/**\n\t* 设备电量范围1 - 100\n\t*/\n\tlevel : number,\n\t/**\n\t* 是否正在充电中\n\t*/\n\tisCharging : boolean\n}\n\n/**\n * 错误码\n * - 1001 getAppContext is null\n */\nexport type GetBatteryInfoErrorCode = 1001 ;\n/**\n * GetBatteryInfo 的错误回调参数\n */\nexport interface GetBatteryInfoFail extends IUniError {\n errCode : GetBatteryInfoErrorCode\n};\n\n/**\n* 获取电量信息\n* @param {GetBatteryInfoOptions} options\n*\n*\n* @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html\n* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22\n* @since 3.6.11\n*\n* @assert () => success({errCode: 0, errSubject: \"uni-getBatteryInfo\", errMsg: \"getBatteryInfo:ok\", level: 60, isCharging: false })\n* @assert () => fail({errCode: 1001, errSubject: \"uni-getBatteryInfo\", errMsg: \"getBatteryInfo:fail getAppContext is null\" })\n*/\nexport type GetBatteryInfo = (options : GetBatteryInfoOptions) => void\n\n\nexport type GetBatteryInfoSync = () => GetBatteryInfoResult\n\ninterface Uni {\n\n\t/**\n\t * 获取电池电量信息\n\t * @description 获取电池电量信息\n\t * @param {GetBatteryInfoOptions} options\n\t * @example\n\t * ```typescript\n\t * uni.getBatteryInfo({\n\t *\t\tsuccess(res) {\n\t *\t\t\t__f__('log','at uni_modules/uni-getbatteryinfo/utssdk/interface.uts:78',res);\n\t *\t\t}\n\t * })\n\t * ```\n\t * @remark\n\t * - 该接口需要同步调用\n\t * @uniPlatform {\n\t * \"app\": {\n\t * \"android\": {\n\t * \"osVer\": \"4.4.4\",\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"3.9.0\"\n\t * },\n\t * \"ios\": {\n\t * \"osVer\": \"12.0\",\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"4.11\"\n\t * }\n\t * },\n\t * \"web\": {\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"4.0\"\n\t * }\n\t * }\n\t * @uniVueVersion 2,3 //支持的vue版本\n\t *\n\t */\n\tgetBatteryInfo (options : GetBatteryInfoOptions) : void,\n\t/**\n\t * 同步获取电池电量信息\n\t * @description 获取电池电量信息\n\t * @example\n\t * ```typescript\n\t * uni.getBatteryInfo()\n\t * ```\n\t * @remark\n\t * - 该接口需要同步调用\n\t * @uniPlatform {\n\t * \"app\": {\n\t * \"android\": {\n\t * \"osVer\": \"4.4.4\",\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"3.9.0\"\n\t * },\n\t * \"ios\": {\n\t * \"osVer\": \"12.0\",\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"4.11\"\n\t * }\n\t * },\n\t * \"web\": {\n\t * \"uniVer\": \"3.6.11\",\n\t * \"unixVer\": \"4.0\"\n\t * }\n\t * }\n\t * @uniVueVersion 2,3 //支持的vue版本\n\t *\n\t */\n\tgetBatteryInfoSync():GetBatteryInfoResult\n\n}\n"]}

View File

@@ -0,0 +1,30 @@
import { GetBatteryInfoErrorCode, GetBatteryInfoFail } from "./interface.uts";
/**
* 错误主题
*/
export const UniErrorSubject = 'uni-getBatteryInfo';
/**
* 错误信息
* @UniError
*/
export const UniErrors: Map<GetBatteryInfoErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[1001, 'getBatteryInfo:fail getAppContext is null'],
]);
/**
* 错误对象实现
*/
export class GetBatteryInfoFailImpl extends UniError implements GetBatteryInfoFail {
/**
* 错误对象构造函数
*/
constructor(errCode: GetBatteryInfoErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = UniErrors[errCode] ?? "";
}
}
//# sourceMappingURL=unierror.uts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"unierror.uts","sourceRoot":"","sources":["uni_modules/uni-getbatteryinfo/utssdk/unierror.uts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAGpD;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,EAAG,GAAG,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC;IACtE;;OAEG;IACH,CAAC,IAAI,EAAE,2CAA2C,CAAC;CACpD,CAAC,CAAC;AAGH;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,QAAS,YAAW,kBAAkB;IAEhF;;OAEG;IACH,YAAY,OAAO,EAAG,uBAAuB;QAC3C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACzC,CAAC;CACF","sourcesContent":["import { GetBatteryInfoErrorCode, GetBatteryInfoFail } from \"./interface.uts\"\r\n/**\r\n * 错误主题\r\n */\r\nexport const UniErrorSubject = 'uni-getBatteryInfo';\r\n\r\n\r\n/**\r\n * 错误信息\r\n * @UniError\r\n */\r\nexport const UniErrors : Map<GetBatteryInfoErrorCode, string> = new Map([\r\n /**\r\n * 错误码及对应的错误信息\r\n */\r\n [1001, 'getBatteryInfo:fail getAppContext is null'],\r\n]);\r\n\r\n\r\n/**\r\n * 错误对象实现\r\n */\r\nexport class GetBatteryInfoFailImpl extends UniError implements GetBatteryInfoFail {\r\n\r\n /**\r\n * 错误对象构造函数\r\n */\r\n constructor(errCode : GetBatteryInfoErrorCode) {\r\n super();\r\n this.errSubject = UniErrorSubject;\r\n this.errCode = errCode;\r\n this.errMsg = UniErrors[errCode] ?? \"\";\r\n }\r\n}"]}