ota-native-bridge 1.2.0
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 +76 -0
- package/dist/cjs/crypto-ns.js +9 -0
- package/dist/cjs/crypto.js +96 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/native-messenger.js +23 -0
- package/dist/cjs/native.js +87 -0
- package/dist/cjs/plugins.js +325 -0
- package/dist/cjs/runtime.js +101 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.js +7 -0
- package/dist/crypto-ns.d.ts +6 -0
- package/dist/crypto-ns.js +6 -0
- package/dist/crypto.d.ts +26 -0
- package/dist/crypto.js +92 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/native-messenger.d.ts +6 -0
- package/dist/native-messenger.js +19 -0
- package/dist/native.d.ts +418 -0
- package/dist/native.js +54 -0
- package/dist/plugins.d.ts +209 -0
- package/dist/plugins.js +322 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/runtime.js +92 -0
- package/dist/types.d.ts +609 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +4 -0
- package/docs/USAGE.md +1486 -0
- package/ota-native-bridge.d.ts +10 -0
- package/ota-native-bridge.js +399 -0
- package/package.json +75 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { type NativeCallback } from './runtime';
|
|
2
|
+
import type { AppChannelCodes, AppIconState, AppIconsResult, AppInfo, AppInstalledResult, AppUpdateTriggerResult, ApkUpdateResult, CheckAppUpdateOptions, CheckAppsInstalledResult, DeviceInfo, InstallAppPackageOptions, InstallAppPackageResult, InstallResourcePackageOptions, InstallResourcePackageResult, LaunchAppOptions, LaunchAppResult, LocationPermissionResult, LocationResult, LocationStatus, LocationWatchResult, LockStatus, NativeFeatureConfig, NotificationOptions, OpenInBrowserOptions, OpenInBrowserResult, OrientationInfo, PlayVideoOptions, PlayVideoResult, HttpRequestOptions, HttpRequestResult, ResourceUpdateResult, SafeAreaInsets, ScreenInfo, SetAppIconOptions, SetAppIconResult, SetAppThemeOptions, SetNativeFeaturesOptions, SystemInfo, ThemeConfig, VideoPlayerStatus, WindowInfo, AdapterState, BiometricStatus, BrightnessState, CalendarEventOptions, CaptureResult, ClipboardResult, ContactResult, FlashlightState, MotionReading, NativeOk, PaymentOptions, PaymentResult, PedometerResult, PickerResult, PushTokenResult, RecorderResult, ReviewResult, ScanResult, ShareOptions, VolumeState } from './types';
|
|
3
|
+
export declare const App: {
|
|
4
|
+
ping(callback?: NativeCallback<{
|
|
5
|
+
pong: boolean;
|
|
6
|
+
ts: number;
|
|
7
|
+
}>): Promise<{
|
|
8
|
+
pong: boolean;
|
|
9
|
+
ts: number;
|
|
10
|
+
}>;
|
|
11
|
+
getInfo(callback?: NativeCallback<AppInfo>): Promise<AppInfo>;
|
|
12
|
+
/** 读取打包写入的前端渠道码 / 统计渠道码 / 广告码 */
|
|
13
|
+
getChannelCodes(callback?: NativeCallback<AppChannelCodes>): Promise<AppChannelCodes>;
|
|
14
|
+
launch(options: LaunchAppOptions, callback?: NativeCallback<LaunchAppResult>): Promise<LaunchAppResult>;
|
|
15
|
+
isInstalled(packageName: string, callback?: NativeCallback<AppInstalledResult>): Promise<AppInstalledResult>;
|
|
16
|
+
checkInstalled(packageNames: string[], callback?: NativeCallback<CheckAppsInstalledResult>): Promise<CheckAppsInstalledResult>;
|
|
17
|
+
};
|
|
18
|
+
export declare const Device: {
|
|
19
|
+
getInfo(callback?: NativeCallback<DeviceInfo>): Promise<DeviceInfo>;
|
|
20
|
+
getScreenInfo(callback?: NativeCallback<ScreenInfo>): Promise<ScreenInfo>;
|
|
21
|
+
getOrientation(callback?: NativeCallback<OrientationInfo>): Promise<OrientationInfo>;
|
|
22
|
+
getLockStatus(callback?: NativeCallback<LockStatus>): Promise<LockStatus>;
|
|
23
|
+
getSystemInfo(callback?: NativeCallback<SystemInfo>): Promise<SystemInfo>;
|
|
24
|
+
};
|
|
25
|
+
export declare const Config: {
|
|
26
|
+
getNativeConfig(callback?: NativeCallback<NativeFeatureConfig>): Promise<NativeFeatureConfig>;
|
|
27
|
+
setNativeFeatures(options: SetNativeFeaturesOptions, callback?: NativeCallback<NativeFeatureConfig>): Promise<NativeFeatureConfig>;
|
|
28
|
+
};
|
|
29
|
+
export declare const Theme: {
|
|
30
|
+
get(callback?: NativeCallback<ThemeConfig>): Promise<ThemeConfig>;
|
|
31
|
+
set(options: SetAppThemeOptions, callback?: NativeCallback<ThemeConfig>): Promise<ThemeConfig>;
|
|
32
|
+
};
|
|
33
|
+
export declare const Icon: {
|
|
34
|
+
list(callback?: NativeCallback<AppIconsResult>): Promise<AppIconsResult>;
|
|
35
|
+
get(callback?: NativeCallback<AppIconState>): Promise<AppIconState>;
|
|
36
|
+
set(options: SetAppIconOptions, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
37
|
+
setFromUrl(options: {
|
|
38
|
+
url: string;
|
|
39
|
+
}, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
40
|
+
setFromBase64(options: {
|
|
41
|
+
data?: string;
|
|
42
|
+
base64?: string;
|
|
43
|
+
}, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
44
|
+
};
|
|
45
|
+
export declare const Viewport: {
|
|
46
|
+
getSafeAreaInsets(callback?: NativeCallback<SafeAreaInsets>): Promise<SafeAreaInsets>;
|
|
47
|
+
getWindowInfo(callback?: NativeCallback<WindowInfo>): Promise<WindowInfo>;
|
|
48
|
+
refreshSafeArea(callback?: NativeCallback<{
|
|
49
|
+
success: boolean;
|
|
50
|
+
}>): Promise<{
|
|
51
|
+
success: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
export declare const Notification: {
|
|
55
|
+
show(options: NotificationOptions, callback?: NativeCallback<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
}>): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
setBadgeCount(count: number, callback?: NativeCallback<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
}>): Promise<{
|
|
63
|
+
success: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
export declare const Ota: {
|
|
67
|
+
checkResourceUpdate(url?: string, callback?: NativeCallback<ResourceUpdateResult>): Promise<ResourceUpdateResult>;
|
|
68
|
+
applyResourceUpdate(url: string, callback?: NativeCallback<{
|
|
69
|
+
success: boolean;
|
|
70
|
+
}>): Promise<{
|
|
71
|
+
success: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
installResourcePackage(options: InstallResourcePackageOptions, callback?: NativeCallback<InstallResourcePackageResult>): Promise<InstallResourcePackageResult>;
|
|
74
|
+
checkApkUpdate(url?: string, callback?: NativeCallback<ApkUpdateResult>): Promise<ApkUpdateResult>;
|
|
75
|
+
installAppPackage(options: InstallAppPackageOptions, callback?: NativeCallback<InstallAppPackageResult>): Promise<InstallAppPackageResult>;
|
|
76
|
+
checkUpdate(uidOrOptions?: string | CheckAppUpdateOptions, callback?: NativeCallback<AppUpdateTriggerResult>): Promise<AppUpdateTriggerResult>;
|
|
77
|
+
/** 检查更新(推荐):传用户 ID 时会自动 setUid 再检测,一行搞定 */
|
|
78
|
+
check(uid?: string, callback?: NativeCallback<AppUpdateTriggerResult>): Promise<AppUpdateTriggerResult>;
|
|
79
|
+
setUid(uid: string, callback?: NativeCallback<{
|
|
80
|
+
success: boolean;
|
|
81
|
+
uid: string;
|
|
82
|
+
}>): Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
uid: string;
|
|
85
|
+
}>;
|
|
86
|
+
setChannel(channel: string, callback?: NativeCallback<{
|
|
87
|
+
success: boolean;
|
|
88
|
+
channel: string;
|
|
89
|
+
}>): Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
channel: string;
|
|
92
|
+
}>;
|
|
93
|
+
/** 等同 `installAppPackage({ url })`,兼容旧方法名 */
|
|
94
|
+
downloadAndInstallApk(url: string, callback?: NativeCallback<InstallAppPackageResult>): Promise<InstallAppPackageResult>;
|
|
95
|
+
};
|
|
96
|
+
export declare const Browser: {
|
|
97
|
+
/** 打开系统浏览器。可直接传 URL 字符串:`Browser.open('https://example.com')` */
|
|
98
|
+
open(urlOrOptions: string | OpenInBrowserOptions, callback?: NativeCallback<OpenInBrowserResult>): Promise<OpenInBrowserResult>;
|
|
99
|
+
};
|
|
100
|
+
export declare const Location: {
|
|
101
|
+
getStatus(callback?: NativeCallback<LocationStatus>): Promise<LocationStatus>;
|
|
102
|
+
requestPermission(callback?: NativeCallback<LocationPermissionResult>): Promise<LocationPermissionResult>;
|
|
103
|
+
getCurrent(options?: {
|
|
104
|
+
highAccuracy?: boolean;
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
}, callback?: NativeCallback<LocationResult>): Promise<LocationResult>;
|
|
107
|
+
startWatch(options?: {
|
|
108
|
+
watchId?: string;
|
|
109
|
+
intervalMs?: number;
|
|
110
|
+
highAccuracy?: boolean;
|
|
111
|
+
}, callback?: NativeCallback<LocationWatchResult>): Promise<LocationWatchResult>;
|
|
112
|
+
stopWatch(watchId: string, callback?: NativeCallback<{
|
|
113
|
+
success: boolean;
|
|
114
|
+
watchId: string;
|
|
115
|
+
stopped?: boolean;
|
|
116
|
+
}>): Promise<{
|
|
117
|
+
success: boolean;
|
|
118
|
+
watchId: string;
|
|
119
|
+
stopped?: boolean;
|
|
120
|
+
}>;
|
|
121
|
+
};
|
|
122
|
+
export declare const Media: {
|
|
123
|
+
getVideoPlayerStatus(callback?: NativeCallback<VideoPlayerStatus>): Promise<VideoPlayerStatus>;
|
|
124
|
+
playVideo(options: PlayVideoOptions, callback?: NativeCallback<PlayVideoResult>): Promise<PlayVideoResult>;
|
|
125
|
+
};
|
|
126
|
+
export declare const Http: {
|
|
127
|
+
/**
|
|
128
|
+
* 原生 OkHttp 请求。Android 8–9 系统 WebView 跨域 XHR 常失败时使用。
|
|
129
|
+
* GET/HEAD 不要带 JSON Content-Type。
|
|
130
|
+
*/
|
|
131
|
+
request(options: HttpRequestOptions, callback?: NativeCallback<HttpRequestResult>): Promise<HttpRequestResult>;
|
|
132
|
+
};
|
|
133
|
+
export declare const Clipboard: {
|
|
134
|
+
get(callback?: NativeCallback<ClipboardResult>): Promise<ClipboardResult>;
|
|
135
|
+
set(text: string, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
136
|
+
};
|
|
137
|
+
export declare const Share: {
|
|
138
|
+
open(options: ShareOptions, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
139
|
+
};
|
|
140
|
+
export declare const Picker: {
|
|
141
|
+
chooseImage(callback?: NativeCallback<PickerResult>): Promise<PickerResult>;
|
|
142
|
+
chooseVideo(callback?: NativeCallback<PickerResult>): Promise<PickerResult>;
|
|
143
|
+
chooseFile(callback?: NativeCallback<PickerResult>): Promise<PickerResult>;
|
|
144
|
+
takePhoto(callback?: NativeCallback<PickerResult>): Promise<PickerResult>;
|
|
145
|
+
saveImage(options: {
|
|
146
|
+
url?: string;
|
|
147
|
+
dataUrl?: string;
|
|
148
|
+
base64?: string;
|
|
149
|
+
}, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
150
|
+
};
|
|
151
|
+
export declare const Scan: {
|
|
152
|
+
scan(callback?: NativeCallback<ScanResult>): Promise<ScanResult>;
|
|
153
|
+
};
|
|
154
|
+
export declare const Biometric: {
|
|
155
|
+
status(callback?: NativeCallback<BiometricStatus>): Promise<BiometricStatus>;
|
|
156
|
+
authenticate(options?: {
|
|
157
|
+
title?: string;
|
|
158
|
+
subtitle?: string;
|
|
159
|
+
}, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
160
|
+
};
|
|
161
|
+
export declare const Contacts: {
|
|
162
|
+
pick(callback?: NativeCallback<ContactResult>): Promise<ContactResult>;
|
|
163
|
+
};
|
|
164
|
+
export declare const Calendar: {
|
|
165
|
+
addEvent(options?: CalendarEventOptions, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
166
|
+
};
|
|
167
|
+
export declare const Bluetooth: {
|
|
168
|
+
getState(callback?: NativeCallback<AdapterState>): Promise<AdapterState>;
|
|
169
|
+
};
|
|
170
|
+
export declare const Nfc: {
|
|
171
|
+
getState(callback?: NativeCallback<AdapterState>): Promise<AdapterState>;
|
|
172
|
+
};
|
|
173
|
+
export declare const Sensor: {
|
|
174
|
+
getMotion(callback?: NativeCallback<MotionReading>): Promise<MotionReading>;
|
|
175
|
+
getPedometer(callback?: NativeCallback<PedometerResult>): Promise<PedometerResult>;
|
|
176
|
+
};
|
|
177
|
+
export declare const Haptics: {
|
|
178
|
+
vibrate(ms?: number, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
179
|
+
};
|
|
180
|
+
export declare const Flashlight: {
|
|
181
|
+
get(callback?: NativeCallback<FlashlightState>): Promise<FlashlightState>;
|
|
182
|
+
set(on: boolean, callback?: NativeCallback<FlashlightState>): Promise<FlashlightState>;
|
|
183
|
+
};
|
|
184
|
+
export declare const Brightness: {
|
|
185
|
+
get(callback?: NativeCallback<BrightnessState>): Promise<BrightnessState>;
|
|
186
|
+
set(value: number, callback?: NativeCallback<BrightnessState>): Promise<BrightnessState>;
|
|
187
|
+
};
|
|
188
|
+
export declare const Volume: {
|
|
189
|
+
get(callback?: NativeCallback<VolumeState>): Promise<VolumeState>;
|
|
190
|
+
set(value: number, callback?: NativeCallback<VolumeState>): Promise<VolumeState>;
|
|
191
|
+
};
|
|
192
|
+
export declare const Recorder: {
|
|
193
|
+
start(callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
194
|
+
stop(callback?: NativeCallback<RecorderResult>): Promise<RecorderResult>;
|
|
195
|
+
};
|
|
196
|
+
export declare const Capture: {
|
|
197
|
+
screenshot(callback?: NativeCallback<CaptureResult>): Promise<CaptureResult>;
|
|
198
|
+
startScreenRecord(callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
199
|
+
stopScreenRecord(callback?: NativeCallback<CaptureResult>): Promise<CaptureResult>;
|
|
200
|
+
};
|
|
201
|
+
export declare const Payment: {
|
|
202
|
+
pay(options: PaymentOptions, callback?: NativeCallback<PaymentResult>): Promise<PaymentResult>;
|
|
203
|
+
};
|
|
204
|
+
export declare const Store: {
|
|
205
|
+
requestReview(callback?: NativeCallback<ReviewResult>): Promise<ReviewResult>;
|
|
206
|
+
};
|
|
207
|
+
export declare const Push: {
|
|
208
|
+
getToken(callback?: NativeCallback<PushTokenResult>): Promise<PushTokenResult>;
|
|
209
|
+
};
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { invokeNative, withCallback } from './runtime';
|
|
2
|
+
function asBrowserOptions(urlOrOptions) {
|
|
3
|
+
return typeof urlOrOptions === 'string' ? { url: urlOrOptions } : urlOrOptions;
|
|
4
|
+
}
|
|
5
|
+
function asCheckUpdateOptions(uidOrOptions) {
|
|
6
|
+
if (typeof uidOrOptions === 'string') {
|
|
7
|
+
return { uid: uidOrOptions };
|
|
8
|
+
}
|
|
9
|
+
return uidOrOptions ?? {};
|
|
10
|
+
}
|
|
11
|
+
export const App = {
|
|
12
|
+
ping(callback) {
|
|
13
|
+
return withCallback(invokeNative('ping'), callback);
|
|
14
|
+
},
|
|
15
|
+
getInfo(callback) {
|
|
16
|
+
return withCallback(invokeNative('getAppInfo'), callback);
|
|
17
|
+
},
|
|
18
|
+
/** 读取打包写入的前端渠道码 / 统计渠道码 / 广告码 */
|
|
19
|
+
getChannelCodes(callback) {
|
|
20
|
+
return withCallback(invokeNative('getAppChannelCodes'), callback);
|
|
21
|
+
},
|
|
22
|
+
launch(options, callback) {
|
|
23
|
+
return withCallback(invokeNative('launchApp', { ...options }), callback);
|
|
24
|
+
},
|
|
25
|
+
isInstalled(packageName, callback) {
|
|
26
|
+
return withCallback(invokeNative('isAppInstalled', { packageName }), callback);
|
|
27
|
+
},
|
|
28
|
+
checkInstalled(packageNames, callback) {
|
|
29
|
+
return withCallback(invokeNative('checkAppsInstalled', { packageNames }), callback);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export const Device = {
|
|
33
|
+
getInfo(callback) {
|
|
34
|
+
return withCallback(invokeNative('getDeviceInfo'), callback);
|
|
35
|
+
},
|
|
36
|
+
getScreenInfo(callback) {
|
|
37
|
+
return withCallback(invokeNative('getScreenInfo'), callback);
|
|
38
|
+
},
|
|
39
|
+
getOrientation(callback) {
|
|
40
|
+
return withCallback(invokeNative('getOrientation'), callback);
|
|
41
|
+
},
|
|
42
|
+
getLockStatus(callback) {
|
|
43
|
+
return withCallback(invokeNative('getLockStatus'), callback);
|
|
44
|
+
},
|
|
45
|
+
getSystemInfo(callback) {
|
|
46
|
+
return withCallback(invokeNative('getSystemInfo'), callback);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export const Config = {
|
|
50
|
+
getNativeConfig(callback) {
|
|
51
|
+
return withCallback(invokeNative('getNativeConfig'), callback);
|
|
52
|
+
},
|
|
53
|
+
setNativeFeatures(options, callback) {
|
|
54
|
+
return withCallback(invokeNative('setNativeFeatures', { ...options }), callback);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
export const Theme = {
|
|
58
|
+
get(callback) {
|
|
59
|
+
return withCallback(invokeNative('getAppTheme'), callback);
|
|
60
|
+
},
|
|
61
|
+
set(options, callback) {
|
|
62
|
+
return withCallback(invokeNative('setAppTheme', { ...options }), callback);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
export const Icon = {
|
|
66
|
+
list(callback) {
|
|
67
|
+
return withCallback(invokeNative('getAppIcons'), callback);
|
|
68
|
+
},
|
|
69
|
+
get(callback) {
|
|
70
|
+
return withCallback(invokeNative('getAppIcon'), callback);
|
|
71
|
+
},
|
|
72
|
+
set(options, callback) {
|
|
73
|
+
return withCallback(invokeNative('setAppIcon', { ...options }), callback);
|
|
74
|
+
},
|
|
75
|
+
setFromUrl(options, callback) {
|
|
76
|
+
return withCallback(invokeNative('setAppIconFromUrl', { ...options }), callback);
|
|
77
|
+
},
|
|
78
|
+
setFromBase64(options, callback) {
|
|
79
|
+
return withCallback(invokeNative('setAppIconFromBase64', { ...options }), callback);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const Viewport = {
|
|
83
|
+
getSafeAreaInsets(callback) {
|
|
84
|
+
return withCallback(invokeNative('getSafeAreaInsets'), callback);
|
|
85
|
+
},
|
|
86
|
+
getWindowInfo(callback) {
|
|
87
|
+
return withCallback(invokeNative('getWindowInfo'), callback);
|
|
88
|
+
},
|
|
89
|
+
refreshSafeArea(callback) {
|
|
90
|
+
return withCallback(invokeNative('refreshSafeArea'), callback);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
export const Notification = {
|
|
94
|
+
show(options, callback) {
|
|
95
|
+
return withCallback(invokeNative('showNotification', { ...options }), callback);
|
|
96
|
+
},
|
|
97
|
+
setBadgeCount(count, callback) {
|
|
98
|
+
return withCallback(invokeNative('setBadgeCount', { count }), callback);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
export const Ota = {
|
|
102
|
+
checkResourceUpdate(url, callback) {
|
|
103
|
+
return withCallback(invokeNative('checkResourceUpdate', url ? { url } : {}), callback);
|
|
104
|
+
},
|
|
105
|
+
applyResourceUpdate(url, callback) {
|
|
106
|
+
return withCallback(invokeNative('applyResourceUpdate', { url }), callback);
|
|
107
|
+
},
|
|
108
|
+
installResourcePackage(options, callback) {
|
|
109
|
+
return withCallback(invokeNative('installResourcePackage', { ...options }), callback);
|
|
110
|
+
},
|
|
111
|
+
checkApkUpdate(url, callback) {
|
|
112
|
+
return withCallback(invokeNative('checkApkUpdate', url ? { url } : {}), callback);
|
|
113
|
+
},
|
|
114
|
+
installAppPackage(options, callback) {
|
|
115
|
+
return withCallback(invokeNative('installAppPackage', { ...options }), callback);
|
|
116
|
+
},
|
|
117
|
+
checkUpdate(uidOrOptions, callback) {
|
|
118
|
+
const options = asCheckUpdateOptions(uidOrOptions);
|
|
119
|
+
return withCallback(invokeNative('checkAppUpdate', {
|
|
120
|
+
notifyWhenNoUpdate: options.notifyWhenNoUpdate !== false,
|
|
121
|
+
uid: options.uid ?? '',
|
|
122
|
+
}), callback);
|
|
123
|
+
},
|
|
124
|
+
/** 检查更新(推荐):传用户 ID 时会自动 setUid 再检测,一行搞定 */
|
|
125
|
+
check(uid, callback) {
|
|
126
|
+
if (!uid) {
|
|
127
|
+
return Ota.checkUpdate(undefined, callback);
|
|
128
|
+
}
|
|
129
|
+
return withCallback(invokeNative('setOtaUid', { uid }).then(() => invokeNative('checkAppUpdate', {
|
|
130
|
+
notifyWhenNoUpdate: true,
|
|
131
|
+
uid,
|
|
132
|
+
})), callback);
|
|
133
|
+
},
|
|
134
|
+
setUid(uid, callback) {
|
|
135
|
+
return withCallback(invokeNative('setOtaUid', { uid: uid ?? '' }), callback);
|
|
136
|
+
},
|
|
137
|
+
setChannel(channel, callback) {
|
|
138
|
+
return withCallback(invokeNative('setOtaChannel', { channel: channel ?? '' }), callback);
|
|
139
|
+
},
|
|
140
|
+
/** 等同 `installAppPackage({ url })`,兼容旧方法名 */
|
|
141
|
+
downloadAndInstallApk(url, callback) {
|
|
142
|
+
return withCallback(invokeNative('downloadAndInstallApk', { url }), callback);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
export const Browser = {
|
|
146
|
+
/** 打开系统浏览器。可直接传 URL 字符串:`Browser.open('https://example.com')` */
|
|
147
|
+
open(urlOrOptions, callback) {
|
|
148
|
+
const options = asBrowserOptions(urlOrOptions);
|
|
149
|
+
return withCallback(invokeNative('openInBrowser', {
|
|
150
|
+
url: options.url,
|
|
151
|
+
uri: options.uri,
|
|
152
|
+
}), callback);
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
export const Location = {
|
|
156
|
+
getStatus(callback) {
|
|
157
|
+
return withCallback(invokeNative('getLocationStatus'), callback);
|
|
158
|
+
},
|
|
159
|
+
requestPermission(callback) {
|
|
160
|
+
return withCallback(invokeNative('requestLocationPermission'), callback);
|
|
161
|
+
},
|
|
162
|
+
getCurrent(options, callback) {
|
|
163
|
+
return withCallback(invokeNative('getCurrentLocation', { ...(options ?? {}) }), callback);
|
|
164
|
+
},
|
|
165
|
+
startWatch(options, callback) {
|
|
166
|
+
return withCallback(invokeNative('startLocationWatch', { ...(options ?? {}) }), callback);
|
|
167
|
+
},
|
|
168
|
+
stopWatch(watchId, callback) {
|
|
169
|
+
return withCallback(invokeNative('stopLocationWatch', { watchId }), callback);
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
export const Media = {
|
|
173
|
+
getVideoPlayerStatus(callback) {
|
|
174
|
+
return withCallback(invokeNative('getVideoPlayerStatus'), callback);
|
|
175
|
+
},
|
|
176
|
+
playVideo(options, callback) {
|
|
177
|
+
return withCallback(invokeNative('playVideo', { ...options }), callback);
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
export const Http = {
|
|
181
|
+
/**
|
|
182
|
+
* 原生 OkHttp 请求。Android 8–9 系统 WebView 跨域 XHR 常失败时使用。
|
|
183
|
+
* GET/HEAD 不要带 JSON Content-Type。
|
|
184
|
+
*/
|
|
185
|
+
request(options, callback) {
|
|
186
|
+
return withCallback(invokeNative('httpRequest', { ...options }), callback);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
export const Clipboard = {
|
|
190
|
+
get(callback) {
|
|
191
|
+
return withCallback(invokeNative('clipboardGet'), callback);
|
|
192
|
+
},
|
|
193
|
+
set(text, callback) {
|
|
194
|
+
return withCallback(invokeNative('clipboardSet', { text: text ?? '' }), callback);
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
export const Share = {
|
|
198
|
+
open(options, callback) {
|
|
199
|
+
return withCallback(invokeNative('share', { ...options }), callback);
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
export const Picker = {
|
|
203
|
+
chooseImage(callback) {
|
|
204
|
+
return withCallback(invokeNative('pickImage'), callback);
|
|
205
|
+
},
|
|
206
|
+
chooseVideo(callback) {
|
|
207
|
+
return withCallback(invokeNative('pickVideo'), callback);
|
|
208
|
+
},
|
|
209
|
+
chooseFile(callback) {
|
|
210
|
+
return withCallback(invokeNative('pickFile'), callback);
|
|
211
|
+
},
|
|
212
|
+
takePhoto(callback) {
|
|
213
|
+
return withCallback(invokeNative('takePhoto'), callback);
|
|
214
|
+
},
|
|
215
|
+
saveImage(options, callback) {
|
|
216
|
+
return withCallback(invokeNative('saveImage', { ...options }), callback);
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
export const Scan = {
|
|
220
|
+
scan(callback) {
|
|
221
|
+
return withCallback(invokeNative('scanCode'), callback);
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
export const Biometric = {
|
|
225
|
+
status(callback) {
|
|
226
|
+
return withCallback(invokeNative('biometricStatus'), callback);
|
|
227
|
+
},
|
|
228
|
+
authenticate(options, callback) {
|
|
229
|
+
return withCallback(invokeNative('biometricAuth', { ...(options ?? {}) }), callback);
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
export const Contacts = {
|
|
233
|
+
pick(callback) {
|
|
234
|
+
return withCallback(invokeNative('pickContact'), callback);
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
export const Calendar = {
|
|
238
|
+
addEvent(options, callback) {
|
|
239
|
+
return withCallback(invokeNative('addCalendarEvent', { ...(options ?? {}) }), callback);
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
export const Bluetooth = {
|
|
243
|
+
getState(callback) {
|
|
244
|
+
return withCallback(invokeNative('bluetoothState'), callback);
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
export const Nfc = {
|
|
248
|
+
getState(callback) {
|
|
249
|
+
return withCallback(invokeNative('nfcState'), callback);
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
export const Sensor = {
|
|
253
|
+
getMotion(callback) {
|
|
254
|
+
return withCallback(invokeNative('sensorMotion'), callback);
|
|
255
|
+
},
|
|
256
|
+
getPedometer(callback) {
|
|
257
|
+
return withCallback(invokeNative('pedometer'), callback);
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
export const Haptics = {
|
|
261
|
+
vibrate(ms, callback) {
|
|
262
|
+
return withCallback(invokeNative('vibrate', { ms: ms ?? 200 }), callback);
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
export const Flashlight = {
|
|
266
|
+
get(callback) {
|
|
267
|
+
return withCallback(invokeNative('flashlightGet'), callback);
|
|
268
|
+
},
|
|
269
|
+
set(on, callback) {
|
|
270
|
+
return withCallback(invokeNative('flashlightSet', { on: !!on }), callback);
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
export const Brightness = {
|
|
274
|
+
get(callback) {
|
|
275
|
+
return withCallback(invokeNative('brightnessGet'), callback);
|
|
276
|
+
},
|
|
277
|
+
set(value, callback) {
|
|
278
|
+
return withCallback(invokeNative('brightnessSet', { value }), callback);
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
export const Volume = {
|
|
282
|
+
get(callback) {
|
|
283
|
+
return withCallback(invokeNative('volumeGet'), callback);
|
|
284
|
+
},
|
|
285
|
+
set(value, callback) {
|
|
286
|
+
return withCallback(invokeNative('volumeSet', { value }), callback);
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
export const Recorder = {
|
|
290
|
+
start(callback) {
|
|
291
|
+
return withCallback(invokeNative('recorderStart'), callback);
|
|
292
|
+
},
|
|
293
|
+
stop(callback) {
|
|
294
|
+
return withCallback(invokeNative('recorderStop'), callback);
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
export const Capture = {
|
|
298
|
+
screenshot(callback) {
|
|
299
|
+
return withCallback(invokeNative('screenshot'), callback);
|
|
300
|
+
},
|
|
301
|
+
startScreenRecord(callback) {
|
|
302
|
+
return withCallback(invokeNative('screenRecordStart'), callback);
|
|
303
|
+
},
|
|
304
|
+
stopScreenRecord(callback) {
|
|
305
|
+
return withCallback(invokeNative('screenRecordStop'), callback);
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
export const Payment = {
|
|
309
|
+
pay(options, callback) {
|
|
310
|
+
return withCallback(invokeNative('paymentPay', { ...options }), callback);
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
export const Store = {
|
|
314
|
+
requestReview(callback) {
|
|
315
|
+
return withCallback(invokeNative('storeReview'), callback);
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
export const Push = {
|
|
319
|
+
getToken(callback) {
|
|
320
|
+
return withCallback(invokeNative('pushToken'), callback);
|
|
321
|
+
},
|
|
322
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isNativeBridgeAvailable } from './native-messenger';
|
|
2
|
+
export type NativePlatform = 'android' | 'ios' | 'harmony' | 'web';
|
|
3
|
+
export type NativeCallback<T> = (result: T, error?: Error) => void;
|
|
4
|
+
export declare function callNative<T>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
5
|
+
export declare function getPlatform(): NativePlatform;
|
|
6
|
+
export declare function isNativePlatform(): boolean;
|
|
7
|
+
export { isNativeBridgeAvailable };
|
|
8
|
+
export declare function whenReady(timeoutMs?: number): Promise<void>;
|
|
9
|
+
export declare function invokeNative<T>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
10
|
+
export declare function withCallback<T>(promise: Promise<T>, callback?: NativeCallback<T>): Promise<T>;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getNativePostMessage, isNativeBridgeAvailable } from './native-messenger';
|
|
2
|
+
const BRIDGE_READY_EVENT = 'nativebridgeready';
|
|
3
|
+
let seq = 0;
|
|
4
|
+
const pending = {};
|
|
5
|
+
let readyPromise = null;
|
|
6
|
+
function installNativeCallback() {
|
|
7
|
+
if (typeof window === 'undefined' || window.__nativeBridgeCallback) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
window.__nativeBridgeCallback = (id, success, payload) => {
|
|
11
|
+
const item = pending[id];
|
|
12
|
+
if (!item) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
delete pending[id];
|
|
16
|
+
const data = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
|
17
|
+
if (success) {
|
|
18
|
+
item.resolve(data);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
item.reject(new Error(String(data)));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function callNative(method, params) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const post = getNativePostMessage();
|
|
28
|
+
if (!post) {
|
|
29
|
+
reject(new Error('Native bridge not available (AndroidBridge / IOSBridge / HarmonyBridge)'));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
installNativeCallback();
|
|
33
|
+
const id = `cb_${++seq}`;
|
|
34
|
+
pending[id] = {
|
|
35
|
+
resolve: resolve,
|
|
36
|
+
reject,
|
|
37
|
+
};
|
|
38
|
+
post(JSON.stringify({ id, method, params: params ?? {} }));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function getPlatform() {
|
|
42
|
+
if (typeof window === 'undefined') {
|
|
43
|
+
return 'web';
|
|
44
|
+
}
|
|
45
|
+
if (window.AndroidBridge?.postMessage) {
|
|
46
|
+
return 'android';
|
|
47
|
+
}
|
|
48
|
+
if (window.webkit?.messageHandlers?.IOSBridge?.postMessage) {
|
|
49
|
+
return 'ios';
|
|
50
|
+
}
|
|
51
|
+
if (window.HarmonyBridge?.postMessage) {
|
|
52
|
+
return 'harmony';
|
|
53
|
+
}
|
|
54
|
+
return 'web';
|
|
55
|
+
}
|
|
56
|
+
export function isNativePlatform() {
|
|
57
|
+
return getPlatform() !== 'web';
|
|
58
|
+
}
|
|
59
|
+
export { isNativeBridgeAvailable };
|
|
60
|
+
export function whenReady(timeoutMs = 8000) {
|
|
61
|
+
if (typeof window === 'undefined') {
|
|
62
|
+
return Promise.reject(new Error('Not in browser'));
|
|
63
|
+
}
|
|
64
|
+
if (getNativePostMessage()) {
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
if (!readyPromise) {
|
|
68
|
+
readyPromise = new Promise((resolve, reject) => {
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
readyPromise = null;
|
|
71
|
+
reject(new Error('Bridge timeout'));
|
|
72
|
+
}, timeoutMs);
|
|
73
|
+
const onReady = () => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
resolve();
|
|
76
|
+
};
|
|
77
|
+
document.addEventListener(BRIDGE_READY_EVENT, onReady, { once: true });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return readyPromise;
|
|
81
|
+
}
|
|
82
|
+
export function invokeNative(method, params) {
|
|
83
|
+
return whenReady().then(() => callNative(method, params));
|
|
84
|
+
}
|
|
85
|
+
export function withCallback(promise, callback) {
|
|
86
|
+
if (typeof callback === 'function') {
|
|
87
|
+
promise
|
|
88
|
+
.then((result) => callback(result))
|
|
89
|
+
.catch((error) => callback(undefined, error instanceof Error ? error : new Error(String(error))));
|
|
90
|
+
}
|
|
91
|
+
return promise;
|
|
92
|
+
}
|