ota-native-bridge 1.6.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.
@@ -18,6 +18,9 @@
18
18
  if (global.HarmonyBridge && global.HarmonyBridge.postMessage) {
19
19
  return function (msg) { global.HarmonyBridge.postMessage(msg); };
20
20
  }
21
+ if (global.DesktopBridge && global.DesktopBridge.postMessage) {
22
+ return function (msg) { global.DesktopBridge.postMessage(msg); };
23
+ }
21
24
  return null;
22
25
  }
23
26
 
@@ -34,7 +37,11 @@
34
37
  });
35
38
  }
36
39
 
40
+ var previousCallback = global.__nativeBridgeCallback;
37
41
  global.__nativeBridgeCallback = function (id, success, payload) {
42
+ if (typeof previousCallback === 'function') {
43
+ previousCallback(id, success, payload);
44
+ }
38
45
  var item = pending[id];
39
46
  if (!item) return;
40
47
  delete pending[id];
@@ -101,6 +108,9 @@
101
108
  if (global.AndroidBridge && global.AndroidBridge.postMessage) return 'android';
102
109
  if (global.webkit && global.webkit.messageHandlers && global.webkit.messageHandlers.IOSBridge) return 'ios';
103
110
  if (global.HarmonyBridge && global.HarmonyBridge.postMessage) return 'harmony';
111
+ if (global.DesktopBridge && global.DesktopBridge.postMessage) {
112
+ return global.DesktopBridge.os === 'macos' ? 'macos' : 'windows';
113
+ }
104
114
  return 'web';
105
115
  }
106
116
 
@@ -121,6 +131,8 @@
121
131
  getInfo: function (cb) { return withCallback(invokeNative('getDeviceInfo'), cb); },
122
132
  getScreenInfo: function (cb) { return withCallback(invokeNative('getScreenInfo'), cb); },
123
133
  getOrientation: function (cb) { return withCallback(invokeNative('getOrientation'), cb); },
134
+ setOrientation: function (opts, cb) { return withCallback(invokeNative('setOrientation', { orientation: opts && opts.orientation }), cb); },
135
+ setFullscreen: function (opts, cb) { return withCallback(invokeNative('setFullscreen', { enabled: !!(opts && opts.enabled) }), cb); },
124
136
  getLockStatus: function (cb) { return withCallback(invokeNative('getLockStatus'), cb); },
125
137
  getSystemInfo: function (cb) { return withCallback(invokeNative('getSystemInfo'), cb); },
126
138
  getAndroidId: function (cb) { return withCallback(invokeNative('getAndroidId'), cb); },
@@ -161,6 +173,17 @@
161
173
  setBadgeCount: function (count, cb) { return withCallback(invokeNative('setBadgeCount', { count: count }), cb); }
162
174
  };
163
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
+
164
187
  var Ota = {
165
188
  checkResourceUpdate: function (url, cb) { return withCallback(invokeNative('checkResourceUpdate', url ? { url: url } : {}), cb); },
166
189
  applyResourceUpdate: function (url, cb) { return withCallback(invokeNative('applyResourceUpdate', { url: url }), cb); },
@@ -184,7 +207,20 @@
184
207
  setChannel: function (channel, cb) { return withCallback(invokeNative('setOtaChannel', { channel: channel || '' }), cb); },
185
208
  downloadAndInstallApk: function (url, cb) {
186
209
  return withCallback(invokeNative('downloadAndInstallApk', { url: url }), cb);
187
- }
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); }
188
224
  };
189
225
 
190
226
  var Browser = {
@@ -363,7 +399,7 @@
363
399
  };
364
400
 
365
401
  var plugins = {
366
- 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,
367
403
  Viewport: Viewport, Notification: Notification, Location: Location, Media: Media, Http: Http,
368
404
  Clipboard: Clipboard, Share: Share, Picker: Picker, Scan: Scan, Biometric: Biometric,
369
405
  Contacts: Contacts, Calendar: Calendar, Bluetooth: Bluetooth, Nfc: Nfc, Sensor: Sensor,
@@ -372,14 +408,16 @@
372
408
  };
373
409
 
374
410
  global.Native = {
375
- sdkVersion: '1.6.0',
411
+ sdkVersion: '1.8.0',
376
412
  getPlatform: getPlatform,
377
413
  isNativePlatform: isNativePlatform,
378
414
  isNativeBridgeAvailable: function () { return !!getNativeMessenger(); },
379
415
  whenReady: waitForBridge,
416
+ on: onNativeEvent,
380
417
  Plugins: plugins,
381
418
  App: App,
382
419
  Ota: Ota,
420
+ Migration: Migration,
383
421
  Browser: Browser,
384
422
  Device: Device,
385
423
  Config: Config,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ota-native-bridge",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "App OTA WebView 壳应用跨平台 Native Bridge TypeScript SDK(Android / iOS / HarmonyOS)",
5
5
  "keywords": [
6
6
  "ota",