@tusi-ai/plugins 0.0.1-beta.3 → 0.0.1-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/calendar/index.cjs +41 -6
- package/dist/calendar/index.d.mts +5 -5
- package/dist/calendar/index.d.ts +5 -5
- package/dist/calendar/index.js +42 -7
- package/dist/camera/index.cjs +44 -12
- package/dist/camera/index.d.mts +9 -9
- package/dist/camera/index.d.ts +9 -9
- package/dist/camera/index.js +45 -13
- package/dist/clipboard/index.cjs +43 -8
- package/dist/clipboard/index.d.mts +7 -7
- package/dist/clipboard/index.d.ts +7 -7
- package/dist/clipboard/index.js +44 -9
- package/dist/contact-picker/index.cjs +38 -24
- package/dist/contact-picker/index.d.mts +5 -4
- package/dist/contact-picker/index.d.ts +5 -4
- package/dist/contact-picker/index.js +39 -25
- package/dist/filesystem/index.cjs +76 -36
- package/dist/filesystem/index.d.mts +22 -22
- package/dist/filesystem/index.d.ts +22 -22
- package/dist/filesystem/index.js +77 -37
- package/dist/geolocation/index.cjs +38 -4
- package/dist/geolocation/index.d.mts +5 -5
- package/dist/geolocation/index.d.ts +5 -5
- package/dist/geolocation/index.js +39 -5
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/local-notifications/index.cjs +44 -13
- package/dist/local-notifications/index.d.mts +9 -10
- package/dist/local-notifications/index.d.ts +9 -10
- package/dist/local-notifications/index.js +45 -14
- package/dist/result-CbliqkNp.d.mts +13 -0
- package/dist/result-CbliqkNp.d.ts +13 -0
- package/dist/share/index.cjs +40 -7
- package/dist/share/index.d.mts +7 -6
- package/dist/share/index.d.ts +7 -6
- package/dist/share/index.js +41 -8
- package/package.json +3 -2
package/dist/filesystem/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorCode, TusiError, getRuntimeEnv, RuntimeEnv, bridge } from '@tusi-ai/core';
|
|
2
2
|
|
|
3
3
|
var __async = (__this, __arguments, generator) => {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
@@ -20,6 +20,42 @@ var __async = (__this, __arguments, generator) => {
|
|
|
20
20
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
function callPlugin(task) {
|
|
24
|
+
return Promise.resolve().then(task).then((data) => ({
|
|
25
|
+
code: ErrorCode.Success,
|
|
26
|
+
data: data === void 0 ? null : data,
|
|
27
|
+
errMsg: ""
|
|
28
|
+
})).catch((error) => {
|
|
29
|
+
const code = error instanceof TusiError ? error.code : ErrorCode.NativeFailure;
|
|
30
|
+
return { code, data: null, errMsg: userMessage(code) };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function userMessage(code) {
|
|
34
|
+
switch (code) {
|
|
35
|
+
case ErrorCode.InvalidParams:
|
|
36
|
+
return "\u53C2\u6570\u6709\u8BEF";
|
|
37
|
+
case ErrorCode.NotImplemented:
|
|
38
|
+
return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
|
|
39
|
+
case ErrorCode.PermissionDenied:
|
|
40
|
+
return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
|
|
41
|
+
case ErrorCode.Cancelled:
|
|
42
|
+
return "\u5DF2\u53D6\u6D88";
|
|
43
|
+
case ErrorCode.NotFound:
|
|
44
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
|
|
45
|
+
case ErrorCode.Conflict:
|
|
46
|
+
return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
|
|
47
|
+
case ErrorCode.Timeout:
|
|
48
|
+
return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
49
|
+
case ErrorCode.Unsupported:
|
|
50
|
+
return getRuntimeEnv() === RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
|
|
51
|
+
case ErrorCode.SchemeFailed:
|
|
52
|
+
return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
53
|
+
case ErrorCode.PreviewConnectionFailed:
|
|
54
|
+
return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
55
|
+
default:
|
|
56
|
+
return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
23
59
|
var BaseAdapter = class {
|
|
24
60
|
/**
|
|
25
61
|
* 绑定插件名,后续原生调用会拼成 `pluginName.method`。
|
|
@@ -339,106 +375,110 @@ var Filesystem = {
|
|
|
339
375
|
* 打开系统选择器。
|
|
340
376
|
*
|
|
341
377
|
* @param options - 种类和数量。不传时选择图片或视频,最多 9 个
|
|
342
|
-
* @returns
|
|
343
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
|
|
378
|
+
* @returns `code` 为 0 时 `data.files` 是选中的文件。用户取消时 `files` 为空数组。失败时 `errMsg` 可直接 toast
|
|
344
379
|
*/
|
|
345
380
|
pickMedia(options) {
|
|
346
|
-
return __async(
|
|
381
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
347
382
|
assertMedia(options);
|
|
348
383
|
return getAdapter().pickMedia(options);
|
|
349
|
-
});
|
|
384
|
+
}));
|
|
350
385
|
},
|
|
351
386
|
/**
|
|
352
387
|
* 按文件类型保存。端上写入 `Download/YYB/`,浏览器触发下载。
|
|
353
388
|
*
|
|
354
389
|
* @param options - 类型、来源和内容
|
|
355
|
-
* @returns
|
|
356
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
|
|
390
|
+
* @returns `code` 为 0 时 `data` 是保存结果。可预期的失败在 `data.success` 和 `data.errMsg` 里。调用失败时外层 `errMsg` 可直接 toast
|
|
357
391
|
*/
|
|
358
392
|
saveFile(options) {
|
|
359
|
-
return __async(
|
|
393
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
360
394
|
assertSave(options);
|
|
361
395
|
return getAdapter().saveFile(options);
|
|
362
|
-
});
|
|
396
|
+
}));
|
|
363
397
|
},
|
|
364
398
|
/** 读取应用目录里的文件。浏览器不提供这些目录。 */
|
|
365
399
|
readFile(options) {
|
|
366
|
-
return __async(
|
|
400
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
367
401
|
assertPath("Filesystem.readFile", options);
|
|
368
402
|
return getAdapter().readFile(options);
|
|
369
|
-
});
|
|
403
|
+
}));
|
|
370
404
|
},
|
|
371
405
|
/** 写入应用目录。 */
|
|
372
406
|
writeFile(options) {
|
|
373
|
-
return __async(
|
|
407
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
374
408
|
assertPath("Filesystem.writeFile", options);
|
|
375
409
|
if (options.data === void 0) invalid("Filesystem.writeFile", "data is required");
|
|
376
410
|
return getAdapter().writeFile(options);
|
|
377
|
-
});
|
|
411
|
+
}));
|
|
378
412
|
},
|
|
379
413
|
/** 向已有文件追加内容。 */
|
|
380
414
|
appendFile(options) {
|
|
381
|
-
return __async(
|
|
415
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
382
416
|
assertPath("Filesystem.appendFile", options);
|
|
383
417
|
if (options.data === void 0) invalid("Filesystem.appendFile", "data is required");
|
|
384
|
-
|
|
385
|
-
|
|
418
|
+
yield getAdapter().appendFile(options);
|
|
419
|
+
return null;
|
|
420
|
+
}));
|
|
386
421
|
},
|
|
387
422
|
/** 删除应用目录里的文件。 */
|
|
388
423
|
deleteFile(options) {
|
|
389
|
-
return __async(
|
|
424
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
390
425
|
assertPath("Filesystem.deleteFile", options);
|
|
391
|
-
|
|
392
|
-
|
|
426
|
+
yield getAdapter().deleteFile(options);
|
|
427
|
+
return null;
|
|
428
|
+
}));
|
|
393
429
|
},
|
|
394
430
|
/** 创建目录。 */
|
|
395
431
|
mkdir(options) {
|
|
396
|
-
return __async(
|
|
432
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
397
433
|
assertPath("Filesystem.mkdir", options);
|
|
398
|
-
|
|
399
|
-
|
|
434
|
+
yield getAdapter().mkdir(options);
|
|
435
|
+
return null;
|
|
436
|
+
}));
|
|
400
437
|
},
|
|
401
438
|
/** 删除目录。 */
|
|
402
439
|
rmdir(options) {
|
|
403
|
-
return __async(
|
|
440
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
404
441
|
assertPath("Filesystem.rmdir", options);
|
|
405
|
-
|
|
406
|
-
|
|
442
|
+
yield getAdapter().rmdir(options);
|
|
443
|
+
return null;
|
|
444
|
+
}));
|
|
407
445
|
},
|
|
408
446
|
/** 列出目录。 */
|
|
409
447
|
readdir(options) {
|
|
410
|
-
return __async(
|
|
448
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
411
449
|
assertPath("Filesystem.readdir", options);
|
|
412
450
|
return getAdapter().readdir(options);
|
|
413
|
-
});
|
|
451
|
+
}));
|
|
414
452
|
},
|
|
415
453
|
/** 取当前页面可加载的地址。 */
|
|
416
454
|
getUri(options) {
|
|
417
|
-
return __async(
|
|
455
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
418
456
|
assertPath("Filesystem.getUri", options);
|
|
419
457
|
return getAdapter().getUri(options);
|
|
420
|
-
});
|
|
458
|
+
}));
|
|
421
459
|
},
|
|
422
460
|
/** 读取大小和修改时间。 */
|
|
423
461
|
stat(options) {
|
|
424
|
-
return __async(
|
|
462
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
425
463
|
assertPath("Filesystem.stat", options);
|
|
426
464
|
return getAdapter().stat(options);
|
|
427
|
-
});
|
|
465
|
+
}));
|
|
428
466
|
},
|
|
429
467
|
/** 改名或移动。 */
|
|
430
468
|
rename(options) {
|
|
431
|
-
return __async(
|
|
469
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
432
470
|
assertTransfer("Filesystem.rename", options);
|
|
433
|
-
|
|
434
|
-
|
|
471
|
+
yield getAdapter().rename(options);
|
|
472
|
+
return null;
|
|
473
|
+
}));
|
|
435
474
|
},
|
|
436
475
|
/** 复制。 */
|
|
437
476
|
copy(options) {
|
|
438
|
-
return __async(
|
|
477
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
439
478
|
assertTransfer("Filesystem.copy", options);
|
|
440
|
-
|
|
441
|
-
|
|
479
|
+
yield getAdapter().copy(options);
|
|
480
|
+
return null;
|
|
481
|
+
}));
|
|
442
482
|
}
|
|
443
483
|
};
|
|
444
484
|
|
|
@@ -3,6 +3,42 @@
|
|
|
3
3
|
var core = require('@tusi-ai/core');
|
|
4
4
|
|
|
5
5
|
// src/geolocation/index.ts
|
|
6
|
+
function callPlugin(task) {
|
|
7
|
+
return Promise.resolve().then(task).then((data) => ({
|
|
8
|
+
code: core.ErrorCode.Success,
|
|
9
|
+
data: data === void 0 ? null : data,
|
|
10
|
+
errMsg: ""
|
|
11
|
+
})).catch((error) => {
|
|
12
|
+
const code = error instanceof core.TusiError ? error.code : core.ErrorCode.NativeFailure;
|
|
13
|
+
return { code, data: null, errMsg: userMessage(code) };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function userMessage(code) {
|
|
17
|
+
switch (code) {
|
|
18
|
+
case core.ErrorCode.InvalidParams:
|
|
19
|
+
return "\u53C2\u6570\u6709\u8BEF";
|
|
20
|
+
case core.ErrorCode.NotImplemented:
|
|
21
|
+
return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
|
|
22
|
+
case core.ErrorCode.PermissionDenied:
|
|
23
|
+
return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
|
|
24
|
+
case core.ErrorCode.Cancelled:
|
|
25
|
+
return "\u5DF2\u53D6\u6D88";
|
|
26
|
+
case core.ErrorCode.NotFound:
|
|
27
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
|
|
28
|
+
case core.ErrorCode.Conflict:
|
|
29
|
+
return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
|
|
30
|
+
case core.ErrorCode.Timeout:
|
|
31
|
+
return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
32
|
+
case core.ErrorCode.Unsupported:
|
|
33
|
+
return core.getRuntimeEnv() === core.RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
|
|
34
|
+
case core.ErrorCode.SchemeFailed:
|
|
35
|
+
return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
36
|
+
case core.ErrorCode.PreviewConnectionFailed:
|
|
37
|
+
return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
38
|
+
default:
|
|
39
|
+
return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
6
42
|
var BaseAdapter = class {
|
|
7
43
|
/**
|
|
8
44
|
* 绑定插件名,后续原生调用会拼成 `pluginName.method`。
|
|
@@ -102,12 +138,10 @@ var Geolocation = {
|
|
|
102
138
|
* 读取当前坐标。
|
|
103
139
|
*
|
|
104
140
|
* @param options - 精度、超时和缓存年龄
|
|
105
|
-
* @returns
|
|
106
|
-
* @throws {@link TusiError}
|
|
107
|
-
* {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
|
|
141
|
+
* @returns `code` 为 0 时 `data` 是当前位置。`provider` 为 `gps`、`network` 或 `passive`。失败时 `errMsg` 可直接 toast
|
|
108
142
|
*/
|
|
109
143
|
getCurrentPos(options) {
|
|
110
|
-
return getAdapter().getCurrentPos(options);
|
|
144
|
+
return callPlugin(() => getAdapter().getCurrentPos(options));
|
|
111
145
|
}
|
|
112
146
|
};
|
|
113
147
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { P as PluginResult } from '../result-CbliqkNp.mjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* {@link Geolocation.getCurrentPos} 的入参。权限在该方法内部申请。
|
|
3
5
|
*/
|
|
@@ -39,11 +41,9 @@ declare const Geolocation: {
|
|
|
39
41
|
* 读取当前坐标。
|
|
40
42
|
*
|
|
41
43
|
* @param options - 精度、超时和缓存年龄
|
|
42
|
-
* @returns
|
|
43
|
-
* @throws {@link TusiError}
|
|
44
|
-
* {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
|
|
44
|
+
* @returns `code` 为 0 时 `data` 是当前位置。`provider` 为 `gps`、`network` 或 `passive`。失败时 `errMsg` 可直接 toast
|
|
45
45
|
*/
|
|
46
|
-
getCurrentPos(options?: GetCurrentPosOptions): Promise<Position
|
|
46
|
+
getCurrentPos(options?: GetCurrentPosOptions): Promise<PluginResult<Position>>;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export { Geolocation, type GetCurrentPosOptions, type Position };
|
|
49
|
+
export { Geolocation, type GetCurrentPosOptions, PluginResult, type Position };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { P as PluginResult } from '../result-CbliqkNp.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* {@link Geolocation.getCurrentPos} 的入参。权限在该方法内部申请。
|
|
3
5
|
*/
|
|
@@ -39,11 +41,9 @@ declare const Geolocation: {
|
|
|
39
41
|
* 读取当前坐标。
|
|
40
42
|
*
|
|
41
43
|
* @param options - 精度、超时和缓存年龄
|
|
42
|
-
* @returns
|
|
43
|
-
* @throws {@link TusiError}
|
|
44
|
-
* {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
|
|
44
|
+
* @returns `code` 为 0 时 `data` 是当前位置。`provider` 为 `gps`、`network` 或 `passive`。失败时 `errMsg` 可直接 toast
|
|
45
45
|
*/
|
|
46
|
-
getCurrentPos(options?: GetCurrentPosOptions): Promise<Position
|
|
46
|
+
getCurrentPos(options?: GetCurrentPosOptions): Promise<PluginResult<Position>>;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export { Geolocation, type GetCurrentPosOptions, type Position };
|
|
49
|
+
export { Geolocation, type GetCurrentPosOptions, PluginResult, type Position };
|
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorCode, TusiError, getRuntimeEnv, RuntimeEnv, bridge } from '@tusi-ai/core';
|
|
2
2
|
|
|
3
3
|
// src/geolocation/index.ts
|
|
4
|
+
function callPlugin(task) {
|
|
5
|
+
return Promise.resolve().then(task).then((data) => ({
|
|
6
|
+
code: ErrorCode.Success,
|
|
7
|
+
data: data === void 0 ? null : data,
|
|
8
|
+
errMsg: ""
|
|
9
|
+
})).catch((error) => {
|
|
10
|
+
const code = error instanceof TusiError ? error.code : ErrorCode.NativeFailure;
|
|
11
|
+
return { code, data: null, errMsg: userMessage(code) };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function userMessage(code) {
|
|
15
|
+
switch (code) {
|
|
16
|
+
case ErrorCode.InvalidParams:
|
|
17
|
+
return "\u53C2\u6570\u6709\u8BEF";
|
|
18
|
+
case ErrorCode.NotImplemented:
|
|
19
|
+
return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
|
|
20
|
+
case ErrorCode.PermissionDenied:
|
|
21
|
+
return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
|
|
22
|
+
case ErrorCode.Cancelled:
|
|
23
|
+
return "\u5DF2\u53D6\u6D88";
|
|
24
|
+
case ErrorCode.NotFound:
|
|
25
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
|
|
26
|
+
case ErrorCode.Conflict:
|
|
27
|
+
return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
|
|
28
|
+
case ErrorCode.Timeout:
|
|
29
|
+
return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
30
|
+
case ErrorCode.Unsupported:
|
|
31
|
+
return getRuntimeEnv() === RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
|
|
32
|
+
case ErrorCode.SchemeFailed:
|
|
33
|
+
return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
34
|
+
case ErrorCode.PreviewConnectionFailed:
|
|
35
|
+
return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
36
|
+
default:
|
|
37
|
+
return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
4
40
|
var BaseAdapter = class {
|
|
5
41
|
/**
|
|
6
42
|
* 绑定插件名,后续原生调用会拼成 `pluginName.method`。
|
|
@@ -100,12 +136,10 @@ var Geolocation = {
|
|
|
100
136
|
* 读取当前坐标。
|
|
101
137
|
*
|
|
102
138
|
* @param options - 精度、超时和缓存年龄
|
|
103
|
-
* @returns
|
|
104
|
-
* @throws {@link TusiError}
|
|
105
|
-
* {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
|
|
139
|
+
* @returns `code` 为 0 时 `data` 是当前位置。`provider` 为 `gps`、`network` 或 `passive`。失败时 `errMsg` 可直接 toast
|
|
106
140
|
*/
|
|
107
141
|
getCurrentPos(options) {
|
|
108
|
-
return getAdapter().getCurrentPos(options);
|
|
142
|
+
return callPlugin(() => getAdapter().getCurrentPos(options));
|
|
109
143
|
}
|
|
110
144
|
};
|
|
111
145
|
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,42 @@ var __async = (__this, __arguments, generator) => {
|
|
|
22
22
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
|
+
function callPlugin(task) {
|
|
26
|
+
return Promise.resolve().then(task).then((data) => ({
|
|
27
|
+
code: core.ErrorCode.Success,
|
|
28
|
+
data: data === void 0 ? null : data,
|
|
29
|
+
errMsg: ""
|
|
30
|
+
})).catch((error) => {
|
|
31
|
+
const code = error instanceof core.TusiError ? error.code : core.ErrorCode.NativeFailure;
|
|
32
|
+
return { code, data: null, errMsg: userMessage(code) };
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function userMessage(code) {
|
|
36
|
+
switch (code) {
|
|
37
|
+
case core.ErrorCode.InvalidParams:
|
|
38
|
+
return "\u53C2\u6570\u6709\u8BEF";
|
|
39
|
+
case core.ErrorCode.NotImplemented:
|
|
40
|
+
return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
|
|
41
|
+
case core.ErrorCode.PermissionDenied:
|
|
42
|
+
return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
|
|
43
|
+
case core.ErrorCode.Cancelled:
|
|
44
|
+
return "\u5DF2\u53D6\u6D88";
|
|
45
|
+
case core.ErrorCode.NotFound:
|
|
46
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
|
|
47
|
+
case core.ErrorCode.Conflict:
|
|
48
|
+
return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
|
|
49
|
+
case core.ErrorCode.Timeout:
|
|
50
|
+
return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
51
|
+
case core.ErrorCode.Unsupported:
|
|
52
|
+
return core.getRuntimeEnv() === core.RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
|
|
53
|
+
case core.ErrorCode.SchemeFailed:
|
|
54
|
+
return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
55
|
+
case core.ErrorCode.PreviewConnectionFailed:
|
|
56
|
+
return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
57
|
+
default:
|
|
58
|
+
return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
25
61
|
var BaseAdapter = class {
|
|
26
62
|
/**
|
|
27
63
|
* 绑定插件名,后续原生调用会拼成 `pluginName.method`。
|
|
@@ -112,40 +148,35 @@ var LocalNotifications = {
|
|
|
112
148
|
* 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
|
|
113
149
|
*
|
|
114
150
|
* @param request - 标题、时间和重复规则
|
|
115
|
-
* @returns
|
|
116
|
-
* @throws {@link TusiError}
|
|
117
|
-
* {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
|
|
151
|
+
* @returns `code` 为 0 时 `data` 是调度结果。失败时 `errMsg` 可直接 toast
|
|
118
152
|
*/
|
|
119
153
|
schedule(request) {
|
|
120
|
-
return __async(
|
|
154
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
121
155
|
assertRequest(request);
|
|
122
156
|
return getAdapter().schedule(request);
|
|
123
|
-
});
|
|
157
|
+
}));
|
|
124
158
|
},
|
|
125
159
|
/**
|
|
126
160
|
* 撤销尚未触发的提醒。
|
|
127
161
|
*
|
|
128
162
|
* @param reminderIds - 要撤销的 ID,直接传数组
|
|
129
|
-
* @returns
|
|
130
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
|
|
163
|
+
* @returns `code` 为 0 时 `data` 是撤销结果。失败时 `errMsg` 可直接 toast
|
|
131
164
|
*/
|
|
132
165
|
cancel(reminderIds) {
|
|
133
|
-
return __async(
|
|
166
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
134
167
|
if (!Array.isArray(reminderIds) || reminderIds.some((id) => typeof id !== "string" || !id)) {
|
|
135
168
|
invalid("LocalNotifications.cancel", "reminderIds must be a string array");
|
|
136
169
|
}
|
|
137
170
|
return getAdapter().cancel(reminderIds);
|
|
138
|
-
});
|
|
171
|
+
}));
|
|
139
172
|
},
|
|
140
173
|
/**
|
|
141
174
|
* 列出尚未触发的提醒。
|
|
142
175
|
*
|
|
143
|
-
* @returns
|
|
176
|
+
* @returns `code` 为 0 时 `data` 是待触发列表
|
|
144
177
|
*/
|
|
145
178
|
getPending() {
|
|
146
|
-
return
|
|
147
|
-
return getAdapter().getPending();
|
|
148
|
-
});
|
|
179
|
+
return callPlugin(() => getAdapter().getPending());
|
|
149
180
|
}
|
|
150
181
|
};
|
|
151
182
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { P as PluginResult } from '../result-CbliqkNp.mjs';
|
|
2
|
+
|
|
1
3
|
/** 重复规则。不传时只触发一次。 */
|
|
2
4
|
interface NotificationRepeat {
|
|
3
5
|
/** 一次、每天或每周。 */
|
|
@@ -60,25 +62,22 @@ declare const LocalNotifications: {
|
|
|
60
62
|
* 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
|
|
61
63
|
*
|
|
62
64
|
* @param request - 标题、时间和重复规则
|
|
63
|
-
* @returns
|
|
64
|
-
* @throws {@link TusiError}
|
|
65
|
-
* {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
|
|
65
|
+
* @returns `code` 为 0 时 `data` 是调度结果。失败时 `errMsg` 可直接 toast
|
|
66
66
|
*/
|
|
67
|
-
schedule(request: LocalNotificationRequest): Promise<ScheduleResult
|
|
67
|
+
schedule(request: LocalNotificationRequest): Promise<PluginResult<ScheduleResult>>;
|
|
68
68
|
/**
|
|
69
69
|
* 撤销尚未触发的提醒。
|
|
70
70
|
*
|
|
71
71
|
* @param reminderIds - 要撤销的 ID,直接传数组
|
|
72
|
-
* @returns
|
|
73
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
|
|
72
|
+
* @returns `code` 为 0 时 `data` 是撤销结果。失败时 `errMsg` 可直接 toast
|
|
74
73
|
*/
|
|
75
|
-
cancel(reminderIds: string[]): Promise<CancelResult
|
|
74
|
+
cancel(reminderIds: string[]): Promise<PluginResult<CancelResult>>;
|
|
76
75
|
/**
|
|
77
76
|
* 列出尚未触发的提醒。
|
|
78
77
|
*
|
|
79
|
-
* @returns
|
|
78
|
+
* @returns `code` 为 0 时 `data` 是待触发列表
|
|
80
79
|
*/
|
|
81
|
-
getPending(): Promise<PendingNotification[]
|
|
80
|
+
getPending(): Promise<PluginResult<PendingNotification[]>>;
|
|
82
81
|
};
|
|
83
82
|
|
|
84
|
-
export { type CancelResult, type LocalNotificationRequest, LocalNotifications, type NotificationRepeat, type PendingNotification, type ScheduleResult };
|
|
83
|
+
export { type CancelResult, type LocalNotificationRequest, LocalNotifications, type NotificationRepeat, type PendingNotification, PluginResult, type ScheduleResult };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { P as PluginResult } from '../result-CbliqkNp.js';
|
|
2
|
+
|
|
1
3
|
/** 重复规则。不传时只触发一次。 */
|
|
2
4
|
interface NotificationRepeat {
|
|
3
5
|
/** 一次、每天或每周。 */
|
|
@@ -60,25 +62,22 @@ declare const LocalNotifications: {
|
|
|
60
62
|
* 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
|
|
61
63
|
*
|
|
62
64
|
* @param request - 标题、时间和重复规则
|
|
63
|
-
* @returns
|
|
64
|
-
* @throws {@link TusiError}
|
|
65
|
-
* {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
|
|
65
|
+
* @returns `code` 为 0 时 `data` 是调度结果。失败时 `errMsg` 可直接 toast
|
|
66
66
|
*/
|
|
67
|
-
schedule(request: LocalNotificationRequest): Promise<ScheduleResult
|
|
67
|
+
schedule(request: LocalNotificationRequest): Promise<PluginResult<ScheduleResult>>;
|
|
68
68
|
/**
|
|
69
69
|
* 撤销尚未触发的提醒。
|
|
70
70
|
*
|
|
71
71
|
* @param reminderIds - 要撤销的 ID,直接传数组
|
|
72
|
-
* @returns
|
|
73
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
|
|
72
|
+
* @returns `code` 为 0 时 `data` 是撤销结果。失败时 `errMsg` 可直接 toast
|
|
74
73
|
*/
|
|
75
|
-
cancel(reminderIds: string[]): Promise<CancelResult
|
|
74
|
+
cancel(reminderIds: string[]): Promise<PluginResult<CancelResult>>;
|
|
76
75
|
/**
|
|
77
76
|
* 列出尚未触发的提醒。
|
|
78
77
|
*
|
|
79
|
-
* @returns
|
|
78
|
+
* @returns `code` 为 0 时 `data` 是待触发列表
|
|
80
79
|
*/
|
|
81
|
-
getPending(): Promise<PendingNotification[]
|
|
80
|
+
getPending(): Promise<PluginResult<PendingNotification[]>>;
|
|
82
81
|
};
|
|
83
82
|
|
|
84
|
-
export { type CancelResult, type LocalNotificationRequest, LocalNotifications, type NotificationRepeat, type PendingNotification, type ScheduleResult };
|
|
83
|
+
export { type CancelResult, type LocalNotificationRequest, LocalNotifications, type NotificationRepeat, type PendingNotification, PluginResult, type ScheduleResult };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorCode, TusiError, getRuntimeEnv, RuntimeEnv, bridge } from '@tusi-ai/core';
|
|
2
2
|
|
|
3
3
|
var __async = (__this, __arguments, generator) => {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
@@ -20,6 +20,42 @@ var __async = (__this, __arguments, generator) => {
|
|
|
20
20
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
function callPlugin(task) {
|
|
24
|
+
return Promise.resolve().then(task).then((data) => ({
|
|
25
|
+
code: ErrorCode.Success,
|
|
26
|
+
data: data === void 0 ? null : data,
|
|
27
|
+
errMsg: ""
|
|
28
|
+
})).catch((error) => {
|
|
29
|
+
const code = error instanceof TusiError ? error.code : ErrorCode.NativeFailure;
|
|
30
|
+
return { code, data: null, errMsg: userMessage(code) };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function userMessage(code) {
|
|
34
|
+
switch (code) {
|
|
35
|
+
case ErrorCode.InvalidParams:
|
|
36
|
+
return "\u53C2\u6570\u6709\u8BEF";
|
|
37
|
+
case ErrorCode.NotImplemented:
|
|
38
|
+
return "\u8BF7\u5347\u7EA7\u5230\u6700\u65B0\u5410\u53F8\u7248\u672C";
|
|
39
|
+
case ErrorCode.PermissionDenied:
|
|
40
|
+
return "\u8BF7\u5148\u5F00\u542F\u6743\u9650";
|
|
41
|
+
case ErrorCode.Cancelled:
|
|
42
|
+
return "\u5DF2\u53D6\u6D88";
|
|
43
|
+
case ErrorCode.NotFound:
|
|
44
|
+
return "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u5185\u5BB9";
|
|
45
|
+
case ErrorCode.Conflict:
|
|
46
|
+
return "\u5F53\u524D\u72B6\u6001\u65E0\u6CD5\u5B8C\u6210\u64CD\u4F5C";
|
|
47
|
+
case ErrorCode.Timeout:
|
|
48
|
+
return "\u64CD\u4F5C\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
49
|
+
case ErrorCode.Unsupported:
|
|
50
|
+
return getRuntimeEnv() === RuntimeEnv.Browser ? "\u8BF7\u5230\u5410\u53F8 APP \u4F53\u9A8C" : "\u5F53\u524D\u73AF\u5883\u6682\u4E0D\u652F\u6301";
|
|
51
|
+
case ErrorCode.SchemeFailed:
|
|
52
|
+
return "\u8C03\u7528\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
53
|
+
case ErrorCode.PreviewConnectionFailed:
|
|
54
|
+
return "\u9884\u89C8\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
55
|
+
default:
|
|
56
|
+
return "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
23
59
|
var BaseAdapter = class {
|
|
24
60
|
/**
|
|
25
61
|
* 绑定插件名,后续原生调用会拼成 `pluginName.method`。
|
|
@@ -110,40 +146,35 @@ var LocalNotifications = {
|
|
|
110
146
|
* 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
|
|
111
147
|
*
|
|
112
148
|
* @param request - 标题、时间和重复规则
|
|
113
|
-
* @returns
|
|
114
|
-
* @throws {@link TusiError}
|
|
115
|
-
* {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
|
|
149
|
+
* @returns `code` 为 0 时 `data` 是调度结果。失败时 `errMsg` 可直接 toast
|
|
116
150
|
*/
|
|
117
151
|
schedule(request) {
|
|
118
|
-
return __async(
|
|
152
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
119
153
|
assertRequest(request);
|
|
120
154
|
return getAdapter().schedule(request);
|
|
121
|
-
});
|
|
155
|
+
}));
|
|
122
156
|
},
|
|
123
157
|
/**
|
|
124
158
|
* 撤销尚未触发的提醒。
|
|
125
159
|
*
|
|
126
160
|
* @param reminderIds - 要撤销的 ID,直接传数组
|
|
127
|
-
* @returns
|
|
128
|
-
* @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
|
|
161
|
+
* @returns `code` 为 0 时 `data` 是撤销结果。失败时 `errMsg` 可直接 toast
|
|
129
162
|
*/
|
|
130
163
|
cancel(reminderIds) {
|
|
131
|
-
return __async(
|
|
164
|
+
return callPlugin(() => __async(null, null, function* () {
|
|
132
165
|
if (!Array.isArray(reminderIds) || reminderIds.some((id) => typeof id !== "string" || !id)) {
|
|
133
166
|
invalid("LocalNotifications.cancel", "reminderIds must be a string array");
|
|
134
167
|
}
|
|
135
168
|
return getAdapter().cancel(reminderIds);
|
|
136
|
-
});
|
|
169
|
+
}));
|
|
137
170
|
},
|
|
138
171
|
/**
|
|
139
172
|
* 列出尚未触发的提醒。
|
|
140
173
|
*
|
|
141
|
-
* @returns
|
|
174
|
+
* @returns `code` 为 0 时 `data` 是待触发列表
|
|
142
175
|
*/
|
|
143
176
|
getPending() {
|
|
144
|
-
return
|
|
145
|
-
return getAdapter().getPending();
|
|
146
|
-
});
|
|
177
|
+
return callPlugin(() => getAdapter().getPending());
|
|
147
178
|
}
|
|
148
179
|
};
|
|
149
180
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件对外的统一结果。失败不抛错,`errMsg` 可以直接 toast。
|
|
3
|
+
*/
|
|
4
|
+
interface PluginResult<T> {
|
|
5
|
+
/** `0` 成功,其余为 {@link ErrorCode}。 */
|
|
6
|
+
code: number;
|
|
7
|
+
/** 成功时的业务数据。失败或没有数据时为 `null`。 */
|
|
8
|
+
data: T | null;
|
|
9
|
+
/** 给用户看的说明。成功时为空字符串。 */
|
|
10
|
+
errMsg: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type { PluginResult as P };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件对外的统一结果。失败不抛错,`errMsg` 可以直接 toast。
|
|
3
|
+
*/
|
|
4
|
+
interface PluginResult<T> {
|
|
5
|
+
/** `0` 成功,其余为 {@link ErrorCode}。 */
|
|
6
|
+
code: number;
|
|
7
|
+
/** 成功时的业务数据。失败或没有数据时为 `null`。 */
|
|
8
|
+
data: T | null;
|
|
9
|
+
/** 给用户看的说明。成功时为空字符串。 */
|
|
10
|
+
errMsg: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type { PluginResult as P };
|