@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.
Files changed (38) hide show
  1. package/README.md +6 -2
  2. package/dist/calendar/index.cjs +41 -6
  3. package/dist/calendar/index.d.mts +5 -5
  4. package/dist/calendar/index.d.ts +5 -5
  5. package/dist/calendar/index.js +42 -7
  6. package/dist/camera/index.cjs +44 -12
  7. package/dist/camera/index.d.mts +9 -9
  8. package/dist/camera/index.d.ts +9 -9
  9. package/dist/camera/index.js +45 -13
  10. package/dist/clipboard/index.cjs +43 -8
  11. package/dist/clipboard/index.d.mts +7 -7
  12. package/dist/clipboard/index.d.ts +7 -7
  13. package/dist/clipboard/index.js +44 -9
  14. package/dist/contact-picker/index.cjs +38 -24
  15. package/dist/contact-picker/index.d.mts +5 -4
  16. package/dist/contact-picker/index.d.ts +5 -4
  17. package/dist/contact-picker/index.js +39 -25
  18. package/dist/filesystem/index.cjs +76 -36
  19. package/dist/filesystem/index.d.mts +22 -22
  20. package/dist/filesystem/index.d.ts +22 -22
  21. package/dist/filesystem/index.js +77 -37
  22. package/dist/geolocation/index.cjs +38 -4
  23. package/dist/geolocation/index.d.mts +5 -5
  24. package/dist/geolocation/index.d.ts +5 -5
  25. package/dist/geolocation/index.js +39 -5
  26. package/dist/index.d.mts +2 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/local-notifications/index.cjs +44 -13
  29. package/dist/local-notifications/index.d.mts +9 -10
  30. package/dist/local-notifications/index.d.ts +9 -10
  31. package/dist/local-notifications/index.js +45 -14
  32. package/dist/result-CbliqkNp.d.mts +13 -0
  33. package/dist/result-CbliqkNp.d.ts +13 -0
  34. package/dist/share/index.cjs +40 -7
  35. package/dist/share/index.d.mts +7 -6
  36. package/dist/share/index.d.ts +7 -6
  37. package/dist/share/index.js +41 -8
  38. package/package.json +3 -2
