@h-ai/capacitor 0.1.0-alpha.66 → 0.1.0-alpha.68
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.en.md +24 -12
- package/README.ja.md +24 -12
- package/README.md +25 -13
- package/dist/index.d.ts +295 -48
- package/dist/index.js +264 -184
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,17 @@ import * as _h_ai_core from '@h-ai/core';
|
|
|
2
2
|
import { HaiResult } from '@h-ai/core';
|
|
3
3
|
import { TokenStorage } from '@h-ai/api-client';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Capacitor 模块的公共错误定义;业务操作通过 HaiResult 返回。
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { HaiCapacitorError } from '@h-ai/capacitor'
|
|
10
|
+
* import { err } from '@h-ai/core'
|
|
11
|
+
*
|
|
12
|
+
* const result = err(HaiCapacitorError.NOT_AVAILABLE, 'Native bridge required')
|
|
13
|
+
* if (!result.success) void result.error.code
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
5
16
|
declare const HaiCapacitorError: {
|
|
6
17
|
readonly INIT_FAILED: _h_ai_core.HaiErrorDef;
|
|
7
18
|
readonly NOT_AVAILABLE: _h_ai_core.HaiErrorDef;
|
|
@@ -14,10 +25,24 @@ declare const HaiCapacitorError: {
|
|
|
14
25
|
readonly APP_VERSION_FAILED: _h_ai_core.HaiErrorDef;
|
|
15
26
|
readonly PUSH_REGISTER_FAILED: _h_ai_core.HaiErrorDef;
|
|
16
27
|
readonly PUSH_LISTEN_FAILED: _h_ai_core.HaiErrorDef;
|
|
28
|
+
readonly PUSH_CLEANUP_FAILED: _h_ai_core.HaiErrorDef;
|
|
17
29
|
readonly CAMERA_FAILED: _h_ai_core.HaiErrorDef;
|
|
18
30
|
readonly STATUS_BAR_FAILED: _h_ai_core.HaiErrorDef;
|
|
19
31
|
};
|
|
20
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* 设备信息操作
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import type { DeviceOperations } from '@h-ai/capacitor'
|
|
37
|
+
*
|
|
38
|
+
* async function use(operations: DeviceOperations) {
|
|
39
|
+
* const result = await operations.getInfo()
|
|
40
|
+
* if (!result.success) return result.error.message
|
|
41
|
+
* return result.data
|
|
42
|
+
* }
|
|
43
|
+
* // 由已初始化的 capacitor.device 提供这些操作。
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
21
46
|
interface DeviceOperations {
|
|
22
47
|
/** 获取设备信息(平台、型号、系统版本等) */
|
|
23
48
|
getInfo: () => Promise<HaiResult<DeviceInfo>>;
|
|
@@ -27,19 +52,58 @@ interface DeviceOperations {
|
|
|
27
52
|
build: string;
|
|
28
53
|
}>>;
|
|
29
54
|
}
|
|
30
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* 相机操作
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import type { CameraOperations } from '@h-ai/capacitor'
|
|
60
|
+
*
|
|
61
|
+
* async function use(operations: CameraOperations) {
|
|
62
|
+
* const result = await operations.takePhoto({ source: 'photos' })
|
|
63
|
+
* if (!result.success) return result.error.message
|
|
64
|
+
* return result.data
|
|
65
|
+
* }
|
|
66
|
+
* // 由已初始化的 capacitor.camera 提供这些操作。
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
31
69
|
interface CameraOperations {
|
|
32
70
|
/** 拍照或选取相册图片 */
|
|
33
71
|
takePhoto: (options?: PhotoOptions) => Promise<HaiResult<PhotoResult>>;
|
|
34
72
|
}
|
|
35
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* 推送通知操作
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import type { PushOperations } from '@h-ai/capacitor'
|
|
78
|
+
*
|
|
79
|
+
* async function use(operations: PushOperations) {
|
|
80
|
+
* const result = await operations.register()
|
|
81
|
+
* if (!result.success) return result.error.message
|
|
82
|
+
* return result.data
|
|
83
|
+
* }
|
|
84
|
+
* // 由已初始化的 capacitor.push 提供这些操作。
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
36
87
|
interface PushOperations {
|
|
37
|
-
/**
|
|
38
|
-
register: () => Promise<HaiResult<PushRegistration>>;
|
|
39
|
-
/**
|
|
40
|
-
listen: (callbacks: PushNotificationCallbacks) => Promise<HaiResult<
|
|
88
|
+
/** 注册原生 Token;30 秒总超时,可取消,结束时回收监听器。 */
|
|
89
|
+
register: (options?: PushOptions) => Promise<HaiResult<PushRegistration>>;
|
|
90
|
+
/** 监听原生事件;设置阶段限时 30 秒,成功后由 cleanup/信号/模块关闭释放。 */
|
|
91
|
+
listen: (callbacks: PushNotificationCallbacks, options?: PushOptions) => Promise<HaiResult<PushCleanup>>;
|
|
41
92
|
}
|
|
42
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* 状态栏操作
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import type { StatusBarOperations } from '@h-ai/capacitor'
|
|
98
|
+
*
|
|
99
|
+
* async function use(operations: StatusBarOperations) {
|
|
100
|
+
* const result = await operations.configure({ style: 'dark' })
|
|
101
|
+
* if (!result.success) return result.error.message
|
|
102
|
+
* return result.data
|
|
103
|
+
* }
|
|
104
|
+
* // 由已初始化的 capacitor.statusBar 提供这些操作。
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
43
107
|
interface StatusBarOperations {
|
|
44
108
|
/** 配置状态栏(样式、背景色、沉浸式) */
|
|
45
109
|
configure: (config: StatusBarConfig) => Promise<HaiResult<void>>;
|
|
@@ -48,7 +112,20 @@ interface StatusBarOperations {
|
|
|
48
112
|
/** 隐藏状态栏 */
|
|
49
113
|
hide: () => Promise<HaiResult<void>>;
|
|
50
114
|
}
|
|
51
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Preferences 操作(安全读写,返回 HaiResult)
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import type { PreferencesOperations } from '@h-ai/capacitor'
|
|
120
|
+
*
|
|
121
|
+
* async function use(operations: PreferencesOperations) {
|
|
122
|
+
* const result = await operations.get('theme')
|
|
123
|
+
* if (!result.success) return result.error.message
|
|
124
|
+
* return result.data
|
|
125
|
+
* }
|
|
126
|
+
* // 由已初始化的 capacitor.preferences 提供这些操作。
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
52
129
|
interface PreferencesOperations {
|
|
53
130
|
/** 安全读取 Preference 值 */
|
|
54
131
|
get: (key: string) => Promise<HaiResult<string | null>>;
|
|
@@ -57,12 +134,29 @@ interface PreferencesOperations {
|
|
|
57
134
|
/** 安全删除 Preference 值 */
|
|
58
135
|
remove: (key: string) => Promise<HaiResult<void>>;
|
|
59
136
|
}
|
|
60
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Capacitor 模块服务对象接口
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { capacitor } from '@h-ai/capacitor'
|
|
142
|
+
*
|
|
143
|
+
* const initialized = await capacitor.init()
|
|
144
|
+
* if (!initialized.success) throw new Error(initialized.error.message)
|
|
145
|
+
* try {
|
|
146
|
+
* const result = await capacitor.device.getInfo()
|
|
147
|
+
* if (!result.success) throw new Error(result.error.message)
|
|
148
|
+
* void result.data
|
|
149
|
+
* } finally {
|
|
150
|
+
* const closed = await capacitor.close()
|
|
151
|
+
* if (!closed.success) throw new Error(closed.error.message)
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
61
155
|
interface CapacitorFunctions {
|
|
62
156
|
/** 初始化 Capacitor 模块 */
|
|
63
157
|
init: () => Promise<HaiResult<void>>;
|
|
64
|
-
/**
|
|
65
|
-
close: () => Promise<void
|
|
158
|
+
/** 关闭模块并回收推送监听;失败时保持不可用,保留句柄供再次 close 重试。 */
|
|
159
|
+
close: () => Promise<HaiResult<void>>;
|
|
66
160
|
/** 获取当前平台 */
|
|
67
161
|
getPlatform: () => string;
|
|
68
162
|
/** 是否运行在原生 App 中 */
|
|
@@ -80,9 +174,27 @@ interface CapacitorFunctions {
|
|
|
80
174
|
/** Preferences 安全读写操作 */
|
|
81
175
|
readonly preferences: PreferencesOperations;
|
|
82
176
|
}
|
|
83
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* 设备平台
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import type { DevicePlatform } from '@h-ai/capacitor'
|
|
182
|
+
*
|
|
183
|
+
* const value: DevicePlatform = 'android'
|
|
184
|
+
* void value
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
84
187
|
type DevicePlatform = 'ios' | 'android' | 'web';
|
|
85
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* 设备信息
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* import type { DeviceInfo } from '@h-ai/capacitor'
|
|
193
|
+
*
|
|
194
|
+
* const value: DeviceInfo = { platform: 'android', osVersion: '15', model: 'Example device', manufacturer: 'Example', isVirtual: false }
|
|
195
|
+
* void value
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
86
198
|
interface DeviceInfo {
|
|
87
199
|
/** 平台(ios / android / web) */
|
|
88
200
|
platform: DevicePlatform;
|
|
@@ -99,7 +211,44 @@ interface DeviceInfo {
|
|
|
99
211
|
/** 应用 Build 号 */
|
|
100
212
|
appBuild?: string;
|
|
101
213
|
}
|
|
102
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* 推送流程的取消选项;listen 成功后信号仍可终止监听。
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* import type { PushOptions } from '@h-ai/capacitor'
|
|
219
|
+
*
|
|
220
|
+
* const value: PushOptions = { signal: new AbortController().signal }
|
|
221
|
+
* void value
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
interface PushOptions {
|
|
225
|
+
/** 取消当前注册或监听,不影响其他消费者拥有的句柄。 */
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 幂等推送清理函数;原生 remove 失败返回错误,调用同一函数可重试。
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* import type { PushCleanup } from '@h-ai/capacitor'
|
|
233
|
+
*
|
|
234
|
+
* async function release(cleanup: PushCleanup) {
|
|
235
|
+
* const result = await cleanup()
|
|
236
|
+
* if (!result.success) return cleanup() // 同一所有权句柄允许重试清理。
|
|
237
|
+
* return result
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
type PushCleanup = () => Promise<HaiResult<void>>;
|
|
242
|
+
/**
|
|
243
|
+
* 推送通知数据
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* import type { PushNotification } from '@h-ai/capacitor'
|
|
247
|
+
*
|
|
248
|
+
* const value: PushNotification = { id: 'notice_1', title: 'Order ready', data: { orderId: 'order_1' } }
|
|
249
|
+
* void value
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
103
252
|
interface PushNotification {
|
|
104
253
|
/** 通知 ID */
|
|
105
254
|
id: string;
|
|
@@ -110,21 +259,57 @@ interface PushNotification {
|
|
|
110
259
|
/** 附加数据 */
|
|
111
260
|
data?: Record<string, unknown>;
|
|
112
261
|
}
|
|
113
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* 推送注册结果
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import type { PushRegistration } from '@h-ai/capacitor'
|
|
267
|
+
*
|
|
268
|
+
* const value: PushRegistration = { token: 'example-only-native-token' }
|
|
269
|
+
* void value
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
114
272
|
interface PushRegistration {
|
|
115
273
|
/** 设备推送 Token */
|
|
116
274
|
token: string;
|
|
117
275
|
}
|
|
118
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* 推送通知回调
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import type { PushNotificationCallbacks } from '@h-ai/capacitor'
|
|
281
|
+
*
|
|
282
|
+
* const value: PushNotificationCallbacks = { onReceived: notification => { document.title = notification.title ?? 'Notice' } }
|
|
283
|
+
* void value
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
119
286
|
interface PushNotificationCallbacks {
|
|
120
287
|
/** 收到推送时调用 */
|
|
121
288
|
onReceived?: (notification: PushNotification) => void;
|
|
122
289
|
/** 用户点击推送时调用 */
|
|
123
290
|
onActionPerformed?: (notification: PushNotification) => void;
|
|
124
291
|
}
|
|
125
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* 照片来源
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* import type { PhotoSource } from '@h-ai/capacitor'
|
|
297
|
+
*
|
|
298
|
+
* const value: PhotoSource = 'photos'
|
|
299
|
+
* void value
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
126
302
|
type PhotoSource = 'camera' | 'photos' | 'prompt';
|
|
127
|
-
/**
|
|
303
|
+
/**
|
|
304
|
+
* 照片选项
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* import type { PhotoOptions } from '@h-ai/capacitor'
|
|
308
|
+
*
|
|
309
|
+
* const value: PhotoOptions = { source: 'photos', resultType: 'uri', quality: 90, width: 1200 }
|
|
310
|
+
* void value
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
128
313
|
interface PhotoOptions {
|
|
129
314
|
/** 来源(默认 'prompt') */
|
|
130
315
|
source?: PhotoSource;
|
|
@@ -137,16 +322,43 @@ interface PhotoOptions {
|
|
|
137
322
|
/** 返回格式 */
|
|
138
323
|
resultType?: 'uri' | 'base64' | 'dataUrl';
|
|
139
324
|
}
|
|
140
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* 照片结果
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* import type { PhotoResult } from '@h-ai/capacitor'
|
|
330
|
+
*
|
|
331
|
+
* const value: PhotoResult = { data: 'file:///example/photo.jpeg', format: 'jpeg' }
|
|
332
|
+
* void value
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
141
335
|
interface PhotoResult {
|
|
142
336
|
/** 图片路径或 base64 数据 */
|
|
143
337
|
data: string;
|
|
144
|
-
/** MIME 类型 */
|
|
338
|
+
/** 原生插件返回的格式扩展名(如 jpeg),不是 MIME 类型 */
|
|
145
339
|
format: string;
|
|
146
340
|
}
|
|
147
|
-
/**
|
|
341
|
+
/**
|
|
342
|
+
* 状态栏样式
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* import type { StatusBarStyle } from '@h-ai/capacitor'
|
|
346
|
+
*
|
|
347
|
+
* const value: StatusBarStyle = 'dark'
|
|
348
|
+
* void value
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
148
351
|
type StatusBarStyle = 'dark' | 'light' | 'default';
|
|
149
|
-
/**
|
|
352
|
+
/**
|
|
353
|
+
* 状态栏配置
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* import type { StatusBarConfig } from '@h-ai/capacitor'
|
|
357
|
+
*
|
|
358
|
+
* const value: StatusBarConfig = { style: 'dark', overlay: false }
|
|
359
|
+
* void value
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
150
362
|
interface StatusBarConfig {
|
|
151
363
|
/** 状态栏文字样式 */
|
|
152
364
|
style?: StatusBarStyle;
|
|
@@ -167,15 +379,19 @@ interface StatusBarConfig {
|
|
|
167
379
|
|
|
168
380
|
/**
|
|
169
381
|
* Capacitor 模块服务对象
|
|
170
|
-
*
|
|
171
382
|
* @example
|
|
172
383
|
* ```ts
|
|
173
384
|
* import { capacitor } from '@h-ai/capacitor'
|
|
174
385
|
*
|
|
175
|
-
* const
|
|
176
|
-
* if (
|
|
177
|
-
*
|
|
178
|
-
* await capacitor.
|
|
386
|
+
* const initialized = await capacitor.init()
|
|
387
|
+
* if (!initialized.success) throw new Error(initialized.error.message)
|
|
388
|
+
* try {
|
|
389
|
+
* const result = await capacitor.device.getInfo()
|
|
390
|
+
* if (!result.success) throw new Error(result.error.message)
|
|
391
|
+
* void result.data
|
|
392
|
+
* } finally {
|
|
393
|
+
* const closed = await capacitor.close()
|
|
394
|
+
* if (!closed.success) throw new Error(closed.error.message)
|
|
179
395
|
* }
|
|
180
396
|
* ```
|
|
181
397
|
*/
|
|
@@ -194,22 +410,26 @@ declare const capacitor: CapacitorFunctions;
|
|
|
194
410
|
* 创建基于原生安全存储的 TokenStorage
|
|
195
411
|
*
|
|
196
412
|
* 在原生 Android/iOS 环境下使用 `@aparajita/capacitor-secure-storage`
|
|
197
|
-
* 保存 access token / refresh token
|
|
413
|
+
* 保存 access token / refresh token。所有方法的存储/平台错误均通过 Promise 拒绝传播,
|
|
414
|
+
* Web 调用明确失败,不做存储回退或伪成功。
|
|
415
|
+
* `clear()` 一开始即屏蔽本实例旧凭据,删除失败时仍保持屏蔽;相应 key 成功写入后恢复读取。
|
|
416
|
+
* 任一凭据写入失败也会屏蔽整对凭据,避免 access 已保存、refresh 失败时暴露半完成登录。
|
|
417
|
+
* 本实例屏蔽不代表原生持久数据已删除;跨重启撤销仍依赖服务端退出/撤销会话。
|
|
198
418
|
*
|
|
199
419
|
* @returns TokenStorage 实例
|
|
200
|
-
*
|
|
420
|
+
* @throws 返回适配器的方法在插件不可用或原生存储失败时拒绝 Promise。
|
|
201
421
|
* @example
|
|
202
422
|
* ```ts
|
|
203
423
|
* import { createCapacitorTokenStorage } from '@h-ai/capacitor'
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* }
|
|
424
|
+
*
|
|
425
|
+
* const storage = createCapacitorTokenStorage()
|
|
426
|
+
* try {
|
|
427
|
+
* const token = await storage.getAccessToken()
|
|
428
|
+
* void token // 仅原生安全存储;平台或存储失败会拒绝 Promise。
|
|
429
|
+
* } catch (cause) {
|
|
430
|
+
* // 应阻止认证流程继续并呈现本地化错误;不回退到普通 Preferences。
|
|
431
|
+
* void cause
|
|
432
|
+
* }
|
|
213
433
|
* ```
|
|
214
434
|
*/
|
|
215
435
|
declare function createCapacitorTokenStorage(): TokenStorage;
|
|
@@ -218,12 +438,19 @@ declare function createCapacitorTokenStorage(): TokenStorage;
|
|
|
218
438
|
*
|
|
219
439
|
* @param key - Preference Key
|
|
220
440
|
* @returns HaiResult 包裹的值
|
|
221
|
-
*
|
|
222
441
|
* @example
|
|
223
442
|
* ```ts
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
443
|
+
* import { capacitor } from '@h-ai/capacitor'
|
|
444
|
+
*
|
|
445
|
+
* const initialized = await capacitor.init()
|
|
446
|
+
* if (!initialized.success) throw new Error(initialized.error.message)
|
|
447
|
+
* try {
|
|
448
|
+
* const result = await capacitor.preferences.get('theme')
|
|
449
|
+
* if (!result.success) throw new Error(result.error.message)
|
|
450
|
+
* void result.data
|
|
451
|
+
* } finally {
|
|
452
|
+
* const closed = await capacitor.close()
|
|
453
|
+
* if (!closed.success) throw new Error(closed.error.message)
|
|
227
454
|
* }
|
|
228
455
|
* ```
|
|
229
456
|
*/
|
|
@@ -234,10 +461,20 @@ declare function safeGetPreference(key: string): Promise<HaiResult<string | null
|
|
|
234
461
|
* @param key - Preference Key
|
|
235
462
|
* @param value - 要写入的值
|
|
236
463
|
* @returns HaiResult
|
|
237
|
-
*
|
|
238
464
|
* @example
|
|
239
465
|
* ```ts
|
|
240
|
-
*
|
|
466
|
+
* import { capacitor } from '@h-ai/capacitor'
|
|
467
|
+
*
|
|
468
|
+
* const initialized = await capacitor.init()
|
|
469
|
+
* if (!initialized.success) throw new Error(initialized.error.message)
|
|
470
|
+
* try {
|
|
471
|
+
* const result = await capacitor.preferences.set('theme', 'dark')
|
|
472
|
+
* if (!result.success) throw new Error(result.error.message)
|
|
473
|
+
* void result.data
|
|
474
|
+
* } finally {
|
|
475
|
+
* const closed = await capacitor.close()
|
|
476
|
+
* if (!closed.success) throw new Error(closed.error.message)
|
|
477
|
+
* }
|
|
241
478
|
* ```
|
|
242
479
|
*/
|
|
243
480
|
declare function safeSetPreference(key: string, value: string): Promise<HaiResult<void>>;
|
|
@@ -246,12 +483,22 @@ declare function safeSetPreference(key: string, value: string): Promise<HaiResul
|
|
|
246
483
|
*
|
|
247
484
|
* @param key - Preference Key
|
|
248
485
|
* @returns HaiResult
|
|
249
|
-
*
|
|
250
486
|
* @example
|
|
251
487
|
* ```ts
|
|
252
|
-
*
|
|
488
|
+
* import { capacitor } from '@h-ai/capacitor'
|
|
489
|
+
*
|
|
490
|
+
* const initialized = await capacitor.init()
|
|
491
|
+
* if (!initialized.success) throw new Error(initialized.error.message)
|
|
492
|
+
* try {
|
|
493
|
+
* const result = await capacitor.preferences.remove('theme')
|
|
494
|
+
* if (!result.success) throw new Error(result.error.message)
|
|
495
|
+
* void result.data
|
|
496
|
+
* } finally {
|
|
497
|
+
* const closed = await capacitor.close()
|
|
498
|
+
* if (!closed.success) throw new Error(closed.error.message)
|
|
499
|
+
* }
|
|
253
500
|
* ```
|
|
254
501
|
*/
|
|
255
502
|
declare function safeRemovePreference(key: string): Promise<HaiResult<void>>;
|
|
256
503
|
|
|
257
|
-
export { type CameraOperations, type CapacitorFunctions, type DeviceInfo, type DeviceOperations, type DevicePlatform, HaiCapacitorError, type PhotoOptions, type PhotoResult, type PhotoSource, type PreferencesOperations, type PushNotification, type PushNotificationCallbacks, type PushOperations, type PushRegistration, type StatusBarConfig, type StatusBarOperations, type StatusBarStyle, capacitor, createCapacitorTokenStorage, safeGetPreference, safeRemovePreference, safeSetPreference };
|
|
504
|
+
export { type CameraOperations, type CapacitorFunctions, type DeviceInfo, type DeviceOperations, type DevicePlatform, HaiCapacitorError, type PhotoOptions, type PhotoResult, type PhotoSource, type PreferencesOperations, type PushCleanup, type PushNotification, type PushNotificationCallbacks, type PushOperations, type PushOptions, type PushRegistration, type StatusBarConfig, type StatusBarOperations, type StatusBarStyle, capacitor, createCapacitorTokenStorage, safeGetPreference, safeRemovePreference, safeSetPreference };
|