@taole/dev-helper 0.1.10 → 0.1.12

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.
@@ -66,6 +66,7 @@
66
66
  this._alink_link = '';
67
67
  this._alink_fin_5s = '';
68
68
  this._fin5sTimer = null;
69
+ this._fin5sVisHandler = null;
69
70
  this._template = null;
70
71
  this._alink = null;
71
72
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -81,7 +82,7 @@
81
82
  this._clipboardTextTimer = null;
82
83
  }
83
84
  _log(...args) {
84
- if (this._debug) {
85
+ if (this._debug || true) {
85
86
  console.log('open-diandian:[' + this._id + ']', ...args);
86
87
  }
87
88
  }
@@ -129,16 +130,29 @@
129
130
  tmplnk.click();
130
131
  this._log('open-diandian: wx-open-launch-app error, go to fallback link', e, this._alink_fallback);
131
132
  if (this._alink_fin_5s) {
132
- if (this._fin5sTimer) {
133
- clearTimeout(this._fin5sTimer);
134
- }
133
+ this._cancelFinalFallback();
134
+ this._fin5sVisHandler = () => {
135
+ if (document.hidden) {
136
+ this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
137
+ this._cancelFinalFallback();
138
+ }
139
+ };
140
+ document.addEventListener('visibilitychange', this._fin5sVisHandler);
135
141
  this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
136
142
  this._fin5sTimer = setTimeout(() => {
137
143
  this._fin5sTimer = null;
144
+ if (this._fin5sVisHandler) {
145
+ document.removeEventListener('visibilitychange', this._fin5sVisHandler);
146
+ this._fin5sVisHandler = null;
147
+ }
138
148
  if (!this._isConnected) {
139
149
  this._log('open-diandian: disconnected, skip final fallback');
140
150
  return;
141
151
  }
152
+ if (document.hidden) {
153
+ this._log('open-diandian: page hidden when timer fired, skip final fallback');
154
+ return;
155
+ }
142
156
  this._log('open-diandian: final fallback go', this._alink_fin_5s);
143
157
  var lnkFinal = document.createElement("a");
144
158
  lnkFinal.href = this._alink_fin_5s;
@@ -146,6 +160,14 @@
146
160
  }, 5000);
147
161
  }
148
162
  });
163
+ this._openAppTag.addEventListener('launch', (e) => {
164
+ this._log('open-diandian: wx-open-launch-app launch', e);
165
+ this.dispatchEvent(new CustomEvent('launch', {
166
+ detail: e.detail, // 如需透传微信事件数据
167
+ bubbles: true,
168
+ composed: true,
169
+ }));
170
+ });
149
171
  } else {
150
172
  this._updateTagAttr();
151
173
  }
@@ -212,10 +234,17 @@
212
234
  this._alink.remove();
213
235
  this._alink = null;
214
236
  }
237
+ this._cancelFinalFallback();
238
+ }
239
+ _cancelFinalFallback() {
215
240
  if (this._fin5sTimer) {
216
241
  clearTimeout(this._fin5sTimer);
217
242
  this._fin5sTimer = null;
218
243
  }
244
+ if (this._fin5sVisHandler) {
245
+ document.removeEventListener('visibilitychange', this._fin5sVisHandler);
246
+ this._fin5sVisHandler = null;
247
+ }
219
248
  }
220
249
  _initClipboardText() {
221
250
  // 延迟20ms执行,如果20ms后卸载了,直接不执行了
@@ -61,6 +61,7 @@ function defineTag() {
61
61
  this._alink_link = '';
62
62
  this._alink_fin_5s = '';
63
63
  this._fin5sTimer = null;
64
+ this._fin5sVisHandler = null;
64
65
  this._template = null;
65
66
  this._alink = null;
66
67
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -76,7 +77,7 @@ function defineTag() {
76
77
  this._clipboardTextTimer = null;
77
78
  }
78
79
  _log(...args) {
79
- if (this._debug) {
80
+ if (this._debug || true) {
80
81
  console.log('open-diandian:[' + this._id + ']', ...args);
81
82
  }
82
83
  }
@@ -124,16 +125,29 @@ function defineTag() {
124
125
  tmplnk.click();
125
126
  this._log('open-diandian: wx-open-launch-app error, go to fallback link', e, this._alink_fallback);
126
127
  if (this._alink_fin_5s) {
127
- if (this._fin5sTimer) {
128
- clearTimeout(this._fin5sTimer);
129
- }
128
+ this._cancelFinalFallback();
129
+ this._fin5sVisHandler = () => {
130
+ if (document.hidden) {
131
+ this._log('open-diandian: page hidden, fallback succeeded, cancel final fallback');
132
+ this._cancelFinalFallback();
133
+ }
134
+ };
135
+ document.addEventListener('visibilitychange', this._fin5sVisHandler);
130
136
  this._log('open-diandian: schedule final fallback 5s later', this._alink_fin_5s);
131
137
  this._fin5sTimer = setTimeout(() => {
132
138
  this._fin5sTimer = null;
139
+ if (this._fin5sVisHandler) {
140
+ document.removeEventListener('visibilitychange', this._fin5sVisHandler);
141
+ this._fin5sVisHandler = null;
142
+ }
133
143
  if (!this._isConnected) {
134
144
  this._log('open-diandian: disconnected, skip final fallback');
135
145
  return;
136
146
  }
147
+ if (document.hidden) {
148
+ this._log('open-diandian: page hidden when timer fired, skip final fallback');
149
+ return;
150
+ }
137
151
  this._log('open-diandian: final fallback go', this._alink_fin_5s);
138
152
  var lnkFinal = document.createElement("a");
139
153
  lnkFinal.href = this._alink_fin_5s;
@@ -141,6 +155,14 @@ function defineTag() {
141
155
  }, 5000);
142
156
  }
143
157
  });
158
+ this._openAppTag.addEventListener('launch', (e) => {
159
+ this._log('open-diandian: wx-open-launch-app launch', e);
160
+ this.dispatchEvent(new CustomEvent('launch', {
161
+ detail: e.detail, // 如需透传微信事件数据
162
+ bubbles: true,
163
+ composed: true,
164
+ }));
165
+ });
144
166
  } else {
145
167
  this._updateTagAttr();
146
168
  }
@@ -207,10 +229,17 @@ function defineTag() {
207
229
  this._alink.remove();
208
230
  this._alink = null;
209
231
  }
232
+ this._cancelFinalFallback();
233
+ }
234
+ _cancelFinalFallback() {
210
235
  if (this._fin5sTimer) {
211
236
  clearTimeout(this._fin5sTimer);
212
237
  this._fin5sTimer = null;
213
238
  }
239
+ if (this._fin5sVisHandler) {
240
+ document.removeEventListener('visibilitychange', this._fin5sVisHandler);
241
+ this._fin5sVisHandler = null;
242
+ }
214
243
  }
215
244
  _initClipboardText() {
216
245
  // 延迟20ms执行,如果20ms后卸载了,直接不执行了
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",