@@ -1,4 +1,4 @@
1
- import { getRuntimeEnv, RuntimeEnv, TusiError, ErrorCode, bridge } from '@tusi-ai/core';
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`。
@@ -115,22 +151,21 @@ var Clipboard = {
115
151
  * 写入剪贴板。
116
152
  *
117
153
  * @param options - `image`、`url`、`string` 三选一,优先级依次降低
118
- * @throws {@link TusiError}
119
- * {@link ErrorCode.InvalidParams} 没有可写内容,{@link ErrorCode.Unsupported} 当前环境没有剪贴板 API
154
+ * @returns 成功时 `data` 为 `null`。失败时 `errMsg` 可直接 toast
120
155
  */
121
156
  write(options) {
122
- return __async(this, null, function* () {
123
- return getAdapter().write(options);
124
- });
157
+ return callPlugin(() => __async(null, null, function* () {
158
+ yield getAdapter().write(options);
159
+ return null;
160
+ }));
125
161
  },
126
162
  /**
127
163
  * 读取剪贴板。
128
164
  *
129
- * @returns 内容和类型
130
- * @throws {@link TusiError} {@link ErrorCode.NotFound} 剪贴板为空或没有读取权限
165
+ * @returns `code` 为 0 时 `data` 是内容和类型。失败时 `errMsg` 可直接 toast
131
166
  */
132
167
  read() {
133
- return getAdapter().read();
168
+ return callPlugin(() => getAdapter().read());
134
169
  }
135
170
  };
136
171
 
@@ -2,26 +2,43 @@
2
2
 
3
3
  var core = require('@tusi-ai/core');
4
4
 
5
- var __async = (__this, __arguments, generator) => {
6
- return new Promise((resolve, reject) => {
7
- var fulfilled = (value) => {
8
- try {
9
- step(generator.next(value));
10
- } catch (e) {
11
- reject(e);
12
- }
13
- };
14
- var rejected = (value) => {
15
- try {
16
- step(generator.throw(value));
17
- } catch (e) {
18
- reject(e);
19
- }
20
- };
21
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
- step((generator = generator.apply(__this, __arguments)).next());
5
+ // src/contact-picker/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) };
23
14
  });
24
- };
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
+ }
25
42
  var BaseAdapter = class {
26
43
  /**
27
44
  * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
@@ -87,13 +104,10 @@ var ContactPicker = {
87
104
  /**
88
105
  * 打开系统通讯录。
89
106
  *
90
- * @returns 选中的联系人。用户取消时 `{ canceled: true }`,不是错误
91
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前浏览器没有该选择器
107
+ * @returns `code` 为 0 时 `data` 是选中的联系人。用户取消时 `data` 为 `{ canceled: true }`。失败时 `errMsg` 可直接 toast
92
108
  */
93
109
  pickContact() {
94
- return __async(this, null, function* () {
95
- return getAdapter().pickContact();
96
- });
110
+ return callPlugin(() => getAdapter().pickContact());
97
111
  }
98
112
  };
99
113
 
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.mjs';
2
+
1
3
  /** 一个电话号码。 */
2
4
  interface PhoneNumber {
3
5
  /** 号码原文。 */
@@ -28,10 +30,9 @@ declare const ContactPicker: {
28
30
  /**
29
31
  * 打开系统通讯录。
30
32
  *
31
- * @returns 选中的联系人。用户取消时 `{ canceled: true }`,不是错误
32
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前浏览器没有该选择器
33
+ * @returns `code` 为 0 时 `data` 是选中的联系人。用户取消时 `data` 为 `{ canceled: true }`。失败时 `errMsg` 可直接 toast
33
34
  */
34
- pickContact(): Promise<PickContactResult>;
35
+ pickContact(): Promise<PluginResult<PickContactResult>>;
35
36
  };
36
37
 
37
- export { ContactPicker, type PhoneNumber, type PickContactResult };
38
+ export { ContactPicker, type PhoneNumber, type PickContactResult, PluginResult };
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.js';
2
+
1
3
  /** 一个电话号码。 */
2
4
  interface PhoneNumber {
3
5
  /** 号码原文。 */
@@ -28,10 +30,9 @@ declare const ContactPicker: {
28
30
  /**
29
31
  * 打开系统通讯录。
30
32
  *
31
- * @returns 选中的联系人。用户取消时 `{ canceled: true }`,不是错误
32
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前浏览器没有该选择器
33
+ * @returns `code` 为 0 时 `data` 是选中的联系人。用户取消时 `data` 为 `{ canceled: true }`。失败时 `errMsg` 可直接 toast
33
34
  */
34
- pickContact(): Promise<PickContactResult>;
35
+ pickContact(): Promise<PluginResult<PickContactResult>>;
35
36
  };
36
37
 
37
- export { ContactPicker, type PhoneNumber, type PickContactResult };
38
+ export { ContactPicker, type PhoneNumber, type PickContactResult, PluginResult };
@@ -1,25 +1,42 @@
1
- import { getRuntimeEnv, RuntimeEnv, bridge, TusiError, ErrorCode } from '@tusi-ai/core';
1
+ import { ErrorCode, TusiError, getRuntimeEnv, RuntimeEnv, bridge } from '@tusi-ai/core';
2
2
 
3
- var __async = (__this, __arguments, generator) => {
4
- return new Promise((resolve, reject) => {
5
- var fulfilled = (value) => {
6
- try {
7
- step(generator.next(value));
8
- } catch (e) {
9
- reject(e);
10
- }
11
- };
12
- var rejected = (value) => {
13
- try {
14
- step(generator.throw(value));
15
- } catch (e) {
16
- reject(e);
17
- }
18
- };
19
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
20
- step((generator = generator.apply(__this, __arguments)).next());
3
+ // src/contact-picker/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) };
21
12
  });
22
- };
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
+ }
23
40
  var BaseAdapter = class {
24
41
  /**
25
42
  * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
@@ -85,13 +102,10 @@ var ContactPicker = {
85
102
  /**
86
103
  * 打开系统通讯录。
87
104
  *
88
- * @returns 选中的联系人。用户取消时 `{ canceled: true }`,不是错误
89
- * @throws {@link TusiError} {@link ErrorCode.Unsupported} 当前浏览器没有该选择器
105
+ * @returns `code` 为 0 时 `data` 是选中的联系人。用户取消时 `data` 为 `{ canceled: true }`。失败时 `errMsg` 可直接 toast
90
106
  */
91
107
  pickContact() {
92
- return __async(this, null, function* () {
93
- return getAdapter().pickContact();
94
- });
108
+ return callPlugin(() => getAdapter().pickContact());
95
109
  }
96
110
  };
97
111
 
@@ -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`。
@@ -341,106 +377,110 @@ var Filesystem = {
341
377
  * 打开系统选择器。
342
378
  *
343
379
  * @param options - 种类和数量。不传时选择图片或视频,最多 9 个
344
- * @returns 选中的文件。用户取消时 `files` 为空数组
345
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
380
+ * @returns `code` 为 0 时 `data.files` 是选中的文件。用户取消时 `files` 为空数组。失败时 `errMsg` 可直接 toast
346
381
  */
347
382
  pickMedia(options) {
348
- return __async(this, null, function* () {
383
+ return callPlugin(() => __async(null, null, function* () {
349
384
  assertMedia(options);
350
385
  return getAdapter().pickMedia(options);
351
- });
386
+ }));
352
387
  },
353
388
  /**
354
389
  * 按文件类型保存。端上写入 `Download/YYB/`,浏览器触发下载。
355
390
  *
356
391
  * @param options - 类型、来源和内容
357
- * @returns 保存结果。可预期的失败在 `success` 里,不抛错
358
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
392
+ * @returns `code` 为 0 时 `data` 是保存结果。可预期的失败在 `data.success` 和 `data.errMsg` 里。调用失败时外层 `errMsg` 可直接 toast
359
393
  */
360
394
  saveFile(options) {
361
- return __async(this, null, function* () {
395
+ return callPlugin(() => __async(null, null, function* () {
362
396
  assertSave(options);
363
397
  return getAdapter().saveFile(options);
364
- });
398
+ }));
365
399
  },
366
400
  /** 读取应用目录里的文件。浏览器不提供这些目录。 */
367
401
  readFile(options) {
368
- return __async(this, null, function* () {
402
+ return callPlugin(() => __async(null, null, function* () {
369
403
  assertPath("Filesystem.readFile", options);
370
404
  return getAdapter().readFile(options);
371
- });
405
+ }));
372
406
  },
373
407
  /** 写入应用目录。 */
374
408
  writeFile(options) {
375
- return __async(this, null, function* () {
409
+ return callPlugin(() => __async(null, null, function* () {
376
410
  assertPath("Filesystem.writeFile", options);
377
411
  if (options.data === void 0) invalid("Filesystem.writeFile", "data is required");
378
412
  return getAdapter().writeFile(options);
379
- });
413
+ }));
380
414
  },
381
415
  /** 向已有文件追加内容。 */
382
416
  appendFile(options) {
383
- return __async(this, null, function* () {
417
+ return callPlugin(() => __async(null, null, function* () {
384
418
  assertPath("Filesystem.appendFile", options);
385
419
  if (options.data === void 0) invalid("Filesystem.appendFile", "data is required");
386
- return getAdapter().appendFile(options);
387
- });
420
+ yield getAdapter().appendFile(options);
421
+ return null;
422
+ }));
388
423
  },
389
424
  /** 删除应用目录里的文件。 */
390
425
  deleteFile(options) {
391
- return __async(this, null, function* () {
426
+ return callPlugin(() => __async(null, null, function* () {
392
427
  assertPath("Filesystem.deleteFile", options);
393
- return getAdapter().deleteFile(options);
394
- });
428
+ yield getAdapter().deleteFile(options);
429
+ return null;
430
+ }));
395
431
  },
396
432
  /** 创建目录。 */
397
433
  mkdir(options) {
398
- return __async(this, null, function* () {
434
+ return callPlugin(() => __async(null, null, function* () {
399
435
  assertPath("Filesystem.mkdir", options);
400
- return getAdapter().mkdir(options);
401
- });
436
+ yield getAdapter().mkdir(options);
437
+ return null;
438
+ }));
402
439
  },
403
440
  /** 删除目录。 */
404
441
  rmdir(options) {
405
- return __async(this, null, function* () {
442
+ return callPlugin(() => __async(null, null, function* () {
406
443
  assertPath("Filesystem.rmdir", options);
407
- return getAdapter().rmdir(options);
408
- });
444
+ yield getAdapter().rmdir(options);
445
+ return null;
446
+ }));
409
447
  },
410
448
  /** 列出目录。 */
411
449
  readdir(options) {
412
- return __async(this, null, function* () {
450
+ return callPlugin(() => __async(null, null, function* () {
413
451
  assertPath("Filesystem.readdir", options);
414
452
  return getAdapter().readdir(options);
415
- });
453
+ }));
416
454
  },
417
455
  /** 取当前页面可加载的地址。 */
418
456
  getUri(options) {
419
- return __async(this, null, function* () {
457
+ return callPlugin(() => __async(null, null, function* () {
420
458
  assertPath("Filesystem.getUri", options);
421
459
  return getAdapter().getUri(options);
422
- });
460
+ }));
423
461
  },
424
462
  /** 读取大小和修改时间。 */
425
463
  stat(options) {
426
- return __async(this, null, function* () {
464
+ return callPlugin(() => __async(null, null, function* () {
427
465
  assertPath("Filesystem.stat", options);
428
466
  return getAdapter().stat(options);
429
- });
467
+ }));
430
468
  },
431
469
  /** 改名或移动。 */
432
470
  rename(options) {
433
- return __async(this, null, function* () {
471
+ return callPlugin(() => __async(null, null, function* () {
434
472
  assertTransfer("Filesystem.rename", options);
435
- return getAdapter().rename(options);
436
- });
473
+ yield getAdapter().rename(options);
474
+ return null;
475
+ }));
437
476
  },
438
477
  /** 复制。 */
439
478
  copy(options) {
440
- return __async(this, null, function* () {
479
+ return callPlugin(() => __async(null, null, function* () {
441
480
  assertTransfer("Filesystem.copy", options);
442
- return getAdapter().copy(options);
443
- });
481
+ yield getAdapter().copy(options);
482
+ return null;
483
+ }));
444
484
  }
445
485
  };
