@taole/dev-helper 0.1.25 → 0.1.26

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.
@@ -227,9 +227,7 @@
227
227
  return;
228
228
  }
229
229
  this._log('open-diandian: final fallback go', this._alink_fin_5s);
230
- var lnkFinal = document.createElement("a");
231
- lnkFinal.href = this._alink_fin_5s;
232
- lnkFinal.click();
230
+ this._openFallbackLink(this._alink_fin_5s);
233
231
  }, 5000);
234
232
  }
235
233
  });
@@ -261,11 +259,7 @@
261
259
  if (document.hidden) {
262
260
  if (this._clickLink) {
263
261
  this._log("open app successfully");
264
- if (this._alink_click_timer) {
265
- clearTimeout(this._alink_click_timer);
266
- this._alink_click_timer = null;
267
- }
268
- this._clickLink = false;
262
+ this._cancelLaunchFallback();
269
263
  }
270
264
  }
271
265
  });
@@ -281,32 +275,44 @@
281
275
  }
282
276
  }
283
277
  _handleAlinkClick(event) {
278
+ this._writeClickboard();
279
+ this._cancelLaunchFallback();
280
+ if (this._alink_link === this._alink_fallback) {
281
+ // 没有可用的拉端链接,点击本身就是兜底。
282
+ if (this._useOpenInstall()) {
283
+ event.preventDefault();
284
+ this._wakeupOpenInstall();
285
+ }
286
+ return;
287
+ }
288
+ // 先使用原链接拉端,页面没有隐藏才执行兜底。
289
+ this._clickLink = true;
290
+ this._alink_click_timer = setTimeout(() => {
291
+ this._cancelLaunchFallback();
292
+ if (!this._isConnected || document.hidden) return;
293
+ this._log('open app timed out, run fallback');
294
+ this._openFallbackLink(this._alink_fallback);
295
+ }, this._fallbackTime);
296
+ }
297
+ _cancelLaunchFallback() {
298
+ clearTimeout(this._alink_click_timer);
299
+ this._alink_click_timer = null;
300
+ this._clickLink = false;
301
+ }
302
+ _openFallbackLink(href) {
284
303
  if (this._useOpenInstall()) {
285
- event.preventDefault();
286
304
  this._wakeupOpenInstall();
287
305
  return;
288
306
  }
289
- this._writeClickboard();
290
- if (this._alink_link != this._alink_fallback) {
291
- this._log("this._alink is clicked");
292
- // 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
293
- if (this._alink_click_timer) {
294
- clearTimeout(this._alink_click_timer);
295
- }
296
- this._clickLink = true;
297
- this._alink_click_timer = setTimeout(() => {
298
- this._log("3s timeout, open app failed, jump to fallback link");
299
- this._alink_click_timer = null;
300
- var tmplnk = document.createElement("a");
301
- tmplnk.href = this._alink_fallback;
302
- tmplnk.click();
303
- }, this._fallbackTime);
304
- }
307
+ const link = document.createElement('a');
308
+ link.href = href;
309
+ link.click();
305
310
  }
306
311
  disconnectedCallback() {
307
312
  this._log("disconnectedCallback");
308
313
  this._isConnected = false;
309
314
  this._openInstallPending = false;
315
+ this._cancelLaunchFallback();
310
316
  if (this._openAppTag) {
311
317
  this._openAppTag.remove();
312
318
  this._openAppTag = null;
@@ -520,7 +526,10 @@
520
526
  this._openAppTag.setAttribute('appid', this._appid);
521
527
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
522
528
  } else if (this._alink) {
523
- this._alink.href = this._alink_link;
529
+ // 开启 OpenInstall 时,由组件统一触发兜底,避免 Android Intent 直接跳转。
530
+ this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
531
+ ? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
532
+ : this._alink_link;
524
533
  }
525
534
  }
526
535
  };
@@ -222,9 +222,7 @@ function createOpenDiandianElementClass() {
222
222
  return;
223
223
  }
