ota-native-bridge 1.7.0 → 1.8.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/dist/cjs/events.js +24 -0
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/native.js +6 -1
- package/dist/cjs/plugins.js +49 -1
- package/dist/cjs/version.js +1 -1
- package/dist/events.d.ts +9 -0
- package/dist/events.js +21 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/native.d.ts +24 -3
- package/dist/native.js +6 -2
- package/dist/plugins.d.ts +31 -1
- package/dist/plugins.js +48 -0
- package/dist/types.d.ts +93 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/USAGE.md +75 -2
- package/ota-native-bridge.js +29 -3
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onNativeEvent = onNativeEvent;
|
|
4
|
+
const NATIVE_EVENT = 'nativebridgeevent';
|
|
5
|
+
function onNativeEvent(name, handler) {
|
|
6
|
+
if (typeof window === 'undefined') {
|
|
7
|
+
return () => undefined;
|
|
8
|
+
}
|
|
9
|
+
const listener = (e) => {
|
|
10
|
+
const detail = e.detail;
|
|
11
|
+
if (!detail || detail.name !== name) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
handler(detail.payload);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// 业务回调异常不要影响后续事件
|
|
19
|
+
console.error('[ota-native-bridge] event handler failed', error);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener(NATIVE_EVENT, listener);
|
|
23
|
+
return () => window.removeEventListener(NATIVE_EVENT, listener);
|
|
24
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Crypto = exports.postEncrypted = exports.encryptRequestBody = exports.isNativeBridgeAvailable = exports.getNativePostMessage = exports.decodeBridgePayload = exports.invokeNative = exports.isNativePlatform = exports.getPlatform = exports.whenReady = exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.Browser = exports.Ota = exports.App = exports.Native = exports.SDK_VERSION = exports.PACKAGE_NAME = void 0;
|
|
17
|
+
exports.Crypto = exports.postEncrypted = exports.encryptRequestBody = exports.isNativeBridgeAvailable = exports.getNativePostMessage = exports.decodeBridgePayload = exports.invokeNative = exports.isNativePlatform = exports.getPlatform = exports.whenReady = exports.onNativeEvent = exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.Browser = exports.Migration = exports.Ota = exports.App = exports.Native = exports.SDK_VERSION = exports.PACKAGE_NAME = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
19
|
var version_1 = require("./version");
|
|
20
20
|
Object.defineProperty(exports, "PACKAGE_NAME", { enumerable: true, get: function () { return version_1.PACKAGE_NAME; } });
|
|
@@ -23,6 +23,7 @@ var native_1 = require("./native");
|
|
|
23
23
|
Object.defineProperty(exports, "Native", { enumerable: true, get: function () { return native_1.Native; } });
|
|
24
24
|
Object.defineProperty(exports, "App", { enumerable: true, get: function () { return native_1.App; } });
|
|
25
25
|
Object.defineProperty(exports, "Ota", { enumerable: true, get: function () { return native_1.Ota; } });
|
|
26
|
+
Object.defineProperty(exports, "Migration", { enumerable: true, get: function () { return native_1.Migration; } });
|
|
26
27
|
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return native_1.Browser; } });
|
|
27
28
|
Object.defineProperty(exports, "Device", { enumerable: true, get: function () { return native_1.Device; } });
|
|
28
29
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return native_1.Config; } });
|
|
@@ -52,6 +53,8 @@ Object.defineProperty(exports, "Capture", { enumerable: true, get: function () {
|
|
|
52
53
|
Object.defineProperty(exports, "Payment", { enumerable: true, get: function () { return native_1.Payment; } });
|
|
53
54
|
Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return native_1.Store; } });
|
|
54
55
|
Object.defineProperty(exports, "Push", { enumerable: true, get: function () { return native_1.Push; } });
|
|
56
|
+
var events_1 = require("./events");
|
|
57
|
+
Object.defineProperty(exports, "onNativeEvent", { enumerable: true, get: function () { return events_1.onNativeEvent; } });
|
|
55
58
|
var runtime_1 = require("./runtime");
|
|
56
59
|
Object.defineProperty(exports, "whenReady", { enumerable: true, get: function () { return runtime_1.whenReady; } });
|
|
57
60
|
Object.defineProperty(exports, "getPlatform", { enumerable: true, get: function () { return runtime_1.getPlatform; } });
|
package/dist/cjs/native.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Crypto = exports.Volume = exports.Viewport = exports.Theme = exports.Store = exports.Share = exports.Sensor = exports.Scan = exports.Recorder = exports.Push = exports.Picker = exports.Payment = exports.Ota = exports.Notification = exports.Nfc = exports.Media = exports.Location = exports.Icon = exports.Http = exports.Haptics = exports.Flashlight = exports.Device = exports.Contacts = exports.Config = exports.Clipboard = exports.Capture = exports.Calendar = exports.Browser = exports.Brightness = exports.Bluetooth = exports.Biometric = exports.App = exports.Native = void 0;
|
|
3
|
+
exports.Crypto = exports.Volume = exports.Viewport = exports.Theme = exports.Store = exports.Share = exports.Sensor = exports.Scan = exports.Recorder = exports.Push = exports.Picker = exports.Payment = exports.Ota = exports.Notification = exports.Nfc = exports.Migration = exports.Media = exports.Location = exports.Icon = exports.Http = exports.Haptics = exports.Flashlight = exports.Device = exports.Contacts = exports.Config = exports.Clipboard = exports.Capture = exports.Calendar = exports.Browser = exports.Brightness = exports.Bluetooth = exports.Biometric = exports.App = exports.Native = void 0;
|
|
4
4
|
const crypto_ns_1 = require("./crypto-ns");
|
|
5
5
|
Object.defineProperty(exports, "Crypto", { enumerable: true, get: function () { return crypto_ns_1.Crypto; } });
|
|
6
6
|
const plugins_1 = require("./plugins");
|
|
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "Http", { enumerable: true, get: function () { re
|
|
|
21
21
|
Object.defineProperty(exports, "Icon", { enumerable: true, get: function () { return plugins_1.Icon; } });
|
|
22
22
|
Object.defineProperty(exports, "Location", { enumerable: true, get: function () { return plugins_1.Location; } });
|
|
23
23
|
Object.defineProperty(exports, "Media", { enumerable: true, get: function () { return plugins_1.Media; } });
|
|
24
|
+
Object.defineProperty(exports, "Migration", { enumerable: true, get: function () { return plugins_1.Migration; } });
|
|
24
25
|
Object.defineProperty(exports, "Nfc", { enumerable: true, get: function () { return plugins_1.Nfc; } });
|
|
25
26
|
Object.defineProperty(exports, "Notification", { enumerable: true, get: function () { return plugins_1.Notification; } });
|
|
26
27
|
Object.defineProperty(exports, "Ota", { enumerable: true, get: function () { return plugins_1.Ota; } });
|
|
@@ -35,11 +36,13 @@ Object.defineProperty(exports, "Store", { enumerable: true, get: function () { r
|
|
|
35
36
|
Object.defineProperty(exports, "Theme", { enumerable: true, get: function () { return plugins_1.Theme; } });
|
|
36
37
|
Object.defineProperty(exports, "Viewport", { enumerable: true, get: function () { return plugins_1.Viewport; } });
|
|
37
38
|
Object.defineProperty(exports, "Volume", { enumerable: true, get: function () { return plugins_1.Volume; } });
|
|
39
|
+
const events_1 = require("./events");
|
|
38
40
|
const runtime_1 = require("./runtime");
|
|
39
41
|
const version_1 = require("./version");
|
|
40
42
|
const plugins = {
|
|
41
43
|
App: plugins_1.App,
|
|
42
44
|
Ota: plugins_1.Ota,
|
|
45
|
+
Migration: plugins_1.Migration,
|
|
43
46
|
Browser: plugins_1.Browser,
|
|
44
47
|
Device: plugins_1.Device,
|
|
45
48
|
Config: plugins_1.Config,
|
|
@@ -77,6 +80,8 @@ exports.Native = {
|
|
|
77
80
|
isNativePlatform: runtime_1.isNativePlatform,
|
|
78
81
|
isNativeBridgeAvailable: runtime_1.isNativeBridgeAvailable,
|
|
79
82
|
whenReady: runtime_1.whenReady,
|
|
83
|
+
/** 订阅壳推送的事件:`Native.on('ota.install', fn)` / `Native.on('migration', fn)`,返回取消订阅函数 */
|
|
84
|
+
on: events_1.onNativeEvent,
|
|
80
85
|
Plugins: plugins,
|
|
81
86
|
...plugins,
|
|
82
87
|
/** H5 自行请求 Client API 时加密请求体(平台公钥来自 App.getInfo().platform.paramPublicKey) */
|
package/dist/cjs/plugins.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Browser = exports.Ota = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.App = void 0;
|
|
3
|
+
exports.Push = exports.Store = exports.Payment = exports.Capture = exports.Recorder = exports.Volume = exports.Brightness = exports.Flashlight = exports.Haptics = exports.Sensor = exports.Nfc = exports.Bluetooth = exports.Calendar = exports.Contacts = exports.Biometric = exports.Scan = exports.Picker = exports.Share = exports.Clipboard = exports.Http = exports.Media = exports.Location = exports.Browser = exports.Migration = exports.Ota = exports.Notification = exports.Viewport = exports.Icon = exports.Theme = exports.Config = exports.Device = exports.App = void 0;
|
|
4
|
+
const events_1 = require("./events");
|
|
4
5
|
const runtime_1 = require("./runtime");
|
|
5
6
|
const webview_signals_1 = require("./webview-signals");
|
|
6
7
|
function toEnvironmentDevice(device, system) {
|
|
@@ -223,6 +224,53 @@ exports.Ota = {
|
|
|
223
224
|
downloadAndInstallApk(url, callback) {
|
|
224
225
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('downloadAndInstallApk', { url }), callback);
|
|
225
226
|
},
|
|
227
|
+
/**
|
|
228
|
+
* 订阅安装包下载与安装进度(Android)。原生更新弹窗和 `installAppPackage` 都会触发。
|
|
229
|
+
* 返回取消订阅函数。
|
|
230
|
+
*/
|
|
231
|
+
onInstallEvent(handler) {
|
|
232
|
+
return (0, events_1.onNativeEvent)('ota.install', handler);
|
|
233
|
+
},
|
|
234
|
+
/** 换包安装的当前阶段(Android)。页面刷新后用它恢复界面状态。 */
|
|
235
|
+
getInstallState(callback) {
|
|
236
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getAppInstallState'), callback);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* 换包更新的数据迁移(Android)。新安装包的包名与当前应用不同时,
|
|
241
|
+
* 装好后当前应用会自动拉起新应用,把登录状态(Cookie / localStorage)、
|
|
242
|
+
* 设备序列号和 `setExtras` 的数据交给它,完成后请求卸载当前应用。
|
|
243
|
+
*/
|
|
244
|
+
exports.Migration = {
|
|
245
|
+
/**
|
|
246
|
+
* 迁移前补充要带走的数据。建议在登录后和每次登录态变化时调用。
|
|
247
|
+
* 新应用通过 `Migration.getInfo().extras` 读取。
|
|
248
|
+
*/
|
|
249
|
+
setExtras(options, callback) {
|
|
250
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('setMigrationExtras', {
|
|
251
|
+
extras: options.extras ?? {},
|
|
252
|
+
cookieUrls: options.cookieUrls ?? [],
|
|
253
|
+
}), callback);
|
|
254
|
+
},
|
|
255
|
+
/** 新应用已装好但没自动打开时(后台启动被系统拦截等),由用户点按钮手动继续 */
|
|
256
|
+
continue(callback) {
|
|
257
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('continueAppMigration'), callback);
|
|
258
|
+
},
|
|
259
|
+
/** 新应用里读取迁移结果 */
|
|
260
|
+
getInfo(callback) {
|
|
261
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getMigrationInfo'), callback);
|
|
262
|
+
},
|
|
263
|
+
/**
|
|
264
|
+
* 请求卸载:`self` 卸载当前应用(需迁移已完成),`source` 在新应用里卸载被迁移的旧应用。
|
|
265
|
+
* 迁移完成后原生会自动请求一次;用户在系统确认框里取消后,可用它再次发起。
|
|
266
|
+
*/
|
|
267
|
+
requestUninstall(target = 'self', callback) {
|
|
268
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('requestUninstall', { target }), callback);
|
|
269
|
+
},
|
|
270
|
+
/** 订阅迁移事件。返回取消订阅函数。 */
|
|
271
|
+
onEvent(handler) {
|
|
272
|
+
return (0, events_1.onNativeEvent)('migration', handler);
|
|
273
|
+
},
|
|
226
274
|
};
|
|
227
275
|
exports.Browser = {
|
|
228
276
|
/** 打开系统浏览器。可直接传 URL 字符串:`Browser.open('https://example.com')` */
|
package/dist/cjs/version.js
CHANGED
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NativeEventMap } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 订阅壳推送的事件(Android:`ota.install` 下载与安装、`migration` 换包数据迁移)。
|
|
4
|
+
* 返回取消订阅函数。非浏览器环境返回空函数。
|
|
5
|
+
*
|
|
6
|
+
* 页面没加载好时发出的事件不会补发;启动时请用 `Ota.getInstallState()` / `Migration.getInfo()` 读取当前状态。
|
|
7
|
+
*/
|
|
8
|
+
export declare function onNativeEvent<K extends keyof NativeEventMap>(name: K, handler: (event: NativeEventMap[K]) => void): () => void;
|
|
9
|
+
export declare function onNativeEvent(name: string, handler: (event: unknown) => void): () => void;
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const NATIVE_EVENT = 'nativebridgeevent';
|
|
2
|
+
export function onNativeEvent(name, handler) {
|
|
3
|
+
if (typeof window === 'undefined') {
|
|
4
|
+
return () => undefined;
|
|
5
|
+
}
|
|
6
|
+
const listener = (e) => {
|
|
7
|
+
const detail = e.detail;
|
|
8
|
+
if (!detail || detail.name !== name) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
handler(detail.payload);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// 业务回调异常不要影响后续事件
|
|
16
|
+
console.error('[ota-native-bridge] event handler failed', error);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
window.addEventListener(NATIVE_EVENT, listener);
|
|
20
|
+
return () => window.removeEventListener(NATIVE_EVENT, listener);
|
|
21
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
|
-
export { Native, App, Ota, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
3
|
+
export { Native, App, Ota, Migration, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
4
|
+
export { onNativeEvent } from './events';
|
|
4
5
|
export type { NativeCallback, NativePlatform } from './runtime';
|
|
5
6
|
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
6
7
|
export { getNativePostMessage, isNativeBridgeAvailable, type NativePostMessage, } from './native-messenger';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
|
-
export { Native, App, Ota, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
3
|
+
export { Native, App, Ota, Migration, Browser, Device, Config, Theme, Icon, Viewport, Notification, Location, Media, Http, Clipboard, Share, Picker, Scan, Biometric, Contacts, Calendar, Bluetooth, Nfc, Sensor, Haptics, Flashlight, Brightness, Volume, Recorder, Capture, Payment, Store, Push, } from './native';
|
|
4
|
+
export { onNativeEvent } from './events';
|
|
4
5
|
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
5
6
|
export { getNativePostMessage, isNativeBridgeAvailable, } from './native-messenger';
|
|
6
7
|
export { encryptRequestBody, postEncrypted, } from './crypto';
|
package/dist/native.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Crypto } from './crypto-ns';
|
|
2
|
-
import { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume } from './plugins';
|
|
2
|
+
import { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Migration, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume } from './plugins';
|
|
3
|
+
import { onNativeEvent } from './events';
|
|
3
4
|
import { getPlatform, isNativeBridgeAvailable, isNativePlatform, whenReady } from './runtime';
|
|
4
5
|
/** 插件式 Native SDK:直接调用即可,首次会自动等待壳注入完成 */
|
|
5
6
|
export declare const Native: {
|
|
@@ -49,6 +50,15 @@ export declare const Native: {
|
|
|
49
50
|
channel: string;
|
|
50
51
|
}>;
|
|
51
52
|
downloadAndInstallApk(url: string, callback?: import("./runtime").NativeCallback<import("./types").InstallAppPackageResult>): Promise<import("./types").InstallAppPackageResult>;
|
|
53
|
+
onInstallEvent(handler: (event: import("./types").OtaInstallEvent) => void): () => void;
|
|
54
|
+
getInstallState(callback?: import("./runtime").NativeCallback<import("./types").AppInstallState>): Promise<import("./types").AppInstallState>;
|
|
55
|
+
};
|
|
56
|
+
readonly Migration: {
|
|
57
|
+
setExtras(options: import("./types").MigrationExtrasOptions, callback?: import("./runtime").NativeCallback<import("./types").NativeOk>): Promise<import("./types").NativeOk>;
|
|
58
|
+
continue(callback?: import("./runtime").NativeCallback<import("./types").AppInstallState>): Promise<import("./types").AppInstallState>;
|
|
59
|
+
getInfo(callback?: import("./runtime").NativeCallback<import("./types").MigrationInfo>): Promise<import("./types").MigrationInfo>;
|
|
60
|
+
requestUninstall(target?: import("./types").MigrationUninstallTarget, callback?: import("./runtime").NativeCallback<import("./types").MigrationUninstallResult>): Promise<import("./types").MigrationUninstallResult>;
|
|
61
|
+
onEvent(handler: (event: import("./types").MigrationEvent) => void): () => void;
|
|
52
62
|
};
|
|
53
63
|
readonly Browser: {
|
|
54
64
|
open(urlOrOptions: string | import("./types").OpenInBrowserOptions, callback?: import("./runtime").NativeCallback<import("./types").OpenInBrowserResult>): Promise<import("./types").OpenInBrowserResult>;
|
|
@@ -225,11 +235,13 @@ export declare const Native: {
|
|
|
225
235
|
readonly Push: {
|
|
226
236
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
227
237
|
};
|
|
228
|
-
readonly sdkVersion: "1.
|
|
238
|
+
readonly sdkVersion: "1.8.0";
|
|
229
239
|
readonly getPlatform: typeof getPlatform;
|
|
230
240
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
231
241
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
|
232
242
|
readonly whenReady: typeof whenReady;
|
|
243
|
+
/** 订阅壳推送的事件:`Native.on('ota.install', fn)` / `Native.on('migration', fn)`,返回取消订阅函数 */
|
|
244
|
+
readonly on: typeof onNativeEvent;
|
|
233
245
|
readonly Plugins: {
|
|
234
246
|
readonly App: {
|
|
235
247
|
ping(callback?: import("./runtime").NativeCallback<{
|
|
@@ -272,6 +284,15 @@ export declare const Native: {
|
|
|
272
284
|
channel: string;
|
|
273
285
|
}>;
|
|
274
286
|
downloadAndInstallApk(url: string, callback?: import("./runtime").NativeCallback<import("./types").InstallAppPackageResult>): Promise<import("./types").InstallAppPackageResult>;
|
|
287
|
+
onInstallEvent(handler: (event: import("./types").OtaInstallEvent) => void): () => void;
|
|
288
|
+
getInstallState(callback?: import("./runtime").NativeCallback<import("./types").AppInstallState>): Promise<import("./types").AppInstallState>;
|
|
289
|
+
};
|
|
290
|
+
readonly Migration: {
|
|
291
|
+
setExtras(options: import("./types").MigrationExtrasOptions, callback?: import("./runtime").NativeCallback<import("./types").NativeOk>): Promise<import("./types").NativeOk>;
|
|
292
|
+
continue(callback?: import("./runtime").NativeCallback<import("./types").AppInstallState>): Promise<import("./types").AppInstallState>;
|
|
293
|
+
getInfo(callback?: import("./runtime").NativeCallback<import("./types").MigrationInfo>): Promise<import("./types").MigrationInfo>;
|
|
294
|
+
requestUninstall(target?: import("./types").MigrationUninstallTarget, callback?: import("./runtime").NativeCallback<import("./types").MigrationUninstallResult>): Promise<import("./types").MigrationUninstallResult>;
|
|
295
|
+
onEvent(handler: (event: import("./types").MigrationEvent) => void): () => void;
|
|
275
296
|
};
|
|
276
297
|
readonly Browser: {
|
|
277
298
|
open(urlOrOptions: string | import("./types").OpenInBrowserOptions, callback?: import("./runtime").NativeCallback<import("./types").OpenInBrowserResult>): Promise<import("./types").OpenInBrowserResult>;
|
|
@@ -450,5 +471,5 @@ export declare const Native: {
|
|
|
450
471
|
};
|
|
451
472
|
};
|
|
452
473
|
};
|
|
453
|
-
export { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, };
|
|
474
|
+
export { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Migration, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, };
|
|
454
475
|
export { Crypto };
|
package/dist/native.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Crypto } from './crypto-ns';
|
|
2
|
-
import { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, } from './plugins';
|
|
2
|
+
import { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Migration, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, } from './plugins';
|
|
3
|
+
import { onNativeEvent } from './events';
|
|
3
4
|
import { getPlatform, isNativeBridgeAvailable, isNativePlatform, whenReady } from './runtime';
|
|
4
5
|
import { SDK_VERSION } from './version';
|
|
5
6
|
const plugins = {
|
|
6
7
|
App,
|
|
7
8
|
Ota,
|
|
9
|
+
Migration,
|
|
8
10
|
Browser,
|
|
9
11
|
Device,
|
|
10
12
|
Config,
|
|
@@ -42,6 +44,8 @@ export const Native = {
|
|
|
42
44
|
isNativePlatform,
|
|
43
45
|
isNativeBridgeAvailable,
|
|
44
46
|
whenReady,
|
|
47
|
+
/** 订阅壳推送的事件:`Native.on('ota.install', fn)` / `Native.on('migration', fn)`,返回取消订阅函数 */
|
|
48
|
+
on: onNativeEvent,
|
|
45
49
|
Plugins: plugins,
|
|
46
50
|
...plugins,
|
|
47
51
|
/** H5 自行请求 Client API 时加密请求体(平台公钥来自 App.getInfo().platform.paramPublicKey) */
|
|
@@ -50,5 +54,5 @@ export const Native = {
|
|
|
50
54
|
if (typeof window !== 'undefined') {
|
|
51
55
|
window.Native = Native;
|
|
52
56
|
}
|
|
53
|
-
export { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, };
|
|
57
|
+
export { App, Biometric, Bluetooth, Brightness, Browser, Calendar, Capture, Clipboard, Config, Contacts, Device, Flashlight, Haptics, Http, Icon, Location, Media, Migration, Nfc, Notification, Ota, Payment, Picker, Push, Recorder, Scan, Sensor, Share, Store, Theme, Viewport, Volume, };
|
|
54
58
|
export { Crypto };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type NativeCallback } from './runtime';
|
|
2
|
-
import type { AppChannelCodes, AppIconState, AppIconsResult, AppInfo, AppInstalledResult, AppUpdateTriggerResult, ApkUpdateResult, CheckAppUpdateOptions, CheckAppsInstalledResult, DeviceIdentifiers, InstallDeviceId, DeviceInfo, CpuInfo, CanvasRenderInfo, WebGlInfo, EnvironmentInfo, EnvironmentDeviceInfo, PhoneStatePermissionResult, InstallAppPackageOptions, InstallAppPackageResult, InstallResourcePackageOptions, InstallResourcePackageResult, LaunchAppOptions, LaunchAppResult, LocationPermissionResult, LocationResult, LocationStatus, LocationWatchResult, LockStatus, NativeFeatureConfig, NotificationOptions, OpenInBrowserOptions, OpenInBrowserResult, OrientationInfo, SetFullscreenOptions, SetFullscreenResult, SetOrientationOptions, SetOrientationResult, PlayVideoOptions, PlayVideoResult, HttpRequestOptions, HttpRequestResult, ResourceUpdateResult, SafeAreaInsets, ScreenInfo, SetAppIconFromResourceOptions, 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';
|
|
2
|
+
import type { AppInstallState, MigrationEvent, MigrationExtrasOptions, MigrationInfo, MigrationUninstallResult, MigrationUninstallTarget, OtaInstallEvent, AppChannelCodes, AppIconState, AppIconsResult, AppInfo, AppInstalledResult, AppUpdateTriggerResult, ApkUpdateResult, CheckAppUpdateOptions, CheckAppsInstalledResult, DeviceIdentifiers, InstallDeviceId, DeviceInfo, CpuInfo, CanvasRenderInfo, WebGlInfo, EnvironmentInfo, EnvironmentDeviceInfo, PhoneStatePermissionResult, InstallAppPackageOptions, InstallAppPackageResult, InstallResourcePackageOptions, InstallResourcePackageResult, LaunchAppOptions, LaunchAppResult, LocationPermissionResult, LocationResult, LocationStatus, LocationWatchResult, LockStatus, NativeFeatureConfig, NotificationOptions, OpenInBrowserOptions, OpenInBrowserResult, OrientationInfo, SetFullscreenOptions, SetFullscreenResult, SetOrientationOptions, SetOrientationResult, PlayVideoOptions, PlayVideoResult, HttpRequestOptions, HttpRequestResult, ResourceUpdateResult, SafeAreaInsets, ScreenInfo, SetAppIconFromResourceOptions, 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
3
|
export declare const App: {
|
|
4
4
|
ping(callback?: NativeCallback<{
|
|
5
5
|
pong: boolean;
|
|
@@ -118,6 +118,36 @@ export declare const Ota: {
|
|
|
118
118
|
}>;
|
|
119
119
|
/** 等同 `installAppPackage({ url })`,兼容旧方法名 */
|
|
120
120
|
downloadAndInstallApk(url: string, callback?: NativeCallback<InstallAppPackageResult>): Promise<InstallAppPackageResult>;
|
|
121
|
+
/**
|
|
122
|
+
* 订阅安装包下载与安装进度(Android)。原生更新弹窗和 `installAppPackage` 都会触发。
|
|
123
|
+
* 返回取消订阅函数。
|
|
124
|
+
*/
|
|
125
|
+
onInstallEvent(handler: (event: OtaInstallEvent) => void): () => void;
|
|
126
|
+
/** 换包安装的当前阶段(Android)。页面刷新后用它恢复界面状态。 */
|
|
127
|
+
getInstallState(callback?: NativeCallback<AppInstallState>): Promise<AppInstallState>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* 换包更新的数据迁移(Android)。新安装包的包名与当前应用不同时,
|
|
131
|
+
* 装好后当前应用会自动拉起新应用,把登录状态(Cookie / localStorage)、
|
|
132
|
+
* 设备序列号和 `setExtras` 的数据交给它,完成后请求卸载当前应用。
|
|
133
|
+
*/
|
|
134
|
+
export declare const Migration: {
|
|
135
|
+
/**
|
|
136
|
+
* 迁移前补充要带走的数据。建议在登录后和每次登录态变化时调用。
|
|
137
|
+
* 新应用通过 `Migration.getInfo().extras` 读取。
|
|
138
|
+
*/
|
|
139
|
+
setExtras(options: MigrationExtrasOptions, callback?: NativeCallback<NativeOk>): Promise<NativeOk>;
|
|
140
|
+
/** 新应用已装好但没自动打开时(后台启动被系统拦截等),由用户点按钮手动继续 */
|
|
141
|
+
continue(callback?: NativeCallback<AppInstallState>): Promise<AppInstallState>;
|
|
142
|
+
/** 新应用里读取迁移结果 */
|
|
143
|
+
getInfo(callback?: NativeCallback<MigrationInfo>): Promise<MigrationInfo>;
|
|
144
|
+
/**
|
|
145
|
+
* 请求卸载:`self` 卸载当前应用(需迁移已完成),`source` 在新应用里卸载被迁移的旧应用。
|
|
146
|
+
* 迁移完成后原生会自动请求一次;用户在系统确认框里取消后,可用它再次发起。
|
|
147
|
+
*/
|
|
148
|
+
requestUninstall(target?: MigrationUninstallTarget, callback?: NativeCallback<MigrationUninstallResult>): Promise<MigrationUninstallResult>;
|
|
149
|
+
/** 订阅迁移事件。返回取消订阅函数。 */
|
|
150
|
+
onEvent(handler: (event: MigrationEvent) => void): () => void;
|
|
121
151
|
};
|
|
122
152
|
export declare const Browser: {
|
|
123
153
|
/** 打开系统浏览器。可直接传 URL 字符串:`Browser.open('https://example.com')` */
|
package/dist/plugins.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onNativeEvent } from './events';
|
|
1
2
|
import { invokeNative, withCallback } from './runtime';
|
|
2
3
|
import { readCanvasRenderInfo, readNavigatorCpu, readWebGlInfo } from './webview-signals';
|
|
3
4
|
function toEnvironmentDevice(device, system) {
|
|
@@ -220,6 +221,53 @@ export const Ota = {
|
|
|
220
221
|
downloadAndInstallApk(url, callback) {
|
|
221
222
|
return withCallback(invokeNative('downloadAndInstallApk', { url }), callback);
|
|
222
223
|
},
|
|
224
|
+
/**
|
|
225
|
+
* 订阅安装包下载与安装进度(Android)。原生更新弹窗和 `installAppPackage` 都会触发。
|
|
226
|
+
* 返回取消订阅函数。
|
|
227
|
+
*/
|
|
228
|
+
onInstallEvent(handler) {
|
|
229
|
+
return onNativeEvent('ota.install', handler);
|
|
230
|
+
},
|
|
231
|
+
/** 换包安装的当前阶段(Android)。页面刷新后用它恢复界面状态。 */
|
|
232
|
+
getInstallState(callback) {
|
|
233
|
+
return withCallback(invokeNative('getAppInstallState'), callback);
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* 换包更新的数据迁移(Android)。新安装包的包名与当前应用不同时,
|
|
238
|
+
* 装好后当前应用会自动拉起新应用,把登录状态(Cookie / localStorage)、
|
|
239
|
+
* 设备序列号和 `setExtras` 的数据交给它,完成后请求卸载当前应用。
|
|
240
|
+
*/
|
|
241
|
+
export const Migration = {
|
|
242
|
+
/**
|
|
243
|
+
* 迁移前补充要带走的数据。建议在登录后和每次登录态变化时调用。
|
|
244
|
+
* 新应用通过 `Migration.getInfo().extras` 读取。
|
|
245
|
+
*/
|
|
246
|
+
setExtras(options, callback) {
|
|
247
|
+
return withCallback(invokeNative('setMigrationExtras', {
|
|
248
|
+
extras: options.extras ?? {},
|
|
249
|
+
cookieUrls: options.cookieUrls ?? [],
|
|
250
|
+
}), callback);
|
|
251
|
+
},
|
|
252
|
+
/** 新应用已装好但没自动打开时(后台启动被系统拦截等),由用户点按钮手动继续 */
|
|
253
|
+
continue(callback) {
|
|
254
|
+
return withCallback(invokeNative('continueAppMigration'), callback);
|
|
255
|
+
},
|
|
256
|
+
/** 新应用里读取迁移结果 */
|
|
257
|
+
getInfo(callback) {
|
|
258
|
+
return withCallback(invokeNative('getMigrationInfo'), callback);
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* 请求卸载:`self` 卸载当前应用(需迁移已完成),`source` 在新应用里卸载被迁移的旧应用。
|
|
262
|
+
* 迁移完成后原生会自动请求一次;用户在系统确认框里取消后,可用它再次发起。
|
|
263
|
+
*/
|
|
264
|
+
requestUninstall(target = 'self', callback) {
|
|
265
|
+
return withCallback(invokeNative('requestUninstall', { target }), callback);
|
|
266
|
+
},
|
|
267
|
+
/** 订阅迁移事件。返回取消订阅函数。 */
|
|
268
|
+
onEvent(handler) {
|
|
269
|
+
return onNativeEvent('migration', handler);
|
|
270
|
+
},
|
|
223
271
|
};
|
|
224
272
|
export const Browser = {
|
|
225
273
|
/** 打开系统浏览器。可直接传 URL 字符串:`Browser.open('https://example.com')` */
|
package/dist/types.d.ts
CHANGED
|
@@ -526,6 +526,99 @@ export interface InstallAppPackageResult {
|
|
|
526
526
|
redirectedToStore?: boolean;
|
|
527
527
|
needsInstallPermission?: boolean;
|
|
528
528
|
message?: string;
|
|
529
|
+
/** 新安装包的包名(仅 Android;下载完成后读到) */
|
|
530
|
+
targetPackage?: string;
|
|
531
|
+
/** true:新安装包与当前应用不是同一个包名,装完后会迁移数据并卸载当前应用 */
|
|
532
|
+
crossPackage?: boolean;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* `Ota.onInstallEvent` 的阶段。顺序一般为:
|
|
536
|
+
* download-start → download-progress… → download-complete → install-start →
|
|
537
|
+
* install-prompt(等用户在系统框里确认)→ install-success。
|
|
538
|
+
* 同包升级装完后系统会替换并重启本应用,收不到 install-success。
|
|
539
|
+
*/
|
|
540
|
+
export type OtaInstallStage = 'download-start' | 'download-progress' | 'download-complete' | 'download-failed' | 'install-start' | 'install-prompt' | 'install-success' | 'install-canceled' | 'install-failed';
|
|
541
|
+
export interface OtaInstallEvent {
|
|
542
|
+
stage: OtaInstallStage;
|
|
543
|
+
ts: number;
|
|
544
|
+
/** download-progress:0–100,服务器没给长度时为 -1 */
|
|
545
|
+
percent?: number;
|
|
546
|
+
downloadedBytes?: number;
|
|
547
|
+
totalBytes?: number;
|
|
548
|
+
sizeBytes?: number;
|
|
549
|
+
packageName?: string;
|
|
550
|
+
versionName?: string;
|
|
551
|
+
/** install-start / install-success:是否换了包名 */
|
|
552
|
+
crossPackage?: boolean;
|
|
553
|
+
/** install-prompt:当前应用是否在前台。false 时会改用通知提示用户确认 */
|
|
554
|
+
foreground?: boolean;
|
|
555
|
+
message?: string;
|
|
556
|
+
code?: number;
|
|
557
|
+
}
|
|
558
|
+
/** 换包安装的当前阶段 */
|
|
559
|
+
export type AppInstallPhase = 'none' | 'installing' | 'installed' | 'handoff' | 'done' | 'failed';
|
|
560
|
+
/** Ota.getInstallState() / Migration.continue() */
|
|
561
|
+
export interface AppInstallState {
|
|
562
|
+
phase: AppInstallPhase;
|
|
563
|
+
targetPackage: string;
|
|
564
|
+
targetVersion: string;
|
|
565
|
+
handoffAttempts: number;
|
|
566
|
+
startedAt: number;
|
|
567
|
+
error: string;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* `Migration.onEvent` 的阶段。
|
|
571
|
+
* 旧应用侧:snapshot-saved、handoff-start、handoff-blocked、handoff-failed、complete、uninstall-prompt。
|
|
572
|
+
* 新应用侧:imported、applied、import-failed、uninstall-prompt。
|
|
573
|
+
*/
|
|
574
|
+
export type MigrationStage = 'snapshot-saved' | 'handoff-start' | 'handoff-blocked' | 'handoff-failed' | 'complete' | 'imported' | 'applied' | 'import-failed' | 'uninstall-prompt';
|
|
575
|
+
export interface MigrationEvent {
|
|
576
|
+
stage: MigrationStage;
|
|
577
|
+
ts: number;
|
|
578
|
+
message?: string;
|
|
579
|
+
packageName?: string;
|
|
580
|
+
targetPackage?: string;
|
|
581
|
+
fromPackage?: string;
|
|
582
|
+
source?: string;
|
|
583
|
+
foreground?: boolean;
|
|
584
|
+
deviceIdAdopted?: boolean;
|
|
585
|
+
/** imported:旧应用里通过 Migration.setExtras 保存的数据 */
|
|
586
|
+
extras?: Record<string, unknown>;
|
|
587
|
+
}
|
|
588
|
+
/** 新应用里读取:本应用是否由旧应用迁移而来 */
|
|
589
|
+
export interface MigrationInfo {
|
|
590
|
+
imported: boolean;
|
|
591
|
+
fromPackage: string;
|
|
592
|
+
importedAt: number;
|
|
593
|
+
/** 设备序列号(getInstallDeviceId)是否已沿用旧应用的值 */
|
|
594
|
+
deviceIdAdopted: boolean;
|
|
595
|
+
/** localStorage 是否已写入页面 */
|
|
596
|
+
webApplied: boolean;
|
|
597
|
+
/** localStorage 太大被裁剪过 */
|
|
598
|
+
truncated: boolean;
|
|
599
|
+
/** 旧应用还没卸载 */
|
|
600
|
+
uninstallPending: boolean;
|
|
601
|
+
extras: Record<string, unknown>;
|
|
602
|
+
lastError: string;
|
|
603
|
+
}
|
|
604
|
+
export interface MigrationExtrasOptions {
|
|
605
|
+
/** 随迁移带给新应用的数据,如内存里的 token,读取方式:`Migration.getInfo().extras` */
|
|
606
|
+
extras?: Record<string, unknown>;
|
|
607
|
+
/**
|
|
608
|
+
* 需要一起迁移 Cookie 的接口站点。页面所在站点自动包含,
|
|
609
|
+
* 接口放在别的域名时在这里列出,如 `['https://api.example.com']`。
|
|
610
|
+
*/
|
|
611
|
+
cookieUrls?: string[];
|
|
612
|
+
}
|
|
613
|
+
export type MigrationUninstallTarget = 'self' | 'source';
|
|
614
|
+
export interface MigrationUninstallResult {
|
|
615
|
+
success: boolean;
|
|
616
|
+
packageName: string;
|
|
617
|
+
}
|
|
618
|
+
export type NativeEventName = 'ota.install' | 'migration';
|
|
619
|
+
export interface NativeEventMap {
|
|
620
|
+
'ota.install': OtaInstallEvent;
|
|
621
|
+
migration: MigrationEvent;
|
|
529
622
|
}
|
|
530
623
|
export interface ApkUpdateResult {
|
|
531
624
|
hasUpdate: boolean;
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/docs/USAGE.md
CHANGED
|
@@ -732,6 +732,77 @@ Ota.checkApkUpdate().then(console.log);
|
|
|
732
732
|
// 返回示例:{ "hasUpdate": true, "versionCode": 12, "versionName": "1.0.2", "url": "https://...", "force": false }
|
|
733
733
|
```
|
|
734
734
|
|
|
735
|
+
### 5.3.1 换包更新与数据迁移(Android,包版本 **1.8.0+**)
|
|
736
|
+
|
|
737
|
+
新安装包的**包名**和当前应用不一样时(例如换了 `APP_ID` 出新包),系统把它当成另一个应用:登录态、localStorage、设备序列号都不会自动继承。壳在**安装 APK 的统一入口**里把这件事接住了,不管用户点的是**原生更新弹窗**(普通 / 强制)还是前端自定义弹窗里调用的 `Ota.installAppPackage`,走的是同一条流程,前端不用区分。
|
|
738
|
+
|
|
739
|
+
**流程**
|
|
740
|
+
|
|
741
|
+
1. 下载 APK,期间推送 `download-progress`。
|
|
742
|
+
2. 读 APK 包名。和当前应用相同:走系统安装器原地升级,和以前一样。不同:用 PackageInstaller 安装,并推送 `install-prompt` / `install-success` / `install-failed`。
|
|
743
|
+
3. 装好后,旧应用把登录态打包成一次性票据(10 分钟有效),用显式组件拉起新应用。
|
|
744
|
+
4. 新应用凭票据取走数据:Cookie、localStorage、设备序列号、`Migration.setExtras` 的内容。写好后确认,旧应用标记"已完成"。
|
|
745
|
+
5. 新应用请求卸载旧应用,旧应用回到前台时也会兜底提示一次。
|
|
746
|
+
|
|
747
|
+
**迁移的内容**
|
|
748
|
+
|
|
749
|
+
| 数据 | 怎么迁 |
|
|
750
|
+
|------|------|
|
|
751
|
+
| 登录 Cookie | 页面所在站点的 Cookie 自动带走;接口在其他域名时用 `Migration.setExtras({ cookieUrls })` 列出。迁过去的都是会话 Cookie(`Domain` / `Expires` 等属性 WebView 读不到) |
|
|
752
|
+
| localStorage | 在新页面加载的第一时间写入,页面脚本读到的就是旧值。单次最多约 300K 字符,超出会丢最大的几项(`getInfo().truncated`) |
|
|
753
|
+
| 设备序列号 | 新应用的 `Device.getInstallDeviceId()` 沿用旧值 |
|
|
754
|
+
| 前端自定义数据 | `Migration.setExtras({ extras })`,新应用 `Migration.getInfo().extras` 读取 |
|
|
755
|
+
| sessionStorage / IndexedDB | **不迁移**。需要的内容放进 `extras` |
|
|
756
|
+
|
|
757
|
+
**事件**
|
|
758
|
+
|
|
759
|
+
```typescript
|
|
760
|
+
import { Ota, Migration } from 'ota-native-bridge';
|
|
761
|
+
|
|
762
|
+
// 下载与安装进度。原生弹窗触发的更新也会收到
|
|
763
|
+
const offInstall = Ota.onInstallEvent((e) => {
|
|
764
|
+
switch (e.stage) {
|
|
765
|
+
case 'download-progress': render(e.percent); break; // 0-100,未知长度时为 -1
|
|
766
|
+
case 'install-prompt': tip('请在系统弹窗里确认安装'); break;
|
|
767
|
+
case 'install-success': tip('安装完成,正在迁移数据'); break;
|
|
768
|
+
case 'install-failed':
|
|
769
|
+
case 'download-failed': tip(e.message); break;
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
// 迁移进度(旧应用与新应用都会收到各自一侧的事件)
|
|
774
|
+
const offMigration = Migration.onEvent((e) => {
|
|
775
|
+
if (e.stage === 'handoff-blocked') showButton('打开新版本', () => Migration.continue());
|
|
776
|
+
if (e.stage === 'imported') console.log('已迁移', e.extras);
|
|
777
|
+
});
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
事件是 DOM 事件 `nativebridgeevent`(`detail = { name, payload }`),`Ota.onInstallEvent` / `Migration.onEvent` / `Native.on(name, fn)` 都是对它的封装。**页面还没加载好时发出的事件不补发**,页面启动时请用 `Ota.getInstallState()`、`Migration.getInfo()` 读当前状态。
|
|
781
|
+
|
|
782
|
+
**接口**
|
|
783
|
+
|
|
784
|
+
| 方法 | 说明 |
|
|
785
|
+
|------|------|
|
|
786
|
+
| `Ota.onInstallEvent(fn)` | 订阅下载与安装事件,返回取消订阅函数 |
|
|
787
|
+
| `Ota.getInstallState()` | 换包安装的阶段:`{ phase, targetPackage, targetVersion, handoffAttempts, startedAt, error }`,`phase` 为 `none / installing / installed / handoff / done / failed` |
|
|
788
|
+
| `Ota.installAppPackage(options)` | 结果新增 `targetPackage`、`crossPackage` |
|
|
789
|
+
| `Migration.setExtras({ extras?, cookieUrls? })` | 迁移前补充要带走的数据。建议登录后和登录态变化时调用 |
|
|
790
|
+
| `Migration.continue()` | 新应用已装好但没自动打开时,由用户点按钮重试交接 |
|
|
791
|
+
| `Migration.getInfo()` | 新应用里读迁移结果:`{ imported, fromPackage, importedAt, deviceIdAdopted, webApplied, truncated, uninstallPending, extras, lastError }` |
|
|
792
|
+
| `Migration.requestUninstall('self' \| 'source')` | `self` 卸载当前应用(迁移完成后),`source` 在新应用里卸载旧应用。用户在系统框里取消后可再次发起 |
|
|
793
|
+
| `Migration.onEvent(fn)` | 订阅迁移事件 |
|
|
794
|
+
|
|
795
|
+
`Migration` 事件的 `stage`:旧应用侧 `snapshot-saved`、`handoff-start`、`handoff-blocked`、`handoff-failed`、`complete`、`uninstall-prompt`;新应用侧 `imported`、`applied`、`import-failed`、`uninstall-prompt`。
|
|
796
|
+
|
|
797
|
+
**限制**
|
|
798
|
+
|
|
799
|
+
- 仅 **Android** 壳支持,iOS / Harmony / 桌面端调用 `Migration.*` 会报 `Unknown method`。
|
|
800
|
+
- 安装和卸载的**系统确认框一定会弹**,Android 不允许普通应用静默安装或卸载。
|
|
801
|
+
- Android 10 起后台应用不能直接拉起别的应用。装完时旧应用不在前台,会改发一条通知,点通知或回到旧应用时继续交接(最多重试 5 次),也可以由前端 `Migration.continue()` 手动触发。
|
|
802
|
+
- 谷歌商店渠道(`canSideloadApkUpdate=false`)不走应用内安装,直接跳商店,没有迁移。
|
|
803
|
+
- 新旧应用能互信靠的是同签名,或者两边打包进去的同一把平台密钥(HMAC)。用不同签名、也没有平台配置的包不会迁移。
|
|
804
|
+
- 新应用会先让预热页面起来,再把迁移来的 localStorage 写入并重新加载入口页。服务端可能短暂见到一次新设备序列号,请求以 `Device.getInstallDeviceId()` 为准时请在 `Migration.getInfo().imported === true` 后再读。
|
|
805
|
+
|
|
735
806
|
### 5.4 Client API 请求参数加密(必选)
|
|
736
807
|
|
|
737
808
|
凡 H5 / 自定义逻辑向 `/api/client/v1/**` 发起的 JSON POST(含 WebSocket 首条 subscribe),**必须**使用创建平台时生成的**参数公钥**加密。明文直传会被服务端拒绝(HTTP 400)。
|
|
@@ -1021,7 +1092,7 @@ Device.requestPhoneStatePermission().then(function () {
|
|
|
1021
1092
|
|
|
1022
1093
|
#### `Device.getInstallDeviceId()`
|
|
1023
1094
|
|
|
1024
|
-
壳在第一次启动时生成 32 位十六进制设备序列号(UUID v4)并保存。值由安全随机数产生,与签名证书、`ANDROID_ID` / IDFV / ODID 无关,也不受 `collectDeviceIdsAfterConsent` 控制。同一安装上的覆盖更新保持不变。iOS 写在仅本机的 Keychain 中,同一 Bundle ID、同一开发者 Team 卸载后重装仍是原值,换机备份不会把序列号复制到另一台设备。Android 写在应用私有偏好中,并排除云备份和换机迁移;覆盖安装不变,卸载重装会生成新值。Harmony 写在应用 preferences 中,覆盖安装不变,卸载重装会生成新值。
|
|
1095
|
+
壳在第一次启动时生成 32 位十六进制设备序列号(UUID v4)并保存。值由安全随机数产生,与签名证书、`ANDROID_ID` / IDFV / ODID 无关,也不受 `collectDeviceIdsAfterConsent` 控制。同一安装上的覆盖更新保持不变。Android 换了包名的更新,新应用会沿用旧应用的值(见 §5.3.1)。iOS 写在仅本机的 Keychain 中,同一 Bundle ID、同一开发者 Team 卸载后重装仍是原值,换机备份不会把序列号复制到另一台设备。Android 写在应用私有偏好中,并排除云备份和换机迁移;覆盖安装不变,卸载重装会生成新值。Harmony 写在应用 preferences 中,覆盖安装不变,卸载重装会生成新值。
|
|
1025
1096
|
|
|
1026
1097
|
```javascript
|
|
1027
1098
|
Device.getInstallDeviceId().then(function (result) {
|
|
@@ -1594,7 +1665,9 @@ Http.request({
|
|
|
1594
1665
|
| `Ota.setUid(uid)` | 仅设置上报用户 ID(主动设置后不再被请求头 Hook 覆盖) | `{ success: true, uid: "user-123" }` |
|
|
1595
1666
|
| `Ota.setChannel(channel)` | 仅设置上报渠道码(主动设置后不再被请求头 Hook 覆盖) | `{ success: true, channel: "yyb" }` |
|
|
1596
1667
|
| `Ota.installResourcePackage(options)` | 安装资源包 | `{ success, needsRestart, restarted, message }` |
|
|
1597
|
-
| `Ota.installAppPackage(options)` | 安装 APK 等 | `{ success, message, needsInstallPermission? }` |
|
|
1668
|
+
| `Ota.installAppPackage(options)` | 安装 APK 等 | `{ success, message, needsInstallPermission?, targetPackage?, crossPackage? }` |
|
|
1669
|
+
| `Ota.onInstallEvent(fn)` / `Ota.getInstallState()` | 下载与安装进度、换包安装阶段(Android) | 见 §5.3.1 |
|
|
1670
|
+
| `Migration.setExtras` / `continue` / `getInfo` / `requestUninstall` / `onEvent` | 换包数据迁移(Android) | 见 §5.3.1 |
|
|
1598
1671
|
| `Ota.downloadAndInstallApk(url)` | 等同 `installAppPackage({ url })` | 同上 |
|
|
1599
1672
|
| `Ota.checkResourceUpdate` / `Ota.checkApkUpdate` | 按 URL 检测 | `{ hasUpdate, version?/versionName?, url? }` |
|
|
1600
1673
|
| `Ota.applyResourceUpdate` | 安装资源包不重启 | `{ success: true, needsRestart: true, restarted: false }` |
|
package/ota-native-bridge.js
CHANGED
|
@@ -173,6 +173,17 @@
|
|
|
173
173
|
setBadgeCount: function (count, cb) { return withCallback(invokeNative('setBadgeCount', { count: count }), cb); }
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
+
function onNativeEvent(name, handler) {
|
|
177
|
+
if (typeof window === 'undefined') return function () {};
|
|
178
|
+
var listener = function (e) {
|
|
179
|
+
var d = e && e.detail;
|
|
180
|
+
if (!d || d.name !== name) return;
|
|
181
|
+
try { handler(d.payload); } catch (err) { if (typeof console !== 'undefined') console.error('[ota-native-bridge] event handler failed', err); }
|
|
182
|
+
};
|
|
183
|
+
window.addEventListener('nativebridgeevent', listener);
|
|
184
|
+
return function () { window.removeEventListener('nativebridgeevent', listener); };
|
|
185
|
+
}
|
|
186
|
+
|
|
176
187
|
var Ota = {
|
|
177
188
|
checkResourceUpdate: function (url, cb) { return withCallback(invokeNative('checkResourceUpdate', url ? { url: url } : {}), cb); },
|
|
178
189
|
applyResourceUpdate: function (url, cb) { return withCallback(invokeNative('applyResourceUpdate', { url: url }), cb); },
|
|
@@ -196,7 +207,20 @@
|
|
|
196
207
|
setChannel: function (channel, cb) { return withCallback(invokeNative('setOtaChannel', { channel: channel || '' }), cb); },
|
|
197
208
|
downloadAndInstallApk: function (url, cb) {
|
|
198
209
|
return withCallback(invokeNative('downloadAndInstallApk', { url: url }), cb);
|
|
199
|
-
}
|
|
210
|
+
},
|
|
211
|
+
onInstallEvent: function (handler) { return onNativeEvent('ota.install', handler); },
|
|
212
|
+
getInstallState: function (cb) { return withCallback(invokeNative('getAppInstallState'), cb); }
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
var Migration = {
|
|
216
|
+
setExtras: function (opts, cb) {
|
|
217
|
+
opts = opts || {};
|
|
218
|
+
return withCallback(invokeNative('setMigrationExtras', { extras: opts.extras || {}, cookieUrls: opts.cookieUrls || [] }), cb);
|
|
219
|
+
},
|
|
220
|
+
'continue': function (cb) { return withCallback(invokeNative('continueAppMigration'), cb); },
|
|
221
|
+
getInfo: function (cb) { return withCallback(invokeNative('getMigrationInfo'), cb); },
|
|
222
|
+
requestUninstall: function (target, cb) { return withCallback(invokeNative('requestUninstall', { target: target || 'self' }), cb); },
|
|
223
|
+
onEvent: function (handler) { return onNativeEvent('migration', handler); }
|
|
200
224
|
};
|
|
201
225
|
|
|
202
226
|
var Browser = {
|
|
@@ -375,7 +399,7 @@
|
|
|
375
399
|
};
|
|
376
400
|
|
|
377
401
|
var plugins = {
|
|
378
|
-
App: App, Ota: Ota, Browser: Browser, Device: Device, Config: Config, Theme: Theme, Icon: Icon,
|
|
402
|
+
App: App, Ota: Ota, Migration: Migration, Browser: Browser, Device: Device, Config: Config, Theme: Theme, Icon: Icon,
|
|
379
403
|
Viewport: Viewport, Notification: Notification, Location: Location, Media: Media, Http: Http,
|
|
380
404
|
Clipboard: Clipboard, Share: Share, Picker: Picker, Scan: Scan, Biometric: Biometric,
|
|
381
405
|
Contacts: Contacts, Calendar: Calendar, Bluetooth: Bluetooth, Nfc: Nfc, Sensor: Sensor,
|
|
@@ -384,14 +408,16 @@
|
|
|
384
408
|
};
|
|
385
409
|
|
|
386
410
|
global.Native = {
|
|
387
|
-
sdkVersion: '1.
|
|
411
|
+
sdkVersion: '1.8.0',
|
|
388
412
|
getPlatform: getPlatform,
|
|
389
413
|
isNativePlatform: isNativePlatform,
|
|
390
414
|
isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
|
|
391
415
|
whenReady: waitForBridge,
|
|
416
|
+
on: onNativeEvent,
|
|
392
417
|
Plugins: plugins,
|
|
393
418
|
App: App,
|
|
394
419
|
Ota: Ota,
|
|
420
|
+
Migration: Migration,
|
|
395
421
|
Browser: Browser,
|
|
396
422
|
Device: Device,
|
|
397
423
|
Config: Config,
|