446
486
 
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.mjs';
2
+
1
3
  /** `pickMedia` 能选择的种类。`all` 只包含图片和视频。 */
2
4
  type MediaType = 'all' | 'image' | 'video' | 'audio' | 'file';
3
5
  /** 选中文件的种类。 */
@@ -155,48 +157,46 @@ declare const Filesystem: {
155
157
  * 打开系统选择器。
156
158
  *
157
159
  * @param options - 种类和数量。不传时选择图片或视频,最多 9 个
158
- * @returns 选中的文件。用户取消时 `files` 为空数组
159
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
160
+ * @returns `code` 为 0 时 `data.files` 是选中的文件。用户取消时 `files` 为空数组。失败时 `errMsg` 可直接 toast
160
161
  */
161
- pickMedia(options?: PickMediaOptions): Promise<PickMediaResult>;
162
+ pickMedia(options?: PickMediaOptions): Promise<PluginResult<PickMediaResult>>;
162
163
  /**
163
164
  * 按文件类型保存。端上写入 `Download/YYB/`,浏览器触发下载。
164
165
  *
165
166
  * @param options - 类型、来源和内容
166
- * @returns 保存结果。可预期的失败在 `success` 里,不抛错
167
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
167
+ * @returns `code` 为 0 时 `data` 是保存结果。可预期的失败在 `data.success` 和 `data.errMsg` 里。调用失败时外层 `errMsg` 可直接 toast
168
168
  */
169
- saveFile(options: SaveFileOptions): Promise<SaveFileResult>;
169
+ saveFile(options: SaveFileOptions): Promise<PluginResult<SaveFileResult>>;
170
170
  /** 读取应用目录里的文件。浏览器不提供这些目录。 */
171
- readFile(options: ReadFileOptions): Promise<{
171
+ readFile(options: ReadFileOptions): Promise<PluginResult<{
172
172
  data: string;
173
- }>;
173
+ }>>;
174
174
  /** 写入应用目录。 */
175
- writeFile(options: WriteFileOptions): Promise<{
175
+ writeFile(options: WriteFileOptions): Promise<PluginResult<{
176
176
  uri: string;
177
- }>;
177
+ }>>;
178
178
  /** 向已有文件追加内容。 */
179
- appendFile(options: AppendFileOptions): Promise<void>;
179
+ appendFile(options: AppendFileOptions): Promise<PluginResult<null>>;
180
180
  /** 删除应用目录里的文件。 */
181
- deleteFile(options: FilesystemPathOptions): Promise<void>;
181
+ deleteFile(options: FilesystemPathOptions): Promise<PluginResult<null>>;
182
182
  /** 创建目录。 */
183
- mkdir(options: FilesystemPathOptions): Promise<void>;
183
+ mkdir(options: FilesystemPathOptions): Promise<PluginResult<null>>;
184
184
  /** 删除目录。 */
185
- rmdir(options: FilesystemPathOptions): Promise<void>;
185
+ rmdir(options: FilesystemPathOptions): Promise<PluginResult<null>>;
186
186
  /** 列出目录。 */
187
- readdir(options: FilesystemPathOptions): Promise<{
187
+ readdir(options: FilesystemPathOptions): Promise<PluginResult<{
188
188
  files: FilesystemFileInfo[];
189
- }>;
189
+ }>>;
190
190
  /** 取当前页面可加载的地址。 */
191
- getUri(options: FilesystemPathOptions): Promise<{
191
+ getUri(options: FilesystemPathOptions): Promise<PluginResult<{
192
192
  uri: string;
193
- }>;
193
+ }>>;
194
194
  /** 读取大小和修改时间。 */
195
- stat(options: FilesystemPathOptions): Promise<FilesystemStat>;
195
+ stat(options: FilesystemPathOptions): Promise<PluginResult<FilesystemStat>>;
196
196
  /** 改名或移动。 */
197
- rename(options: TransferOptions): Promise<void>;
197
+ rename(options: TransferOptions): Promise<PluginResult<null>>;
198
198
  /** 复制。 */
199
- copy(options: TransferOptions): Promise<void>;
199
+ copy(options: TransferOptions): Promise<PluginResult<null>>;
200
200
  };
