@pisell/utils 1.0.41 → 1.0.42

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.
@@ -6,7 +6,7 @@ import regDeviceApi from "./regDeviceApi";
6
6
  * @param callback
7
7
  */
8
8
  export function webPrint(params, _callback, onError) {
9
- regDeviceApi().then(function (jsBridge) {
9
+ regDeviceApi(true).then(function (jsBridge) {
10
10
  jsBridge.callDeviceApi({
11
11
  apiName: "webPrint",
12
12
  params: params,
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
10
10
  calledByDevice: (a: { apiName: string; callback: Functon }) => void;
11
11
  };
12
12
 
13
- const regDeviceApi: () => Promise<ComposedJSBridge>;
13
+ const regDeviceApi: (isWebPrint?: boolean) => Promise<ComposedJSBridge>;
14
14
 
15
15
  export default regDeviceApi;
@@ -4,10 +4,12 @@ var iosRegStatus = false;
4
4
  var androidBridge;
5
5
  var iosBridge;
6
6
  var composedBridge;
7
- function regIosJsBridge(callback) {
7
+ function regIosJsBridge(callback, reject) {
8
8
  if (window.WebViewJavascriptBridge) {
9
9
  callback(window.WebViewJavascriptBridge);
10
10
  return;
11
+ } else {
12
+ reject();
11
13
  }
12
14
  if (window.WVJBCallbacks) {
13
15
  window.WVJBCallbacks.push(callback);
@@ -123,15 +125,23 @@ function getComposedBridge(deviceType) {
123
125
  };
124
126
  return composedBridge;
125
127
  }
126
- export default function regDeviceApi() {
128
+ export default function regDeviceApi(isWebPrint) {
127
129
  return new Promise(function (resolve, reject) {
130
+ // 旧版本只能用WebPrint
131
+ var isOld = !navigator.userAgent.includes('jsBridge');
132
+ if (isOld) {
133
+ if (!isWebPrint) {
134
+ reject();
135
+ return;
136
+ }
137
+ }
128
138
  if (isIos() && !iosRegStatus) {
129
139
  regIosJsBridge(function (bridge) {
130
140
  iosRegStatus = true;
131
141
  iosBridge = bridge;
132
142
  var realBridge = getComposedBridge('iphone');
133
143
  resolve(realBridge);
134
- });
144
+ }, reject);
135
145
  } else if (isIos() && iosRegStatus) {
136
146
  var realBridge = getComposedBridge('iphone');
137
147
  resolve(realBridge);
@@ -35,7 +35,7 @@ __export(jsBridge_exports, {
35
35
  module.exports = __toCommonJS(jsBridge_exports);
36
36
  var import_regDeviceApi = __toESM(require("./regDeviceApi"));
37
37
  function webPrint(params, callback, onError) {
38
- (0, import_regDeviceApi.default)().then((jsBridge) => {
38
+ (0, import_regDeviceApi.default)(true).then((jsBridge) => {
39
39
  jsBridge.callDeviceApi({
40
40
  apiName: "webPrint",
41
41
  params,
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
10
10
  calledByDevice: (a: { apiName: string; callback: Functon }) => void;
11
11
  };
12
12
 
13
- const regDeviceApi: () => Promise<ComposedJSBridge>;
13
+ const regDeviceApi: (isWebPrint?: boolean) => Promise<ComposedJSBridge>;
14
14
 
15
15
  export default regDeviceApi;
@@ -28,10 +28,12 @@ var iosRegStatus = false;
28
28
  var androidBridge;
29
29
  var iosBridge;
30
30
  var composedBridge;
31
- function regIosJsBridge(callback) {
31
+ function regIosJsBridge(callback, reject) {
32
32
  if (window.WebViewJavascriptBridge) {
33
33
  callback(window.WebViewJavascriptBridge);
34
34
  return;
35
+ } else {
36
+ reject();
35
37
  }
36
38
  if (window.WVJBCallbacks) {
37
39
  window.WVJBCallbacks.push(callback);
@@ -133,15 +135,22 @@ function getComposedBridge(deviceType) {
133
135
  };
134
136
  return composedBridge;
135
137
  }
136
- function regDeviceApi() {
138
+ function regDeviceApi(isWebPrint) {
137
139
  return new Promise((resolve, reject) => {
140
+ const isOld = !navigator.userAgent.includes("jsBridge");
141
+ if (isOld) {
142
+ if (!isWebPrint) {
143
+ reject();
144
+ return;
145
+ }
146
+ }
138
147
  if ((0, import_platform.isIos)() && !iosRegStatus) {
139
148
  regIosJsBridge((bridge) => {
140
149
  iosRegStatus = true;
141
150
  iosBridge = bridge;
142
151
  const realBridge = getComposedBridge("iphone");
143
152
  resolve(realBridge);
144
- });
153
+ }, reject);
145
154
  } else if ((0, import_platform.isIos)() && iosRegStatus) {
146
155
  const realBridge = getComposedBridge("iphone");
147
156
  resolve(realBridge);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "1.0.41",
3
+ "version": "1.0.42",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",