ota-native-bridge 1.2.0 → 1.3.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 +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/plugins.js +4 -0
- package/dist/cjs/runtime.js +18 -1
- package/dist/cjs/version.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/native.d.ts +3 -1
- package/dist/plugins.d.ts +3 -1
- package/dist/plugins.js +4 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +17 -1
- package/dist/types.d.ts +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/USAGE.md +28 -6
- package/ota-native-bridge.js +18 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ if (Native.isNativePlatform()) {
|
|
|
50
50
|
| 推送 token | `Push.getToken()` |
|
|
51
51
|
| 全屏播视频 | `Media.playVideo({ url, title })` |
|
|
52
52
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
53
|
+
| 用资源包里的图换桌面图标 | `Icon.setFromResource({ path: 'icons/app-icon.png' })`(Android 8+;iOS / Harmony 返回失败) |
|
|
53
54
|
| 加密 Client API 请求 | `Crypto.postEncrypted(url, plain, pem)` |
|
|
54
55
|
|
|
55
56
|
## OTA 服务端地址
|
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.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.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;
|
|
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; } });
|
|
@@ -57,6 +57,7 @@ Object.defineProperty(exports, "whenReady", { enumerable: true, get: function ()
|
|
|
57
57
|
Object.defineProperty(exports, "getPlatform", { enumerable: true, get: function () { return runtime_1.getPlatform; } });
|
|
58
58
|
Object.defineProperty(exports, "isNativePlatform", { enumerable: true, get: function () { return runtime_1.isNativePlatform; } });
|
|
59
59
|
Object.defineProperty(exports, "invokeNative", { enumerable: true, get: function () { return runtime_1.invokeNative; } });
|
|
60
|
+
Object.defineProperty(exports, "decodeBridgePayload", { enumerable: true, get: function () { return runtime_1.decodeBridgePayload; } });
|
|
60
61
|
var native_messenger_1 = require("./native-messenger");
|
|
61
62
|
Object.defineProperty(exports, "getNativePostMessage", { enumerable: true, get: function () { return native_messenger_1.getNativePostMessage; } });
|
|
62
63
|
Object.defineProperty(exports, "isNativeBridgeAvailable", { enumerable: true, get: function () { return native_messenger_1.isNativeBridgeAvailable; } });
|
package/dist/cjs/plugins.js
CHANGED
|
@@ -81,6 +81,10 @@ exports.Icon = {
|
|
|
81
81
|
setFromBase64(options, callback) {
|
|
82
82
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('setAppIconFromBase64', { ...options }), callback);
|
|
83
83
|
},
|
|
84
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
85
|
+
setFromResource(options, callback) {
|
|
86
|
+
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('setAppIconFromResource', { ...options }), callback);
|
|
87
|
+
},
|
|
84
88
|
};
|
|
85
89
|
exports.Viewport = {
|
|
86
90
|
getSafeAreaInsets(callback) {
|
package/dist/cjs/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isNativeBridgeAvailable = void 0;
|
|
4
|
+
exports.decodeBridgePayload = decodeBridgePayload;
|
|
4
5
|
exports.callNative = callNative;
|
|
5
6
|
exports.getPlatform = getPlatform;
|
|
6
7
|
exports.isNativePlatform = isNativePlatform;
|
|
@@ -13,6 +14,22 @@ const BRIDGE_READY_EVENT = 'nativebridgeready';
|
|
|
13
14
|
let seq = 0;
|
|
14
15
|
const pending = {};
|
|
15
16
|
let readyPromise = null;
|
|
17
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
18
|
+
function decodeBridgePayload(payload) {
|
|
19
|
+
if (payload == null || typeof payload !== 'string') {
|
|
20
|
+
return payload;
|
|
21
|
+
}
|
|
22
|
+
const trimmed = payload.trim();
|
|
23
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(payload);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return payload;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
16
33
|
function installNativeCallback() {
|
|
17
34
|
if (typeof window === 'undefined' || window.__nativeBridgeCallback) {
|
|
18
35
|
return;
|
|
@@ -23,7 +40,7 @@ function installNativeCallback() {
|
|
|
23
40
|
return;
|
|
24
41
|
}
|
|
25
42
|
delete pending[id];
|
|
26
|
-
const data =
|
|
43
|
+
const data = decodeBridgePayload(payload);
|
|
27
44
|
if (success) {
|
|
28
45
|
item.resolve(data);
|
|
29
46
|
}
|
package/dist/cjs/version.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './types';
|
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
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';
|
|
4
4
|
export type { NativeCallback, NativePlatform } from './runtime';
|
|
5
|
-
export { whenReady, getPlatform, isNativePlatform, invokeNative } from './runtime';
|
|
5
|
+
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
6
6
|
export { getNativePostMessage, isNativeBridgeAvailable, type NativePostMessage, } from './native-messenger';
|
|
7
7
|
export { encryptRequestBody, postEncrypted, type EncryptedEnvelope, } from './crypto';
|
|
8
8
|
export { Crypto } from './crypto-ns';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export { PACKAGE_NAME, SDK_VERSION } from './version';
|
|
3
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';
|
|
4
|
-
export { whenReady, getPlatform, isNativePlatform, invokeNative } from './runtime';
|
|
4
|
+
export { whenReady, getPlatform, isNativePlatform, invokeNative, decodeBridgePayload } from './runtime';
|
|
5
5
|
export { getNativePostMessage, isNativeBridgeAvailable, } from './native-messenger';
|
|
6
6
|
export { encryptRequestBody, postEncrypted, } from './crypto';
|
|
7
7
|
export { Crypto } from './crypto-ns';
|
package/dist/native.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export declare const Native: {
|
|
|
79
79
|
data?: string;
|
|
80
80
|
base64?: string;
|
|
81
81
|
}, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
82
|
+
setFromResource(options: import("./types").SetAppIconFromResourceOptions, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
82
83
|
};
|
|
83
84
|
readonly Viewport: {
|
|
84
85
|
getSafeAreaInsets(callback?: import("./runtime").NativeCallback<import("./types").SafeAreaInsets>): Promise<import("./types").SafeAreaInsets>;
|
|
@@ -207,7 +208,7 @@ export declare const Native: {
|
|
|
207
208
|
readonly Push: {
|
|
208
209
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
209
210
|
};
|
|
210
|
-
readonly sdkVersion: "1.
|
|
211
|
+
readonly sdkVersion: "1.3.0";
|
|
211
212
|
readonly getPlatform: typeof getPlatform;
|
|
212
213
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
213
214
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
|
@@ -284,6 +285,7 @@ export declare const Native: {
|
|
|
284
285
|
data?: string;
|
|
285
286
|
base64?: string;
|
|
286
287
|
}, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
288
|
+
setFromResource(options: import("./types").SetAppIconFromResourceOptions, callback?: import("./runtime").NativeCallback<import("./types").SetAppIconResult>): Promise<import("./types").SetAppIconResult>;
|
|
287
289
|
};
|
|
288
290
|
readonly Viewport: {
|
|
289
291
|
getSafeAreaInsets(callback?: import("./runtime").NativeCallback<import("./types").SafeAreaInsets>): Promise<import("./types").SafeAreaInsets>;
|
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, 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';
|
|
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, 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;
|
|
@@ -41,6 +41,8 @@ export declare const Icon: {
|
|
|
41
41
|
data?: string;
|
|
42
42
|
base64?: string;
|
|
43
43
|
}, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
44
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
45
|
+
setFromResource(options: SetAppIconFromResourceOptions, callback?: NativeCallback<SetAppIconResult>): Promise<SetAppIconResult>;
|
|
44
46
|
};
|
|
45
47
|
export declare const Viewport: {
|
|
46
48
|
getSafeAreaInsets(callback?: NativeCallback<SafeAreaInsets>): Promise<SafeAreaInsets>;
|
package/dist/plugins.js
CHANGED
|
@@ -78,6 +78,10 @@ export const Icon = {
|
|
|
78
78
|
setFromBase64(options, callback) {
|
|
79
79
|
return withCallback(invokeNative('setAppIconFromBase64', { ...options }), callback);
|
|
80
80
|
},
|
|
81
|
+
/** 用前端资源包内的图片替换桌面图标。Android 8+ 生效(8–10 会弹出系统确认);iOS / Harmony 返回 success: false。 */
|
|
82
|
+
setFromResource(options, callback) {
|
|
83
|
+
return withCallback(invokeNative('setAppIconFromResource', { ...options }), callback);
|
|
84
|
+
},
|
|
81
85
|
};
|
|
82
86
|
export const Viewport = {
|
|
83
87
|
getSafeAreaInsets(callback) {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isNativeBridgeAvailable } from './native-messenger';
|
|
2
2
|
export type NativePlatform = 'android' | 'ios' | 'harmony' | 'web';
|
|
3
3
|
export type NativeCallback<T> = (result: T, error?: Error) => void;
|
|
4
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
5
|
+
export declare function decodeBridgePayload(payload: string | object | null | undefined): unknown;
|
|
4
6
|
export declare function callNative<T>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
5
7
|
export declare function getPlatform(): NativePlatform;
|
|
6
8
|
export declare function isNativePlatform(): boolean;
|
package/dist/runtime.js
CHANGED
|
@@ -3,6 +3,22 @@ const BRIDGE_READY_EVENT = 'nativebridgeready';
|
|
|
3
3
|
let seq = 0;
|
|
4
4
|
const pending = {};
|
|
5
5
|
let readyPromise = null;
|
|
6
|
+
/** 空串 / `"undefined"` 不能 JSON.parse;失败时回传原字符串,避免同步 Uncaught SyntaxError */
|
|
7
|
+
export function decodeBridgePayload(payload) {
|
|
8
|
+
if (payload == null || typeof payload !== 'string') {
|
|
9
|
+
return payload;
|
|
10
|
+
}
|
|
11
|
+
const trimmed = payload.trim();
|
|
12
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(payload);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return payload;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
function installNativeCallback() {
|
|
7
23
|
if (typeof window === 'undefined' || window.__nativeBridgeCallback) {
|
|
8
24
|
return;
|
|
@@ -13,7 +29,7 @@ function installNativeCallback() {
|
|
|
13
29
|
return;
|
|
14
30
|
}
|
|
15
31
|
delete pending[id];
|
|
16
|
-
const data =
|
|
32
|
+
const data = decodeBridgePayload(payload);
|
|
17
33
|
if (success) {
|
|
18
34
|
item.resolve(data);
|
|
19
35
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -226,6 +226,8 @@ export interface AppIconState {
|
|
|
226
226
|
customIconPath: string;
|
|
227
227
|
customIconExists: boolean;
|
|
228
228
|
supportsCustomFromUrl: boolean;
|
|
229
|
+
/** Android 8+ 可从资源包换桌面图标(8–10 需系统确认一次);iOS / Harmony 为 false */
|
|
230
|
+
supportsCustomFromResource?: boolean;
|
|
229
231
|
}
|
|
230
232
|
export interface AppIconsResult {
|
|
231
233
|
icons: AppIconOption[];
|
|
@@ -236,6 +238,10 @@ export interface SetAppIconOptions {
|
|
|
236
238
|
/** 与 iconId 等价 */
|
|
237
239
|
icon?: AppIconId;
|
|
238
240
|
}
|
|
241
|
+
/** 资源包内相对路径,例如 `icons/app-icon.png`(相对 www 根,不要带 `www/` 前缀) */
|
|
242
|
+
export interface SetAppIconFromResourceOptions {
|
|
243
|
+
path: string;
|
|
244
|
+
}
|
|
239
245
|
export interface SetAppIconResult {
|
|
240
246
|
success: boolean;
|
|
241
247
|
iconId: AppIconId;
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/docs/USAGE.md
CHANGED
|
@@ -778,7 +778,8 @@ iOS 对应字段:`apiBaseUrl`、`platformId`、`apiKey`、`autoCheckUpdateOnLa
|
|
|
778
778
|
},
|
|
779
779
|
"update": {
|
|
780
780
|
"useCustomUpdate": false
|
|
781
|
-
}
|
|
781
|
+
},
|
|
782
|
+
"desktopIcon": "icons/app-icon.png"
|
|
782
783
|
}
|
|
783
784
|
```
|
|
784
785
|
|
|
@@ -790,6 +791,7 @@ iOS 对应字段:`apiBaseUrl`、`platformId`、`apiKey`、`autoCheckUpdateOnLa
|
|
|
790
791
|
| `safeArea.enableTop` / `enableBottom` | 头部沉浸式适配 / 底部原生收缩(默认 `true`) |
|
|
791
792
|
| `safeArea.topBackgroundColor` / `bottomBackgroundColor` | 头部/底部安全区色条颜色,留空回退 `theme.backgroundColor` |
|
|
792
793
|
| `theme` / `guide` 等 | 界面与功能开关(**开屏广告不在此配置**,由管理后台 OTA 下发,见 [OTA_PROTOCOL.md](../../docs/OTA_PROTOCOL.md)) |
|
|
794
|
+
| `desktopIcon` | 资源包内桌面图标相对路径(如 `icons/app-icon.png`)。Android 安装资源包后自动套用;Android 11+ 冷启动也会套用。留空则不自动换图标 |
|
|
793
795
|
|
|
794
796
|
### 6.3 `App.getInfo()` 中的 `platform`
|
|
795
797
|
|
|
@@ -1124,7 +1126,8 @@ Icon.list().then(console.log);
|
|
|
1124
1126
|
// "launcherEntryCount": 1,
|
|
1125
1127
|
// "customIconPath": "",
|
|
1126
1128
|
// "customIconExists": false,
|
|
1127
|
-
// "supportsCustomFromUrl": true
|
|
1129
|
+
// "supportsCustomFromUrl": true,
|
|
1130
|
+
// "supportsCustomFromResource": true
|
|
1128
1131
|
// }
|
|
1129
1132
|
// }
|
|
1130
1133
|
|
|
@@ -1139,8 +1142,27 @@ Icon.setFromUrl({ url: 'https://cdn.example.com/icon.png' }).then(console.log);
|
|
|
1139
1142
|
|
|
1140
1143
|
Icon.setFromBase64({ base64: 'iVBORw0KGgo...' }).then(console.log);
|
|
1141
1144
|
// 返回示例:{ "success": true, "iconId": "custom", "message": "ok" }
|
|
1145
|
+
|
|
1146
|
+
Icon.setFromResource({ path: 'icons/app-icon.png' }).then(console.log);
|
|
1147
|
+
// Android 11+:
|
|
1148
|
+
// { "success": true, "iconId": "custom", "message": "ok", "requiresLauncherRefresh": true, "pendingPinConfirmation": false }
|
|
1149
|
+
// Android 8–10,系统确认框还在等用户点:
|
|
1150
|
+
// { "success": true, "iconId": "custom", "message": "Confirm the new home screen icon.", "pendingPinConfirmation": true }
|
|
1142
1151
|
```
|
|
1143
1152
|
|
|
1153
|
+
`path` 是前端资源包内的相对路径,不要带 `www/` 前缀,也不要包含 `..`。壳解密 `www.pkg` 后按这个路径取图(热更新包优先于安装包内置资源)。
|
|
1154
|
+
|
|
1155
|
+
| 系统 | 行为 |
|
|
1156
|
+
|------|------|
|
|
1157
|
+
| Android 11+ | 直接盖住当前桌面入口,不新增图标,没有系统确认框 |
|
|
1158
|
+
| Android 8–10 | 弹出一次系统确认。用户允许后,按 Home 回到桌面,原来的启动入口会被收起,只留新图标。同一张图之后再换不再弹框。`pendingPinConfirmation: true` 表示还在等这次确认 |
|
|
1159
|
+
| iOS | 返回 `success: false`。只能用 `Icon.set` 在打包时烤入的备用图标之间切换 |
|
|
1160
|
+
| HarmonyOS | 返回 `success: false`。运行时不能改桌面图标 |
|
|
1161
|
+
|
|
1162
|
+
`Icon.get()` 的 `supportsCustomFromResource`:Android 11+ 为 `true`;Android 8–10 在当前桌面支持固定快捷方式时为 `true`。
|
|
1163
|
+
|
|
1164
|
+
资源包 `app_config.json` 可写 `"desktopIcon": "icons/app-icon.png"`。安装资源包后 Android 会自动套用;Android 11+ 在冷启动时也会套用。同一份资源包只自动套用一次,之后前端再调用 `Icon.setFromResource` 选其他图,下一次冷启动不会把它盖掉。Android 8–10 的冷启动不会再弹确认框,只在图标已经固定过时静默更新。
|
|
1165
|
+
|
|
1144
1166
|
### 7.4 通知与角标
|
|
1145
1167
|
|
|
1146
1168
|
```typescript
|
|
@@ -1394,8 +1416,8 @@ Push.getToken().then(console.log);
|
|
|
1394
1416
|
| 能力 | Android | iOS | HarmonyOS |
|
|
1395
1417
|
|------|---------|-----|-----------|
|
|
1396
1418
|
| 剪贴板 / 分享 | 已实现 | 已实现 | 已实现 |
|
|
1397
|
-
| 选图 / 拍照 / 选文件 |
|
|
1398
|
-
| 保存相册 | MediaStore | 写入相册(需相册权限) | 系统相册入口,部分机型需业务自行落盘 |
|
|
1419
|
+
| 选图 / 拍照 / 选文件 | 相册始终 `ACTION_PICK`;文件始终 `OPEN_DOCUMENT`;拍照 FileProvider | PHPicker / 相机 / 文档 | PhotoViewPicker / DocumentViewPicker |
|
|
1420
|
+
| 保存相册 | MediaStore(应用专属写入,不需 READ_MEDIA) | 写入相册(需相册权限) | 系统相册入口,部分机型需业务自行落盘 |
|
|
1399
1421
|
| 扫码 | ZXing 全屏扫码 | AVFoundation | Scan Kit |
|
|
1400
1422
|
| 生物识别 | BiometricPrompt | LocalAuthentication(面容/指纹) | 因系统版本差异可能返回未接线提示 |
|
|
1401
1423
|
| 通讯录 / 日历 | 系统选择器 / 插入日历 Intent | CNContactPicker / EKEventEdit | 日历/联系人选择器因 API 版本可能降级 |
|
|
@@ -1406,7 +1428,7 @@ Push.getToken().then(console.log);
|
|
|
1406
1428
|
| 支付 | **不内置**微信/支付宝 SDK,打开 `url`/`payUrl` | 同左 | 同左 |
|
|
1407
1429
|
| 应用内评分 | Play In-App Review | `SKStoreReviewController` | 引导应用市场 |
|
|
1408
1430
|
| 推送 token | 无 FCM;`provider: ota-websocket` | APNs(App ID 须打开 Push) | `ota-websocket` |
|
|
1409
|
-
| 换图标 | `Icon.set
|
|
1431
|
+
| 换图标 | 预置槽 `Icon.set`。资源包图用 `Icon.setFromResource`:Android 11+ 直接覆盖当前入口;Android 8–10 系统确认一次后固定快捷方式 | 只能切 Alternate Icons(`default` / `alt1` / `alt2`)。`setFromResource` 不能改桌面图标 | 运行时不能改桌面图标,`setFromResource` 返回 `success: false` |
|
|
1410
1432
|
| 角标 | ShortcutBadger(看桌面) | `applicationIconBadgeNumber` | `notificationManager.setBadgeNumber` |
|
|
1411
1433
|
| 锁屏 | Keyguard 真实状态 | `isProtectedDataAvailable`(前台近似) | `screenLock`;不支持时 `supported: false` |
|
|
1412
1434
|
|
|
@@ -1481,6 +1503,6 @@ A:执行 `npm run build` 生成 `dist/*.d.ts`,或确认依赖版本已包含
|
|
|
1481
1503
|
|
|
1482
1504
|
## 11. 相关文档
|
|
1483
1505
|
|
|
1484
|
-
- [README.md](../README.md) —
|
|
1506
|
+
- [README.md](../README.md) — 包结构与快速上手
|
|
1485
1507
|
- 仓库 `AppUpgradeOTASystem` 根目录 `README.md` — OTA 系统整体说明
|
|
1486
1508
|
- 管理后台「公共接口」— REST / WebSocket 鉴权与端点列表
|
package/ota-native-bridge.js
CHANGED
|
@@ -38,15 +38,23 @@
|
|
|
38
38
|
var item = pending[id];
|
|
39
39
|
if (!item) return;
|
|
40
40
|
delete pending[id];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
var data = payload;
|
|
42
|
+
if (typeof payload === 'string') {
|
|
43
|
+
var trimmed = payload.replace(/^\s+|\s+$/g, '');
|
|
44
|
+
if (!trimmed || trimmed === 'undefined') {
|
|
45
|
+
data = null;
|
|
46
|
+
} else {
|
|
47
|
+
try {
|
|
48
|
+
data = JSON.parse(payload);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
data = payload;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
53
|
+
}
|
|
54
|
+
if (success) {
|
|
55
|
+
item.resolve(data);
|
|
48
56
|
} else {
|
|
49
|
-
item.reject(new Error(
|
|
57
|
+
item.reject(new Error(String(data)));
|
|
50
58
|
}
|
|
51
59
|
};
|
|
52
60
|
|
|
@@ -132,7 +140,8 @@
|
|
|
132
140
|
get: function (cb) { return withCallback(invokeNative('getAppIcon'), cb); },
|
|
133
141
|
set: function (opts, cb) { return withCallback(invokeNative('setAppIcon', opts), cb); },
|
|
134
142
|
setFromUrl: function (opts, cb) { return withCallback(invokeNative('setAppIconFromUrl', opts), cb); },
|
|
135
|
-
setFromBase64: function (opts, cb) { return withCallback(invokeNative('setAppIconFromBase64', opts), cb); }
|
|
143
|
+
setFromBase64: function (opts, cb) { return withCallback(invokeNative('setAppIconFromBase64', opts), cb); },
|
|
144
|
+
setFromResource: function (opts, cb) { return withCallback(invokeNative('setAppIconFromResource', opts), cb); }
|
|
136
145
|
};
|
|
137
146
|
|
|
138
147
|
var Viewport = {
|
|
@@ -357,7 +366,7 @@
|
|
|
357
366
|
};
|
|
358
367
|
|
|
359
368
|
global.Native = {
|
|
360
|
-
sdkVersion: '1.
|
|
369
|
+
sdkVersion: '1.3.0',
|
|
361
370
|
getPlatform: getPlatform,
|
|
362
371
|
isNativePlatform: isNativePlatform,
|
|
363
372
|
isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
|