201
201
 
202
- export { type AppendFileOptions, Filesystem, type FilesystemDirectory, type FilesystemEncoding, type FilesystemFileInfo, type FilesystemPathOptions, type FilesystemStat, type MediaFile, type MediaFileType, type MediaType, type PickMediaOptions, type PickMediaResult, type ReadFileOptions, type SaveFileOptions, type SaveFileResult, type SaveFileSource, type SaveFileType, type TransferOptions, type WriteFileOptions };
202
+ export { type AppendFileOptions, Filesystem, type FilesystemDirectory, type FilesystemEncoding, type FilesystemFileInfo, type FilesystemPathOptions, type FilesystemStat, type MediaFile, type MediaFileType, type MediaType, type PickMediaOptions, type PickMediaResult, PluginResult, type ReadFileOptions, type SaveFileOptions, type SaveFileResult, type SaveFileSource, type SaveFileType, type TransferOptions, type WriteFileOptions };
@@ -1,3 +1,5 @@
1
+ import { P as PluginResult } from '../result-CbliqkNp.js';
2
+
1
3
  /** `pickMedia` 能选择的种类。`all` 只包含图片和视频。 */
2
4
  type MediaType = 'all' | 'image' | 'video' | 'audio' | 'file';
3
5
  /** 选中文件的种类。 */
