ota-native-bridge 1.5.0 → 1.6.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 +2 -1
- package/dist/cjs/plugins.js +48 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/webview-signals.js +82 -0
- package/dist/native.d.ts +21 -3
- package/dist/plugins.d.ts +15 -2
- package/dist/plugins.js +48 -0
- package/dist/types.d.ts +41 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/webview-signals.d.ts +7 -0
- package/dist/webview-signals.js +77 -0
- package/docs/USAGE.md +33 -2
- package/ota-native-bridge.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,8 +50,9 @@ if (Native.isNativePlatform()) {
|
|
|
50
50
|
| 推送 token | `Push.getToken()` |
|
|
51
51
|
| 全屏播视频 | `Media.playVideo({ url, title })` |
|
|
52
52
|
| 读设备标识 | `Device.getIdentifiers()`(须 `collectDeviceIdsAfterConsent`) |
|
|
53
|
-
|
|
|
53
|
+
| 读壳生成的设备序列号 | `Device.getInstallDeviceId()`(UUID v4,与签名证书无关,不需要同意开关) |
|
|
54
54
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
55
|
+
| 读机型 / 系统 / CPU / Canvas / WebGL | `Device.getEnvironmentInfo()` 一次返回(含系统版本、厂商、型号);也可分别调用 `getInfo()` / `getSystemInfo()` / `getCpuInfo()` / `getCanvasRenderInfo()` / `getWebGlInfo()` |
|
|
55
56
|
| 用资源包里的图换桌面图标 | `Icon.setFromResource({ path: 'icons/app-icon.png' })`(Android 8+;iOS / Harmony 返回失败) |
|
|
56
57
|
| 加密 Client API 请求 | `Crypto.postEncrypted(url, plain, pem)` |
|
|
57
58
|
|
package/dist/cjs/plugins.js
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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;
|
|
4
4
|
const runtime_1 = require("./runtime");
|
|
5
|
+
const webview_signals_1 = require("./webview-signals");
|
|
6
|
+
function toEnvironmentDevice(device, system) {
|
|
7
|
+
return {
|
|
8
|
+
os: firstText(system?.os, system?.platform),
|
|
9
|
+
osVersion: firstText(system?.release, system?.osVersion, device?.systemVersion, device?.osFullName),
|
|
10
|
+
manufacturer: firstText(device?.manufacturer),
|
|
11
|
+
brand: firstText(device?.brand),
|
|
12
|
+
model: firstText(device?.model),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function firstText(...values) {
|
|
16
|
+
for (const value of values) {
|
|
17
|
+
if (typeof value === 'string' && value.trim())
|
|
18
|
+
return value.trim();
|
|
19
|
+
}
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
5
22
|
function asBrowserOptions(urlOrOptions) {
|
|
6
23
|
return typeof urlOrOptions === 'string' ? { url: urlOrOptions } : urlOrOptions;
|
|
7
24
|
}
|
|
@@ -48,6 +65,37 @@ exports.Device = {
|
|
|
48
65
|
getSystemInfo(callback) {
|
|
49
66
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getSystemInfo'), callback);
|
|
50
67
|
},
|
|
68
|
+
/** 逻辑核心数。Android / iOS 读系统值;Harmony 与浏览器预览读 WebView 的 hardwareConcurrency。 */
|
|
69
|
+
getCpuInfo(callback) {
|
|
70
|
+
const promise = (0, runtime_1.invokeNative)('getCpuInfo')
|
|
71
|
+
.then((info) => (info.supported && info.logicalCores > 0 ? info : (0, webview_signals_1.readNavigatorCpu)()))
|
|
72
|
+
.catch(() => (0, webview_signals_1.readNavigatorCpu)());
|
|
73
|
+
return (0, runtime_1.withCallback)(promise, callback);
|
|
74
|
+
},
|
|
75
|
+
/** 当前 WebView 绘制固定图形后的摘要。不是设备序列号。 */
|
|
76
|
+
getCanvasRenderInfo(callback) {
|
|
77
|
+
return (0, runtime_1.withCallback)(Promise.resolve((0, webview_signals_1.readCanvasRenderInfo)()), callback);
|
|
78
|
+
},
|
|
79
|
+
/** 当前 WebView 允许页面看到的 WebGL 厂商、渲染器和版本。 */
|
|
80
|
+
getWebGlInfo(callback) {
|
|
81
|
+
return (0, runtime_1.withCallback)(Promise.resolve((0, webview_signals_1.readWebGlInfo)()), callback);
|
|
82
|
+
},
|
|
83
|
+
/** 机型、系统版本、CPU、Canvas、WebGL 一次返回。不是设备序列号。 */
|
|
84
|
+
getEnvironmentInfo(callback) {
|
|
85
|
+
const promise = Promise.all([
|
|
86
|
+
this.getInfo().catch(() => null),
|
|
87
|
+
this.getSystemInfo().catch(() => null),
|
|
88
|
+
this.getCpuInfo(),
|
|
89
|
+
this.getCanvasRenderInfo(),
|
|
90
|
+
this.getWebGlInfo(),
|
|
91
|
+
]).then(([device, system, cpu, canvas, webgl]) => ({
|
|
92
|
+
device: toEnvironmentDevice(device, system),
|
|
93
|
+
cpu,
|
|
94
|
+
canvas,
|
|
95
|
+
webgl,
|
|
96
|
+
}));
|
|
97
|
+
return (0, runtime_1.withCallback)(promise, callback);
|
|
98
|
+
},
|
|
51
99
|
getAndroidId(callback) {
|
|
52
100
|
return (0, runtime_1.withCallback)((0, runtime_1.invokeNative)('getAndroidId'), callback);
|
|
53
101
|
},
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readNavigatorCpu = readNavigatorCpu;
|
|
4
|
+
exports.readCanvasRenderInfo = readCanvasRenderInfo;
|
|
5
|
+
exports.readWebGlInfo = readWebGlInfo;
|
|
6
|
+
const CANVAS_WIDTH = 240;
|
|
7
|
+
const CANVAS_HEIGHT = 60;
|
|
8
|
+
/** WebView 上报的逻辑核心数。浏览器可以压低这个值,它不是硬件序列号。 */
|
|
9
|
+
function readNavigatorCpu() {
|
|
10
|
+
const cores = typeof navigator !== 'undefined' ? navigator.hardwareConcurrency : 0;
|
|
11
|
+
const logicalCores = typeof cores === 'number' && Number.isFinite(cores) && cores > 0 ? Math.floor(cores) : 0;
|
|
12
|
+
return { logicalCores, supported: logicalCores > 0 };
|
|
13
|
+
}
|
|
14
|
+
/** 固定图形的绘制摘要。同一机型经常相同,也不能在卸载重装后当作设备序列号。 */
|
|
15
|
+
function readCanvasRenderInfo() {
|
|
16
|
+
const empty = { supported: false, digest: '', width: 0, height: 0 };
|
|
17
|
+
if (typeof document === 'undefined')
|
|
18
|
+
return empty;
|
|
19
|
+
const canvas = document.createElement('canvas');
|
|
20
|
+
canvas.width = CANVAS_WIDTH;
|
|
21
|
+
canvas.height = CANVAS_HEIGHT;
|
|
22
|
+
const ctx = canvas.getContext('2d');
|
|
23
|
+
if (!ctx)
|
|
24
|
+
return empty;
|
|
25
|
+
ctx.fillStyle = '#f60';
|
|
26
|
+
ctx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
|
27
|
+
ctx.fillStyle = '#069';
|
|
28
|
+
ctx.font = '14px Arial';
|
|
29
|
+
ctx.textBaseline = 'alphabetic';
|
|
30
|
+
ctx.fillText('ota-canvas', 2, 20);
|
|
31
|
+
ctx.strokeStyle = 'rgba(102, 204, 0, 0.7)';
|
|
32
|
+
ctx.beginPath();
|
|
33
|
+
ctx.arc(50, 40, 12, 0, Math.PI * 2);
|
|
34
|
+
ctx.stroke();
|
|
35
|
+
let url = '';
|
|
36
|
+
try {
|
|
37
|
+
url = canvas.toDataURL('image/png');
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return empty;
|
|
41
|
+
}
|
|
42
|
+
if (!url)
|
|
43
|
+
return empty;
|
|
44
|
+
return {
|
|
45
|
+
supported: true,
|
|
46
|
+
digest: fnv1a(url),
|
|
47
|
+
width: CANVAS_WIDTH,
|
|
48
|
+
height: CANVAS_HEIGHT,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** 当前页面被允许看到的 WebGL 字符串。iOS 通常只给出通用的 Apple GPU。 */
|
|
52
|
+
function readWebGlInfo() {
|
|
53
|
+
const empty = { supported: false, vendor: '', renderer: '', version: '' };
|
|
54
|
+
if (typeof document === 'undefined')
|
|
55
|
+
return empty;
|
|
56
|
+
const canvas = document.createElement('canvas');
|
|
57
|
+
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
|
58
|
+
if (!isWebGlContext(gl))
|
|
59
|
+
return empty;
|
|
60
|
+
const debug = gl.getExtension('WEBGL_debug_renderer_info');
|
|
61
|
+
const vendor = paramString(gl, debug ? debug.UNMASKED_VENDOR_WEBGL : gl.VENDOR);
|
|
62
|
+
const renderer = paramString(gl, debug ? debug.UNMASKED_RENDERER_WEBGL : gl.RENDERER);
|
|
63
|
+
const version = paramString(gl, gl.VERSION);
|
|
64
|
+
const lose = gl.getExtension('WEBGL_lose_context');
|
|
65
|
+
lose?.loseContext();
|
|
66
|
+
return { supported: true, vendor, renderer, version };
|
|
67
|
+
}
|
|
68
|
+
function isWebGlContext(value) {
|
|
69
|
+
return !!value && typeof value.getParameter === 'function';
|
|
70
|
+
}
|
|
71
|
+
function paramString(gl, name) {
|
|
72
|
+
const value = gl.getParameter(name);
|
|
73
|
+
return typeof value === 'string' ? value : '';
|
|
74
|
+
}
|
|
75
|
+
function fnv1a(text) {
|
|
76
|
+
let hash = 0x811c9dc5;
|
|
77
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
78
|
+
hash ^= text.charCodeAt(i);
|
|
79
|
+
hash = Math.imul(hash, 0x01000193);
|
|
80
|
+
}
|
|
81
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
82
|
+
}
|
package/dist/native.d.ts
CHANGED
|
@@ -59,7 +59,16 @@ export declare const Native: {
|
|
|
59
59
|
getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
|
|
60
60
|
getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
|
|
61
61
|
getSystemInfo(callback?: import("./runtime").NativeCallback<import("./types").SystemInfo>): Promise<import("./types").SystemInfo>;
|
|
62
|
-
|
|
62
|
+
getCpuInfo(callback?: import("./runtime").NativeCallback<import("./types").CpuInfo>): Promise<import("./types").CpuInfo>;
|
|
63
|
+
getCanvasRenderInfo(callback?: import("./runtime").NativeCallback<import("./types").CanvasRenderInfo>): Promise<import("./types").CanvasRenderInfo>;
|
|
64
|
+
getWebGlInfo(callback?: import("./runtime").NativeCallback<import("./types").WebGlInfo>): Promise<import("./types").WebGlInfo>;
|
|
65
|
+
getEnvironmentInfo(callback?: import("./runtime").NativeCallback<import("./types").EnvironmentInfo>): Promise<{
|
|
66
|
+
device: import("./types").EnvironmentDeviceInfo;
|
|
67
|
+
cpu: import("./types").CpuInfo;
|
|
68
|
+
canvas: import("./types").CanvasRenderInfo;
|
|
69
|
+
webgl: import("./types").WebGlInfo;
|
|
70
|
+
}>;
|
|
71
|
+
getAndroidId(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<import("./types").DeviceIdentifiers, "androidId" | "collectAllowed">>;
|
|
63
72
|
getImei(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
64
73
|
getDeviceSerial(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
65
74
|
getIdentifiers(callback?: import("./runtime").NativeCallback<import("./types").DeviceIdentifiers>): Promise<import("./types").DeviceIdentifiers>;
|
|
@@ -214,7 +223,7 @@ export declare const Native: {
|
|
|
214
223
|
readonly Push: {
|
|
215
224
|
getToken(callback?: import("./runtime").NativeCallback<import("./types").PushTokenResult>): Promise<import("./types").PushTokenResult>;
|
|
216
225
|
};
|
|
217
|
-
readonly sdkVersion: "1.
|
|
226
|
+
readonly sdkVersion: "1.6.0";
|
|
218
227
|
readonly getPlatform: typeof getPlatform;
|
|
219
228
|
readonly isNativePlatform: typeof isNativePlatform;
|
|
220
229
|
readonly isNativeBridgeAvailable: typeof isNativeBridgeAvailable;
|
|
@@ -271,7 +280,16 @@ export declare const Native: {
|
|
|
271
280
|
getOrientation(callback?: import("./runtime").NativeCallback<import("./types").OrientationInfo>): Promise<import("./types").OrientationInfo>;
|
|
272
281
|
getLockStatus(callback?: import("./runtime").NativeCallback<import("./types").LockStatus>): Promise<import("./types").LockStatus>;
|
|
273
282
|
getSystemInfo(callback?: import("./runtime").NativeCallback<import("./types").SystemInfo>): Promise<import("./types").SystemInfo>;
|
|
274
|
-
|
|
283
|
+
getCpuInfo(callback?: import("./runtime").NativeCallback<import("./types").CpuInfo>): Promise<import("./types").CpuInfo>;
|
|
284
|
+
getCanvasRenderInfo(callback?: import("./runtime").NativeCallback<import("./types").CanvasRenderInfo>): Promise<import("./types").CanvasRenderInfo>;
|
|
285
|
+
getWebGlInfo(callback?: import("./runtime").NativeCallback<import("./types").WebGlInfo>): Promise<import("./types").WebGlInfo>;
|
|
286
|
+
getEnvironmentInfo(callback?: import("./runtime").NativeCallback<import("./types").EnvironmentInfo>): Promise<{
|
|
287
|
+
device: import("./types").EnvironmentDeviceInfo;
|
|
288
|
+
cpu: import("./types").CpuInfo;
|
|
289
|
+
canvas: import("./types").CanvasRenderInfo;
|
|
290
|
+
webgl: import("./types").WebGlInfo;
|
|
291
|
+
}>;
|
|
292
|
+
getAndroidId(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<import("./types").DeviceIdentifiers, "androidId" | "collectAllowed">>;
|
|
275
293
|
getImei(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
276
294
|
getDeviceSerial(callback?: import("./runtime").NativeCallback<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<import("./types").DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
277
295
|
getIdentifiers(callback?: import("./runtime").NativeCallback<import("./types").DeviceIdentifiers>): Promise<import("./types").DeviceIdentifiers>;
|
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, PhoneStatePermissionResult, 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';
|
|
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, 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;
|
|
@@ -21,7 +21,20 @@ export declare const Device: {
|
|
|
21
21
|
getOrientation(callback?: NativeCallback<OrientationInfo>): Promise<OrientationInfo>;
|
|
22
22
|
getLockStatus(callback?: NativeCallback<LockStatus>): Promise<LockStatus>;
|
|
23
23
|
getSystemInfo(callback?: NativeCallback<SystemInfo>): Promise<SystemInfo>;
|
|
24
|
-
|
|
24
|
+
/** 逻辑核心数。Android / iOS 读系统值;Harmony 与浏览器预览读 WebView 的 hardwareConcurrency。 */
|
|
25
|
+
getCpuInfo(callback?: NativeCallback<CpuInfo>): Promise<CpuInfo>;
|
|
26
|
+
/** 当前 WebView 绘制固定图形后的摘要。不是设备序列号。 */
|
|
27
|
+
getCanvasRenderInfo(callback?: NativeCallback<CanvasRenderInfo>): Promise<CanvasRenderInfo>;
|
|
28
|
+
/** 当前 WebView 允许页面看到的 WebGL 厂商、渲染器和版本。 */
|
|
29
|
+
getWebGlInfo(callback?: NativeCallback<WebGlInfo>): Promise<WebGlInfo>;
|
|
30
|
+
/** 机型、系统版本、CPU、Canvas、WebGL 一次返回。不是设备序列号。 */
|
|
31
|
+
getEnvironmentInfo(callback?: NativeCallback<EnvironmentInfo>): Promise<{
|
|
32
|
+
device: EnvironmentDeviceInfo;
|
|
33
|
+
cpu: CpuInfo;
|
|
34
|
+
canvas: CanvasRenderInfo;
|
|
35
|
+
webgl: WebGlInfo;
|
|
36
|
+
}>;
|
|
37
|
+
getAndroidId(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "androidId">>): Promise<Pick<DeviceIdentifiers, "androidId" | "collectAllowed">>;
|
|
25
38
|
getImei(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>): Promise<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "imei">>;
|
|
26
39
|
getDeviceSerial(callback?: NativeCallback<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>): Promise<Pick<DeviceIdentifiers, "collectAllowed" | "phoneStatePermissionGranted" | "serial">>;
|
|
27
40
|
getIdentifiers(callback?: NativeCallback<DeviceIdentifiers>): Promise<DeviceIdentifiers>;
|
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { invokeNative, withCallback } from './runtime';
|
|
2
|
+
import { readCanvasRenderInfo, readNavigatorCpu, readWebGlInfo } from './webview-signals';
|
|
3
|
+
function toEnvironmentDevice(device, system) {
|
|
4
|
+
return {
|
|
5
|
+
os: firstText(system?.os, system?.platform),
|
|
6
|
+
osVersion: firstText(system?.release, system?.osVersion, device?.systemVersion, device?.osFullName),
|
|
7
|
+
manufacturer: firstText(device?.manufacturer),
|
|
8
|
+
brand: firstText(device?.brand),
|
|
9
|
+
model: firstText(device?.model),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function firstText(...values) {
|
|
13
|
+
for (const value of values) {
|
|
14
|
+
if (typeof value === 'string' && value.trim())
|
|
15
|
+
return value.trim();
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
2
19
|
function asBrowserOptions(urlOrOptions) {
|
|
3
20
|
return typeof urlOrOptions === 'string' ? { url: urlOrOptions } : urlOrOptions;
|
|
4
21
|
}
|
|
@@ -45,6 +62,37 @@ export const Device = {
|
|
|
45
62
|
getSystemInfo(callback) {
|
|
46
63
|
return withCallback(invokeNative('getSystemInfo'), callback);
|
|
47
64
|
},
|
|
65
|
+
/** 逻辑核心数。Android / iOS 读系统值;Harmony 与浏览器预览读 WebView 的 hardwareConcurrency。 */
|
|
66
|
+
getCpuInfo(callback) {
|
|
67
|
+
const promise = invokeNative('getCpuInfo')
|
|
68
|
+
.then((info) => (info.supported && info.logicalCores > 0 ? info : readNavigatorCpu()))
|
|
69
|
+
.catch(() => readNavigatorCpu());
|
|
70
|
+
return withCallback(promise, callback);
|
|
71
|
+
},
|
|
72
|
+
/** 当前 WebView 绘制固定图形后的摘要。不是设备序列号。 */
|
|
73
|
+
getCanvasRenderInfo(callback) {
|
|
74
|
+
return withCallback(Promise.resolve(readCanvasRenderInfo()), callback);
|
|
75
|
+
},
|
|
76
|
+
/** 当前 WebView 允许页面看到的 WebGL 厂商、渲染器和版本。 */
|
|
77
|
+
getWebGlInfo(callback) {
|
|
78
|
+
return withCallback(Promise.resolve(readWebGlInfo()), callback);
|
|
79
|
+
},
|
|
80
|
+
/** 机型、系统版本、CPU、Canvas、WebGL 一次返回。不是设备序列号。 */
|
|
81
|
+
getEnvironmentInfo(callback) {
|
|
82
|
+
const promise = Promise.all([
|
|
83
|
+
this.getInfo().catch(() => null),
|
|
84
|
+
this.getSystemInfo().catch(() => null),
|
|
85
|
+
this.getCpuInfo(),
|
|
86
|
+
this.getCanvasRenderInfo(),
|
|
87
|
+
this.getWebGlInfo(),
|
|
88
|
+
]).then(([device, system, cpu, canvas, webgl]) => ({
|
|
89
|
+
device: toEnvironmentDevice(device, system),
|
|
90
|
+
cpu,
|
|
91
|
+
canvas,
|
|
92
|
+
webgl,
|
|
93
|
+
}));
|
|
94
|
+
return withCallback(promise, callback);
|
|
95
|
+
},
|
|
48
96
|
getAndroidId(callback) {
|
|
49
97
|
return withCallback(invokeNative('getAndroidId'), callback);
|
|
50
98
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -342,6 +342,47 @@ export interface SystemInfo {
|
|
|
342
342
|
timezone: string;
|
|
343
343
|
abi: string;
|
|
344
344
|
}
|
|
345
|
+
/** Device.getCpuInfo():逻辑核心数。不是设备序列号。 */
|
|
346
|
+
export interface CpuInfo {
|
|
347
|
+
logicalCores: number;
|
|
348
|
+
/** Harmony 原生侧没有公开接口时为 false,JS 会再读 WebView 的 hardwareConcurrency */
|
|
349
|
+
supported: boolean;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Device.getCanvasRenderInfo():当前 WebView 对固定图形的绘制摘要。
|
|
353
|
+
* 同一机型经常相同,WebView 或驱动更新后可能变化。
|
|
354
|
+
*/
|
|
355
|
+
export interface CanvasRenderInfo {
|
|
356
|
+
supported: boolean;
|
|
357
|
+
digest: string;
|
|
358
|
+
width: number;
|
|
359
|
+
height: number;
|
|
360
|
+
}
|
|
361
|
+
/** Device.getWebGlInfo():当前 WebView 允许页面看到的 WebGL 字符串。 */
|
|
362
|
+
export interface WebGlInfo {
|
|
363
|
+
supported: boolean;
|
|
364
|
+
vendor: string;
|
|
365
|
+
renderer: string;
|
|
366
|
+
version: string;
|
|
367
|
+
}
|
|
368
|
+
/** Device.getEnvironmentInfo() 里的机型与系统。不是设备序列号。 */
|
|
369
|
+
export interface EnvironmentDeviceInfo {
|
|
370
|
+
/** Android / iOS / HarmonyOS */
|
|
371
|
+
os: string;
|
|
372
|
+
/** Android 为系统版本号,如 14;iOS 为系统版本;Harmony 为系统全名 */
|
|
373
|
+
osVersion: string;
|
|
374
|
+
manufacturer: string;
|
|
375
|
+
brand: string;
|
|
376
|
+
/** Android / Harmony 为营销名;iOS 为 iPhone、iPad 这类机型类 */
|
|
377
|
+
model: string;
|
|
378
|
+
}
|
|
379
|
+
/** Device.getEnvironmentInfo():机型、系统、CPU、Canvas、WebGL 一次返回。不是设备序列号。 */
|
|
380
|
+
export interface EnvironmentInfo {
|
|
381
|
+
device: EnvironmentDeviceInfo;
|
|
382
|
+
cpu: CpuInfo;
|
|
383
|
+
canvas: CanvasRenderInfo;
|
|
384
|
+
webgl: WebGlInfo;
|
|
385
|
+
}
|
|
345
386
|
export interface SafeAreaInsets {
|
|
346
387
|
top: number;
|
|
347
388
|
bottom: number;
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CanvasRenderInfo, CpuInfo, WebGlInfo } from './types';
|
|
2
|
+
/** WebView 上报的逻辑核心数。浏览器可以压低这个值,它不是硬件序列号。 */
|
|
3
|
+
export declare function readNavigatorCpu(): CpuInfo;
|
|
4
|
+
/** 固定图形的绘制摘要。同一机型经常相同,也不能在卸载重装后当作设备序列号。 */
|
|
5
|
+
export declare function readCanvasRenderInfo(): CanvasRenderInfo;
|
|
6
|
+
/** 当前页面被允许看到的 WebGL 字符串。iOS 通常只给出通用的 Apple GPU。 */
|
|
7
|
+
export declare function readWebGlInfo(): WebGlInfo;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const CANVAS_WIDTH = 240;
|
|
2
|
+
const CANVAS_HEIGHT = 60;
|
|
3
|
+
/** WebView 上报的逻辑核心数。浏览器可以压低这个值,它不是硬件序列号。 */
|
|
4
|
+
export function readNavigatorCpu() {
|
|
5
|
+
const cores = typeof navigator !== 'undefined' ? navigator.hardwareConcurrency : 0;
|
|
6
|
+
const logicalCores = typeof cores === 'number' && Number.isFinite(cores) && cores > 0 ? Math.floor(cores) : 0;
|
|
7
|
+
return { logicalCores, supported: logicalCores > 0 };
|
|
8
|
+
}
|
|
9
|
+
/** 固定图形的绘制摘要。同一机型经常相同,也不能在卸载重装后当作设备序列号。 */
|
|
10
|
+
export function readCanvasRenderInfo() {
|
|
11
|
+
const empty = { supported: false, digest: '', width: 0, height: 0 };
|
|
12
|
+
if (typeof document === 'undefined')
|
|
13
|
+
return empty;
|
|
14
|
+
const canvas = document.createElement('canvas');
|
|
15
|
+
canvas.width = CANVAS_WIDTH;
|
|
16
|
+
canvas.height = CANVAS_HEIGHT;
|
|
17
|
+
const ctx = canvas.getContext('2d');
|
|
18
|
+
if (!ctx)
|
|
19
|
+
return empty;
|
|
20
|
+
ctx.fillStyle = '#f60';
|
|
21
|
+
ctx.fillRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
|
|
22
|
+
ctx.fillStyle = '#069';
|
|
23
|
+
ctx.font = '14px Arial';
|
|
24
|
+
ctx.textBaseline = 'alphabetic';
|
|
25
|
+
ctx.fillText('ota-canvas', 2, 20);
|
|
26
|
+
ctx.strokeStyle = 'rgba(102, 204, 0, 0.7)';
|
|
27
|
+
ctx.beginPath();
|
|
28
|
+
ctx.arc(50, 40, 12, 0, Math.PI * 2);
|
|
29
|
+
ctx.stroke();
|
|
30
|
+
let url = '';
|
|
31
|
+
try {
|
|
32
|
+
url = canvas.toDataURL('image/png');
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return empty;
|
|
36
|
+
}
|
|
37
|
+
if (!url)
|
|
38
|
+
return empty;
|
|
39
|
+
return {
|
|
40
|
+
supported: true,
|
|
41
|
+
digest: fnv1a(url),
|
|
42
|
+
width: CANVAS_WIDTH,
|
|
43
|
+
height: CANVAS_HEIGHT,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** 当前页面被允许看到的 WebGL 字符串。iOS 通常只给出通用的 Apple GPU。 */
|
|
47
|
+
export function readWebGlInfo() {
|
|
48
|
+
const empty = { supported: false, vendor: '', renderer: '', version: '' };
|
|
49
|
+
if (typeof document === 'undefined')
|
|
50
|
+
return empty;
|
|
51
|
+
const canvas = document.createElement('canvas');
|
|
52
|
+
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
|
53
|
+
if (!isWebGlContext(gl))
|
|
54
|
+
return empty;
|
|
55
|
+
const debug = gl.getExtension('WEBGL_debug_renderer_info');
|
|
56
|
+
const vendor = paramString(gl, debug ? debug.UNMASKED_VENDOR_WEBGL : gl.VENDOR);
|
|
57
|
+
const renderer = paramString(gl, debug ? debug.UNMASKED_RENDERER_WEBGL : gl.RENDERER);
|
|
58
|
+
const version = paramString(gl, gl.VERSION);
|
|
59
|
+
const lose = gl.getExtension('WEBGL_lose_context');
|
|
60
|
+
lose?.loseContext();
|
|
61
|
+
return { supported: true, vendor, renderer, version };
|
|
62
|
+
}
|
|
63
|
+
function isWebGlContext(value) {
|
|
64
|
+
return !!value && typeof value.getParameter === 'function';
|
|
65
|
+
}
|
|
66
|
+
function paramString(gl, name) {
|
|
67
|
+
const value = gl.getParameter(name);
|
|
68
|
+
return typeof value === 'string' ? value : '';
|
|
69
|
+
}
|
|
70
|
+
function fnv1a(text) {
|
|
71
|
+
let hash = 0x811c9dc5;
|
|
72
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
73
|
+
hash ^= text.charCodeAt(i);
|
|
74
|
+
hash = Math.imul(hash, 0x01000193);
|
|
75
|
+
}
|
|
76
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
77
|
+
}
|
package/docs/USAGE.md
CHANGED
|
@@ -50,8 +50,10 @@ if (!Native.isNativePlatform()) {
|
|
|
50
50
|
| 打开网页 | `Browser.open('https://...')` |
|
|
51
51
|
| 读安全区 | `Viewport.getSafeAreaInsets()` |
|
|
52
52
|
| 读设备信息 | `Device.getInfo()` |
|
|
53
|
-
| 读设备标识(ID/IMEI
|
|
53
|
+
| 读设备标识(ID/IMEI/硬件序列号) | `Device.getIdentifiers()`(须 `collectDeviceIdsAfterConsent`) |
|
|
54
|
+
| 读壳生成的设备序列号 | `Device.getInstallDeviceId()`(UUID v4,与签名证书无关,不需要同意开关) |
|
|
54
55
|
| 读分辨率 / 方向 / 锁屏 | `Device.getScreenInfo()` / `getOrientation()` / `getLockStatus()` |
|
|
56
|
+
| 读机型 / 系统 / CPU / Canvas / WebGL | `Device.getEnvironmentInfo()` 一次返回(含系统版本、厂商、型号);也可分别调用 `getInfo()` / `getSystemInfo()` / `getCpuInfo()` / `getCanvasRenderInfo()` / `getWebGlInfo()` |
|
|
55
57
|
| 发通知 | `Notification.show({ title, body })` |
|
|
56
58
|
| 剪贴板 / 分享 | `Clipboard.set('hi')` / `Share.open({ text, url })` |
|
|
57
59
|
| 扫码 / 拍照 | `Scan.scan()` / `Picker.takePhoto()` |
|
|
@@ -958,7 +960,7 @@ Device.requestPhoneStatePermission().then(function () {
|
|
|
958
960
|
|
|
959
961
|
#### `Device.getInstallDeviceId()`
|
|
960
962
|
|
|
961
|
-
壳在第一次启动时生成 32
|
|
963
|
+
壳在第一次启动时生成 32 位十六进制设备序列号(UUID v4)并保存。值由安全随机数产生,与签名证书、`ANDROID_ID` / IDFV / ODID 无关,也不受 `collectDeviceIdsAfterConsent` 控制。同一安装上的覆盖更新保持不变。iOS 写在仅本机的 Keychain 中,同一 Bundle ID、同一开发者 Team 卸载后重装仍是原值,换机备份不会把序列号复制到另一台设备。Android 写在应用私有偏好中,并排除云备份和换机迁移;覆盖安装不变,卸载重装会生成新值。Harmony 写在应用 preferences 中,覆盖安装不变,卸载重装会生成新值。
|
|
962
964
|
|
|
963
965
|
```javascript
|
|
964
966
|
Device.getInstallDeviceId().then(function (result) {
|
|
@@ -1058,6 +1060,35 @@ Device.getSystemInfo().then(console.log);
|
|
|
1058
1060
|
}
|
|
1059
1061
|
```
|
|
1060
1062
|
|
|
1063
|
+
#### `Device.getEnvironmentInfo()`
|
|
1064
|
+
|
|
1065
|
+
一次返回机型、系统版本、CPU、Canvas、WebGL。这些描述当前环境,不是设备序列号。同一机型经常相同,系统或 WebView 更新后也可能变化。需要单字段时仍可调用 `getInfo()`、`getSystemInfo()`、`getCpuInfo()`、`getCanvasRenderInfo()`、`getWebGlInfo()`。
|
|
1066
|
+
|
|
1067
|
+
```javascript
|
|
1068
|
+
Device.getEnvironmentInfo().then(console.log);
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
```json
|
|
1072
|
+
{
|
|
1073
|
+
"device": {
|
|
1074
|
+
"os": "Android",
|
|
1075
|
+
"osVersion": "14",
|
|
1076
|
+
"manufacturer": "Xiaomi",
|
|
1077
|
+
"brand": "Xiaomi",
|
|
1078
|
+
"model": "Xiaomi 15"
|
|
1079
|
+
},
|
|
1080
|
+
"cpu": { "logicalCores": 8, "supported": true },
|
|
1081
|
+
"canvas": { "supported": true, "digest": "a1b2c3d4", "width": 240, "height": 60 },
|
|
1082
|
+
"webgl": { "supported": true, "vendor": "Qualcomm", "renderer": "Adreno (TM) 740", "version": "WebGL 1.0" }
|
|
1083
|
+
}
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
`device.osVersion` 在 Android 上是系统版本号,iOS 上是系统版本,Harmony 上是系统全名。`device.model` 在 Android 和 Harmony 上优先用营销名;iOS 只能拿到 `iPhone`、`iPad` 这类机型类。
|
|
1087
|
+
|
|
1088
|
+
`cpu` 在 Android、iOS 上走壳的 `getCpuInfo`,返回系统逻辑核心数。Harmony 没有公开的原生接口,以及不在壳里的浏览器预览,改为读 WebView 的 `navigator.hardwareConcurrency`。
|
|
1089
|
+
|
|
1090
|
+
`canvas` 和 `webgl` 不经过原生桥,直接读当前页面的 WebView。Canvas 是固定图形的摘要。WebGL 只包含页面被允许看到的厂商、渲染器和版本;iOS 上渲染器通常是通用的 Apple GPU。
|
|
1091
|
+
|
|
1061
1092
|
#### `Config.getNativeConfig()` / `Config.setNativeFeatures(options)`
|
|
1062
1093
|
|
|
1063
1094
|
```typescript
|
package/ota-native-bridge.js
CHANGED