From fc1a78cb7ba6806b0766b94fa663bc0f6dd97355 Mon Sep 17 00:00:00 2001 From: m0_75226990 Date: Tue, 14 Mar 2023 17:46:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20uni-usercapturescreen=20/=20uni-syntaxca?= =?UTF-8?q?se=20=E9=83=A8=E5=88=86uts=E8=AF=AD=E6=B3=95=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/app-ios/index.uts | 49 ++++++++++++------- .../utssdk/interface.uts | 21 ++++++++ uni_modules/uts-syntaxcase/index.uts | 41 +++++++++++----- .../uts-syntaxcase/utssdk/app-ios/index.uts | 48 +++++++++++++----- 4 files changed, 118 insertions(+), 41 deletions(-) create mode 100644 uni_modules/uni-usercapturescreen/utssdk/interface.uts diff --git a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts index 1151d9e..68e7ad4 100644 --- a/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts +++ b/uni_modules/uni-usercapturescreen/utssdk/app-ios/index.uts @@ -1,14 +1,16 @@ import { NotificationCenter} from 'Foundation'; import { UIApplication } from "UIKit" +import { OnUserCaptureScreen, OffUserCaptureScreen, UserCaptureScreenCallback } from "../interface.uts" + /** * 定义监听截屏事件工具类 */ class CaptureScreenTool { - static listener?: UTSCallback; + static listener: UserCaptureScreenCallback | null; // 监听截屏 - static listenCaptureScreen(callback?: UTSCallback) { + static listenCaptureScreen(callback: UserCaptureScreenCallback | null) { this.listener = callback // 注册监听截屏事件及回调方法 @@ -20,30 +22,41 @@ class CaptureScreenTool { // 捕获截屏回调的方法 // target-action 的方法前需要添加 @objc 前缀 @objc static userDidTakeScreenshot() { - const obj = new UTSJSONObject() // 回调 - this.listener?.(obj) + this.listener?.({}) } // 移除监听事件 - static removeListen(callback?: UTSCallback) { + static removeListen(callback: UserCaptureScreenCallback | null) { this.listener = null NotificationCenter.default.removeObserver(this) - const obj = new UTSJSONObject() - callback?.(obj) } } -/** - * 开启截图监听 - */ -export function onUserCaptureScreen(callback?: UTSCallback) { - CaptureScreenTool.listenCaptureScreen(callback) -} +// /** +// * 开启截图监听 +// */ +// export function onUserCaptureScreen(callback?: UTSCallback) { +// CaptureScreenTool.listenCaptureScreen(callback) +// } -/** - * 关闭截屏监听 - */ -export function offUserCaptureScreen(callback?: UTSCallback) { - CaptureScreenTool.removeListen(callback) +// /** +// * 关闭截屏监听 +// */ +// export function offUserCaptureScreen(callback?: UTSCallback) { +// CaptureScreenTool.removeListen(callback) +// } + +/** + * 开启截图监听 + */ +export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.listenCaptureScreen(callback) +} + +/** + * 关闭截屏监听 + */ +export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) { + CaptureScreenTool.removeListen(callback) } diff --git a/uni_modules/uni-usercapturescreen/utssdk/interface.uts b/uni_modules/uni-usercapturescreen/utssdk/interface.uts new file mode 100644 index 0000000..6ed4533 --- /dev/null +++ b/uni_modules/uni-usercapturescreen/utssdk/interface.uts @@ -0,0 +1,21 @@ +export type UserCaptureScreenCallback = (res: any) => void + +/** + * 开启截屏监听 + * + * @param {UTSCallback} 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 {UTSCallback} 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 \ No newline at end of file diff --git a/uni_modules/uts-syntaxcase/index.uts b/uni_modules/uts-syntaxcase/index.uts index 7d49486..1a86e82 100644 --- a/uni_modules/uts-syntaxcase/index.uts +++ b/uni_modules/uts-syntaxcase/index.uts @@ -4,6 +4,16 @@ type AsyncOptions = { fail: (res: string) => void; complete: (res: string) => void; }; + +type SyntaxResult = { + name: string +}; + +type SyncResult = { + msg: string +} + + /** * 导出一个属性 */ @@ -13,11 +23,12 @@ export const MAX = 100; * 导出一个同步方法 * @returns */ -export function testSync(msg: string) { +export function testSync(msg: string): SyncResult { console.log("log test"); - return { - msg: `hello ${msg}`, - }; + const res: SyncResult = { + msg: `hello ${msg}` + } + return res } /** * 导出一个同步方法(触发了数组越界异常) @@ -37,20 +48,28 @@ export function testSyncWithCallback(opts: AsyncOptions) { opts.fail("fail"); } opts.complete("complete"); - return { name: "testSyncWithCallback" }; + + const res: SyntaxResult = { + name: "testSyncWithCallback" + } + return res } /** * 导出一个异步方法 * @returns */ -export async function testAsync(opts: AsyncOptions) { +export async function testAsync(opts: AsyncOptions): Promise { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testAsync" }; + + const res: SyntaxResult = { + name: "testAsync" + } + return res } type TestOptions = { @@ -67,17 +86,17 @@ export class Test { this.name = options.name; options.callback("Test.constructor"); } - static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - static async testClassStaticAsync(opts: AsyncOptions): Promise { + static async testClassStaticAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } - testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - async testClassAsync(opts: AsyncOptions): Promise { + async testClassAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } diff --git a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts index dfdc29f..ae77730 100644 --- a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts @@ -5,6 +5,15 @@ type AsyncOptions = { fail: (res: string) => void; complete: (res: string) => void; }; + +type SyntaxResult = { + name: string +}; + +type SyncResult = { + msg: string +} + /** * 导出一个属性 */ @@ -14,12 +23,17 @@ export const MAX = 100; * 导出一个同步方法 * @returns */ -export function testSync(msg: string) { +export function testSync(msg: string): SyncResult { console.log("log test"); log("log test1"); - return { - msg: `hello ${msg}`, - }; + + const res: SyncResult = { + msg: `hello ${msg}` + } + return res + // return { + // msg: `hello ${msg}`, + // }; } /** * 导出一个同步方法(触发了数组越界异常) @@ -32,27 +46,37 @@ export function testSyncError() { * 导出一个带callback的同步方法 * @param opts */ -export function testSyncWithCallback(opts: AsyncOptions) { +export function testSyncWithCallback(opts: AsyncOptions): SyntaxResult { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testSyncWithCallback" }; + + const res: SyntaxResult = { + name: "testSyncWithCallback" + } + return res; + // return { name: "testSyncWithCallback" }; } /** * 导出一个异步方法 * @returns */ -export async function testAsync(opts: AsyncOptions) { +export async function testAsync(opts: AsyncOptions): Promise { if (opts.type == "success") { opts.success("success"); } else { opts.fail("fail"); } opts.complete("complete"); - return { name: "testAsync" }; + + const res: SyntaxResult = { + name: "testAsync" + } + return res; + // return { name: "testAsync" }; } type TestOptions = { @@ -69,17 +93,17 @@ export class Test { this.name = options.name; options.callback("Test.constructor"); } - static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - static async testClassStaticAsync(opts: AsyncOptions): Promise { + static async testClassStaticAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } - testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { return testSyncWithCallback(opts); } - async testClassAsync(opts: AsyncOptions): Promise { + async testClassAsync(opts: AsyncOptions): Promise { const res = await testAsync(opts); return res; } -- GitLab