@@ -155,48 +157,46 @@ declare const Filesystem: {
155
157
  * 打开系统选择器。
156
158
  *
157
159
  * @param options - 种类和数量。不传时选择图片或视频,最多 9 个
158
- * @returns 选中的文件。用户取消时 `files` 为空数组
159
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
160
+ * @returns `code` 为 0 时 `data.files` 是选中的文件。用户取消时 `files` 为空数组。失败时 `errMsg` 可直接 toast
160
161
  */
161
- pickMedia(options?: PickMediaOptions): Promise<PickMediaResult>;
162
+ pickMedia(options?: PickMediaOptions): Promise<PluginResult<PickMediaResult>>;
162
163
  /**
163
164
  * 按文件类型保存。端上写入 `Download/YYB/`,浏览器触发下载。
164
165
  *
165
166
  * @param options - 类型、来源和内容
166
- * @returns 保存结果。可预期的失败在 `success` 里,不抛错
167
- * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不合法
167
+ * @returns `code` 为 0 时 `data` 是保存结果。可预期的失败在 `data.success` 和 `data.errMsg` 里。调用失败时外层 `errMsg` 可直接 toast
168
168
  */
169
- saveFile(options: SaveFileOptions): Promise<SaveFileResult>;
169
+ saveFile(options: SaveFileOptions): Promise<PluginResult<SaveFileResult>>;
170
170
  /** 读取应用目录里的文件。浏览器不提供这些目录。 */
171
- readFile(options: ReadFileOptions): Promise<{
171
+ readFile(options: ReadFileOptions): Promise<PluginResult<{
172
172
  data: string;
173
- }>;
173
+ }>>;
174
174
  /** 写入应用目录。 */
175
- writeFile(options: WriteFileOptions): Promise<{
175
+ writeFile(options: WriteFileOptions): Promise<PluginResult<{
176
176
  uri: string;
177
- }>;
177
+ }>>;
178
178
  /** 向已有文件追加内容。 */
179
- appendFile(options: AppendFileOptions): Promise<void>;
179
+ appendFile(options: AppendFileOptions): Promise<PluginResult<null>>;
180
180
  /** 删除应用目录里的文件。 */
181
- deleteFile(options: FilesystemPathOptions): Promise<void>;
181
+ deleteFile(options: FilesystemPathOptions): Promise<PluginResult<null>>;
182
182
  /** 创建目录。 */
183
- mkdir(options: FilesystemPathOptions): Promise<void>;
183
+ mkdir(options: FilesystemPathOptions): Promise<PluginResult<null>>;
184
184
  /** 删除目录。 */
185
- rmdir(options: FilesystemPathOptions): Promise<void>;
185
+ rmdir(options: FilesystemPathOptions): Promise<PluginResult<null>>;
186
186
  /** 列出目录。 */
187
- readdir(options: FilesystemPathOptions): Promise<{
187
+ readdir(options: FilesystemPathOptions): Promise<PluginResult<{
188
188
  files: FilesystemFileInfo[];
189
- }>;
189
+ }>>;
190
190
  /** 取当前页面可加载的地址。 */
191
- getUri(options: FilesystemPathOptions): Promise<{
191
+ getUri(options: FilesystemPathOptions): Promise<PluginResult<{
192
192
  uri: string;
193
- }>;
193
+ }>>;
194
194
  /** 读取大小和修改时间。 */
195
- stat(options: FilesystemPathOptions): Promise<FilesystemStat>;
195
+ stat(options: FilesystemPathOptions): Promise<PluginResult<FilesystemStat>>;
196
196
  /** 改名或移动。 */
197
- rename(options: TransferOptions): Promise<void>;
197
+ rename(options: TransferOptions): Promise<PluginResult<null>>;
198
198
  /** 复制。 */
199
- copy(options: TransferOptions): Promise<void>;
199
+ copy(options: TransferOptions): Promise<PluginResult<null>>;
200
200
  };
201
201
 
202
- export { type AppendFileOptions, Filesystem, type FilesystemDirectory, type FilesystemEncoding, type FilesystemFileInfo, type FilesystemPathOptions, type FilesystemStat, type MediaFile, type MediaFileType, type MediaType, type PickMediaOptions, type PickMediaResult, type ReadFileOptions, type SaveFileOptions, type SaveFileResult, type SaveFileSource, type SaveFileType, type TransferOptions, type WriteFileOptions };
202
+ export { type AppendFileOptions, Filesystem, type FilesystemDirectory, type FilesystemEncoding, type FilesystemFileInfo, type FilesystemPathOptions, type FilesystemStat, type MediaFile, type MediaFileType, type MediaType, type PickMediaOptions, type PickMediaResult, PluginResult, type ReadFileOptions, type SaveFileOptions, type SaveFileResult, type SaveFileSource, type SaveFileType, type TransferOptions, type WriteFileOptions };