224
224
  this._log('open-diandian: final fallback go', this._alink_fin_5s);
225
- var lnkFinal = document.createElement("a");
226
- lnkFinal.href = this._alink_fin_5s;
227
- lnkFinal.click();
225
+ this._openFallbackLink(this._alink_fin_5s);
228
226
  }, 5000);
229
227
  }
230
228
  });
@@ -256,11 +254,7 @@ function createOpenDiandianElementClass() {
256
254
  if (document.hidden) {
257
255
  if (this._clickLink) {
258
256
  this._log("open app successfully");
259
- if (this._alink_click_timer) {
260
- clearTimeout(this._alink_click_timer);
261
- this._alink_click_timer = null;
262
- }
263
- this._clickLink = false;
257
+ this._cancelLaunchFallback();
264
258
  }
265
259
  }
266
260
  });
@@ -276,32 +270,44 @@ function createOpenDiandianElementClass() {
276
270
  }
277
271
  }
278
272
  _handleAlinkClick(event) {
273
+ this._writeClickboard();
274
+ this._cancelLaunchFallback();
275
+ if (this._alink_link === this._alink_fallback) {
276
+ // 没有可用的拉端链接,点击本身就是兜底。
277
+ if (this._useOpenInstall()) {
278
+ event.preventDefault();
279
+ this._wakeupOpenInstall();
280
+ }
281
+ return;
282
+ }
283
+ // 先使用原链接拉端,页面没有隐藏才执行兜底。
284
+ this._clickLink = true;
285
+ this._alink_click_timer = setTimeout(() => {
286
+ this._cancelLaunchFallback();
287
+ if (!this._isConnected || document.hidden) return;
288
+ this._log('open app timed out, run fallback');
289
+ this._openFallbackLink(this._alink_fallback);
290
+ }, this._fallbackTime);
291
+ }
292
+ _cancelLaunchFallback() {
293
+ clearTimeout(this._alink_click_timer);
294
+ this._alink_click_timer = null;
295
+ this._clickLink = false;
296
+ }
297
+ _openFallbackLink(href) {
279
298
  if (this._useOpenInstall()) {
280
- event.preventDefault();
281
299
  this._wakeupOpenInstall();
282
300
  return;
283
301
  }
284
- this._writeClickboard();
285
- if (this._alink_link != this._alink_fallback) {
286
- this._log("this._alink is clicked");
287
- // 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
288
- if (this._alink_click_timer) {
289
- clearTimeout(this._alink_click_timer);
290
- }
291
- this._clickLink = true;
292
- this._alink_click_timer = setTimeout(() => {
293
- this._log("3s timeout, open app failed, jump to fallback link");
294
- this._alink_click_timer = null;
295
- var tmplnk = document.createElement("a");
296
- tmplnk.href = this._alink_fallback;
297
- tmplnk.click();
298
- }, this._fallbackTime);
299
- }
302
+ const link = document.createElement('a');
303
+ link.href = href;
304
+ link.click();
300
305
  }
301
306
  disconnectedCallback() {
302
307
  this._log("disconnectedCallback")
303
308
  this._isConnected = false;
304
309
  this._openInstallPending = false;
310
+ this._cancelLaunchFallback();
305
311
  if (this._openAppTag) {
306
312
  this._openAppTag.remove();
307
313
  this._openAppTag = null;
@@ -515,7 +521,10 @@ function createOpenDiandianElementClass() {
515
521
  this._openAppTag.setAttribute('appid', this._appid);
516
522
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
517
523
  } else if (this._alink) {
518
- this._alink.href = this._alink_link;
524
+ // 开启 OpenInstall 时,由组件统一触发兜底,避免 Android Intent 直接跳转。
525
+ this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
526
+ ? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
527
+ : this._alink_link;
519
528
  }
520
529
  }
521
530
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "dev-helper": "./bin/dev-helper.js"