提交 186ead48 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'dev' into alpha

* dev:
  Android uni-usercapturescreen 语法调整
  wifi 适配3.7.7
  fix: uni-usercapturescreen iOS 更新
  usercapturescreen统一interface.uts
  内存警告插件 去掉默认值,避免变量未使用的警告
  内存警告插件 方法参数改回 UTSCallback 类型
  内存警告先还原会 utscallback 写法
  uni-wifi interface更新
  uni-wifi新增interface
  内存监控android 按照 3.7.7语法修改
  优化iOS插件示例
  uni-usercapturescreen 插件iOS调整
  Android uni-usercapturescreen 语法调整
  电量:移除成功信息中的错误码
  电量:移除成功信息中的错误码定义
  电量:重构
  Revert "手动修复内存监控 组件 3.7.6之后编译器新语法"
  手动修复内存监控 组件 3.7.6之后编译器新语法

# Conflicts:
#	pages/index/index.vue
#	uni_modules/uni-usercapturescreen/utssdk/app-android/index.uts
#	uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts
#	uni_modules/uni-usercapturescreen/utssdk/interface.uts
......@@ -44,6 +44,7 @@
uni.connectWifi({
maunal:false,
SSID:"Xiaomi_20D0",
BSSID:"",
password:"BBBB",
complete:(res)=>{
console.log(res);
......@@ -138,27 +139,11 @@
var that = this;
uni.onUserCaptureScreen(function(res) {
console.log(res);
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if(res.errCode == -1){
// 启动失败
that.permissionGranted = true;
return ;
}else if(res.errCode == 0){
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
that.screenImage = res.image
}
}else{
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
}
that.screenImage = res.path
});
if (uni.getSystemInfoSync().platform != "android" || that.permissionGranted) {
......
......@@ -32,7 +32,7 @@
},
"uni_modules": {
"uni-ext-api": {
"uni": "getBatteryInfo"
"uni": ["getBatteryInfo"]
},
"dependencies": [],
"encrypt": [],
......
......@@ -2,14 +2,9 @@ import Context from "android.content.Context";
import BatteryManager from "android.os.BatteryManager";
import { UTSAndroid } from "io.dcloud.uts";
import { GetBatteryInfo, GetBatteryInfoSuccess, GetBatteryInfoFail, GetBatteryInfoOptions } from '../interface.uts'
type GetBatteryInfoOptions = {
success?: (res: UTSJSONObject) => void
fail?: (res: UTSJSONObject) => void
complete?: (res: UTSJSONObject) => void
}
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
export const getBatteryInfo : GetBatteryInfo = function (options) {
const context = UTSAndroid.getAppContext();
if (context != null) {
const manager = context.getSystemService(
......@@ -18,9 +13,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
const level = manager.getIntProperty(
BatteryManager.BATTERY_PROPERTY_CAPACITY
);
const res = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
const res : GetBatteryInfoSuccess = {
errMsg: 'getBatteryInfo:ok',
level,
isCharging: manager.isCharging()
......@@ -28,10 +21,11 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
options.success?.(res)
options.complete?.(res)
} else {
const res = {
const res : GetBatteryInfoFail = {
errSubject: "uni-getBatteryInfo",
errCode: 1001,
errMsg: 'getBatteryInfo:fail getAppContext is null'
errMsg: 'getBatteryInfo:fail getAppContext is null',
cause: null
}
options.fail?.(res)
options.complete?.(res)
......
......@@ -2,27 +2,18 @@
import { UIDevice } from "UIKit";
import { Int } from 'Swift';
/**
* 定义 接口参数
*/
type GetBatteryInfoOptions = {
success?: (res: object) => void;
fail?: (res: object) => void;
complete?: (res: object) => void;
};
import { GetBatteryInfo, GetBatteryInfoSuccess } from '../interface.uts';
/**
* 导出 获取电量方法
*/
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
export const getBatteryInfo : GetBatteryInfo = function (options) {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res = {
errCode: 0,
errSubject: "uni-getBatteryInfo",
const res : GetBatteryInfoSuccess = {
errMsg: "getBatteryInfo:ok",
level: new Int(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
......
type GetBatteryInfoResult = {
/**
* 错误码
* 0:成功
* 1001:getAppContext is null
* 1002:navigator.getBattery is unsupported
*/
errCode : number,
/**
* 调用API的名称
*/
errSubject : string,
/**
* 错误的详细信息
*/
export type GetBatteryInfoSuccess = {
errMsg : string,
/**
* 设备电量,范围1 - 100
......@@ -24,7 +10,7 @@ type GetBatteryInfoResult = {
isCharging : boolean
}
interface UniError<T> {
export type GetBatteryInfoFail = {
/**
* 错误码
*/
......@@ -40,7 +26,7 @@ interface UniError<T> {
/**
* 错误来源
*/
cause : any
cause : any | null
}
......@@ -49,28 +35,27 @@ export type GetBatteryInfoOptions = {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
success ?: (res : GetBatteryInfoResult) => void
success ?: (res : GetBatteryInfoSuccess) => void
/**
* 接口调用失败的回调函数
*/
fail ?: (res : UniError) => void
fail ?: (res : GetBatteryInfoFail) => void
/**
* 接口调用成功的回调
*/
complete ?: (res : object) => void
complete ?: (res : any) => void
}
/**
* 获取电量信息
* @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 default function getBatteryInfo(options : GetBatteryInfoOptions) : void
* 获取电量信息
* @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
\ No newline at end of file
export default function getBatteryInfo(options) {
export function getBatteryInfo(options) {
return my.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
export function getBatteryInfo(options) {
return swan.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
export function getBatteryInfo(options) {
return qq.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
export function getBatteryInfo(options) {
return wx.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
export function getBatteryInfo(options) {
if (navigator.getBattery) {
navigator.getBattery().then(battery => {
const res = {
......
import { UTSAndroid } from "io.dcloud.uts"
let listeners: UTSCallback[] = []
const onAppTrimMemoryListener = (res: number) => {
const onAppTrimMemoryListener = (ret: number) => {
listeners.forEach(listener => {
let res = {
level:ret
}
listener(res)
})
}
@Suppress("DEPRECATION")
export function onMemoryWarning(callback: (res: number) => void) {
export function onMemoryWarning(callback: UTSCallback) {
if (listeners.length == 0) {
// 仅首次执行底层的实际监听
UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener)
......@@ -22,8 +26,9 @@ export function onMemoryWarning(callback: (res: number) => void) {
listeners.push(callback)
}
@Suppress("DEPRECATION")
export function offMemoryWarning(callback: UTSCallback | null = null) {
export function offMemoryWarning(callback: UTSCallback | null) {
if(callback == null){
// 清除全部回调
......@@ -42,3 +47,4 @@ export function offMemoryWarning(callback: UTSCallback | null = null) {
UTSAndroid.offAppTrimMemory(onAppTrimMemoryListener)
}
}
......@@ -8,7 +8,8 @@ import File from "java.io.File";
import Environment from "android.os.Environment";
import System from 'java.lang.System';
import WindowManager from 'android.view.WindowManager';
import { UserCaptureScreenResult, OnUserCaptureScreenResult, SetUserCaptureScreenOptions, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen } from "../interface.uts";
import { OnUserCaptureScreenCallbackResult, UserCaptureScreenCallback, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreenSuccess, SetUserCaptureScreenOptions, SetUserCaptureScreen } from "../interface.uts";
/**
* 文件监听器
......@@ -50,10 +51,7 @@ class ScreenFileObserver extends FileObserver {
lastObserverTime = currentTime;
const screenShotPath = new File(this.screenFile, path).getPath();
const res : OnUserCaptureScreenResult = {
errCode: 0,
errMsg: "onUserCaptureScreen:ok",
errSubject: "uni-onUserCaptureScreen",
const res : OnUserCaptureScreenCallbackResult = {
path: screenShotPath
}
listener?.(res);
......@@ -68,23 +66,15 @@ class ScreenFileObserver extends FileObserver {
export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
// 检查相关权限是否已授予
if (ActivityCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// 无权限,申请权限,并且告知用户监听失败
// 无权限,申请权限
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1001);
// 因权限缺失导致监听失败
const res : OnUserCaptureScreenResult = {
errCode: -1,
errMsg: "onUserCaptureScreen:permission denied",
errSubject: "uni-onUserCaptureScreen"
}
callback?.(res);
return;
}
// 更新监听
listener = callback;
let directory_screenshot : File;
if (Build.MANUFACTURER.toLowerCase() === "xiaomi") {
if (Build.MANUFACTURER.toLowerCase() == "xiaomi") {
// @Suppress("DEPRECATION")
directory_screenshot = new File(new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM), "Screenshots");
} else {
......@@ -113,11 +103,7 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (_ : UserCap
export const setUserCaptureScreen : SetUserCaptureScreen = function (option : SetUserCaptureScreenOptions) {
// 切换到UI线程
UTSAndroid.getUniActivity()?.runOnUiThread(new SetUserCaptureScreenRunnable(option.enable));
const res : UserCaptureScreenResult = {
errCode: 0,
errMsg: "setUserCaptureScreen:ok",
errSubject: "uni-setUserCaptureScreen"
}
const res : SetUserCaptureScreenSuccess = {}
option.success?.(res);
option.complete?.(res);
}
......
......@@ -3,7 +3,7 @@ import { CGRect } from "CoreFoundation";
import { UIApplication, UIView, UITextField, UIScreen, UIDevice } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
import { SetUserCaptureScreenOptions, UserCaptureScreenResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, OnUserCaptureScreenResult } from "../interface.uts"
import { SetUserCaptureScreenOptions, OnUserCaptureScreenCallbackResult, OnUserCaptureScreen, OffUserCaptureScreen, SetUserCaptureScreen, UserCaptureScreenCallback, SetUserCaptureScreenSuccess, SetUserCaptureScreenFail } from "../interface.uts"
/**
* 定义监听截屏事件工具类
......@@ -26,11 +26,7 @@ class CaptureScreenTool {
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
// 回调
const res: OnUserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "onUserCaptureScreen: ok",
path: null
const res: OnUserCaptureScreenCallbackResult = {
}
this.listener?.(res)
}
......@@ -39,13 +35,6 @@ class CaptureScreenTool {
static removeListen(callback : UserCaptureScreenCallback | null) {
this.listener = null
NotificationCenter.default.removeObserver(this)
const res: OnUserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "offUserCaptureScreen: ok",
path: null
}
callback?.(res)
}
static createSecureView() : UIView | null {
......@@ -81,10 +70,7 @@ class CaptureScreenTool {
rootView!.frame = rect
}
}
let res: UserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:ok"
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
......@@ -106,10 +92,7 @@ class CaptureScreenTool {
}
this.secureView = null
}
let res: UserCaptureScreenResult = {
errCode: 0,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:ok"
let res: SetUserCaptureScreenSuccess = {
}
option.success?.(res)
option.complete?.(res)
......@@ -136,7 +119,7 @@ export const offUserCaptureScreen : OffUserCaptureScreen = function (callback :
*/
export const setUserCaptureScreen : SetUserCaptureScreen = function (options : SetUserCaptureScreenOptions) {
if (UIDevice.current.systemVersion < "13.0") {
let res: UserCaptureScreenResult = {
let res: SetUserCaptureScreenFail = {
errCode: 12001,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system not support"
......@@ -145,7 +128,7 @@ export const setUserCaptureScreen : SetUserCaptureScreen = function (options : S
options.complete?.(res);
} else if (UIDevice.current.systemVersion == "15.1") {
let res: UserCaptureScreenResult = {
let res: SetUserCaptureScreenFail = {
errCode: 12010,
errSubject: "uni-usercapturescreen",
errMsg: "setUserCaptureScreen:system internal error"
......
export type UserCaptureScreenResult = {
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
*/
export type OnUserCaptureScreenCallbackResult = {
/**
* 截屏文件路径(仅Android返回)
*/
path ?: string
}
/**
* uni.onUserCaptureScreen/uni.offUserCaptureScreen回调函数定义
*/
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
/**
* uni.onUserCaptureScreen函数定义
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^19
* @since 3.6.8
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.offUserCaptureScreen函数定义
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^19
* @since 3.6.8
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* uni.setUserCaptureScreen成功回调参数
*/
export type SetUserCaptureScreenSuccess = {
}
/**
* uni.setUserCaptureScreen失败回调参数
*/
export type SetUserCaptureScreenFail = {
/**
* 错误码
* 0:成功
......@@ -17,26 +63,24 @@ export type UserCaptureScreenResult = {
errMsg : string,
}
export type OnUserCaptureScreenResult = {
/**
* 错误码
* 0:成功
* -1:permission denied(仅Android返回)
/**
* uni.setUserCaptureScreen成功回调函数定义
*/
errCode : number,
/**
* 调用API的名称
export type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
/**
* uni.setUserCaptureScreen失败回调函数定义
*/
errSubject : string,
/**
* 错误的详细信息
export type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void
/**
* uni.setUserCaptureScreen完成回调函数定义
*/
errMsg : string,
/**
* 截屏文件路径(仅Android返回)
export type SetUserCaptureScreenCompleteCallback = (res : any) => void
/**
* uni.setUserCaptureScreen参数
*/
path : string | null
}
export type SetUserCaptureScreenOptions = {
/**
......@@ -46,45 +90,29 @@ export type SetUserCaptureScreenOptions = {
/**
* 接口调用成功的回调函数
*/
success ?: (res : UserCaptureScreenResult) => void,
// success : SetUserCaptureScreenSuccessCallback | null,
success ?: SetUserCaptureScreenSuccessCallback,
/**
* 接口调用失败的回调函数
*/
fail ?: (res : UserCaptureScreenResult) => void,
// fail : SetUserCaptureScreenFailCallback | null,
fail ?: SetUserCaptureScreenFailCallback,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete ?: (res : UserCaptureScreenResult) => void
// complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null
complete ?: SetUserCaptureScreenCompleteCallback
}
export type UserCaptureScreenCallback = (res : OnUserCaptureScreenResult) => void
/**
* 开启截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* 关闭截屏监听
*
* @param {UserCaptureScreenCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
* * uni.setUserCaptureScreen函数定义
/**
* 设置防截屏
*
* @param {SetUserCaptureScreenOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @platforms APP-IOS = ^13.0,APP-ANDROID = ^19
* @since 3.7.3
*/
export type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
......@@ -94,4 +122,3 @@ interface uni {
offUserCaptureScreen : OffUserCaptureScreen,
setUserCaptureScreen : SetUserCaptureScreen
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册