@taole/dev-helper 0.1.26 → 0.1.27
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/dist/open-diandian.umd.js +38 -39
- package/open-diandian/index.js +38 -39
- package/package.json +1 -1
|
@@ -117,6 +117,7 @@
|
|
|
117
117
|
this._debug = false;
|
|
118
118
|
this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
|
|
119
119
|
this._openAppTag = null;
|
|
120
|
+
this._openInstallButton = null;
|
|
120
121
|
this._fallbackTime = 3000;
|
|
121
122
|
this._appid = '';
|
|
122
123
|
this._appInfo = null;
|
|
@@ -141,7 +142,6 @@
|
|
|
141
142
|
this._openInstall = null;
|
|
142
143
|
this._openInstallPromise = null;
|
|
143
144
|
this._openInstallKey = '';
|
|
144
|
-
this._openInstallPending = false;
|
|
145
145
|
}
|
|
146
146
|
_log(...args) {
|
|
147
147
|
if (this._debug) {
|
|
@@ -164,6 +164,14 @@
|
|
|
164
164
|
this._openAppTag = document.createElement('wx-open-launch-app');
|
|
165
165
|
this._openAppTag.style.background = "transparent";
|
|
166
166
|
this._openAppTag.style.opacity = 0;
|
|
167
|
+
this._openInstallButton = document.createElement('button');
|
|
168
|
+
this._openInstallButton.type = 'button';
|
|
169
|
+
this._openInstallButton.setAttribute('aria-label', '打开 App');
|
|
170
|
+
this._openInstallButton.style.width = '100%';
|
|
171
|
+
this._openInstallButton.style.height = '100%';
|
|
172
|
+
this._openInstallButton.addEventListener('click', () => {
|
|
173
|
+
if (this._useOpenInstall()) this._wakeupOpenInstall();
|
|
174
|
+
});
|
|
167
175
|
this._updateTagAttr();
|
|
168
176
|
|
|
169
177
|
var contentEle = document.createElement('div');
|
|
@@ -180,8 +188,9 @@
|
|
|
180
188
|
|
|
181
189
|
this._openAppTag.appendChild(scriptTag);
|
|
182
190
|
this._template.content.appendChild(this._openAppTag);
|
|
183
|
-
this.
|
|
184
|
-
this.shadowRoot.
|
|
191
|
+
this._template.content.appendChild(this._openInstallButton);
|
|
192
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
193
|
+
shadow.appendChild(this._template.content);
|
|
185
194
|
this._log('open-diandian: wx-open-launch-app appended');
|
|
186
195
|
// 监听打开app失败的情况,跳转fallback链接
|
|
187
196
|
this._openAppTag.addEventListener('error', (e) => {
|
|
@@ -190,10 +199,7 @@
|
|
|
190
199
|
bubbles: true,
|
|
191
200
|
composed: true,
|
|
192
201
|
}));
|
|
193
|
-
if (this._useOpenInstall())
|
|
194
|
-
this._wakeupOpenInstall();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
202
|
+
if (this._useOpenInstall()) return;
|
|
197
203
|
if (this._isHarmony || this._isSceneLink()) {
|
|
198
204
|
this._showOpenInBrowserHint();
|
|
199
205
|
return;
|
|
@@ -227,7 +233,7 @@
|
|
|
227
233
|
return;
|
|
228
234
|
}
|
|
229
235
|
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
230
|
-
this.
|
|
236
|
+
this._openLink(this._alink_fin_5s);
|
|
231
237
|
}, 5000);
|
|
232
238
|
}
|
|
233
239
|
});
|
|
@@ -250,8 +256,8 @@
|
|
|
250
256
|
this._alink.style.width = '100%';
|
|
251
257
|
this._alink.style.height = '100%';
|
|
252
258
|
this._template.content.appendChild(this._alink);
|
|
253
|
-
this.attachShadow({ mode: 'open' });
|
|
254
|
-
|
|
259
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
260
|
+
shadow.appendChild(this._template.content);
|
|
255
261
|
this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
|
|
256
262
|
this._log('open-diandian: open link appended');
|
|
257
263
|
this._clickLink = false;
|
|
@@ -275,14 +281,18 @@
|
|
|
275
281
|
}
|
|
276
282
|
}
|
|
277
283
|
_handleAlinkClick(event) {
|
|
284
|
+
const useOpenInstall = this._useOpenInstall();
|
|
285
|
+
if (useOpenInstall) {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
if (!this._openInstall) return;
|
|
288
|
+
}
|
|
278
289
|
this._writeClickboard();
|
|
279
290
|
this._cancelLaunchFallback();
|
|
291
|
+
if (useOpenInstall) {
|
|
292
|
+
this._wakeupOpenInstall();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
280
295
|
if (this._alink_link === this._alink_fallback) {
|
|
281
|
-
// 没有可用的拉端链接,点击本身就是兜底。
|
|
282
|
-
if (this._useOpenInstall()) {
|
|
283
|
-
event.preventDefault();
|
|
284
|
-
this._wakeupOpenInstall();
|
|
285
|
-
}
|
|
286
296
|
return;
|
|
287
297
|
}
|
|
288
298
|
// 先使用原链接拉端,页面没有隐藏才执行兜底。
|
|
@@ -291,7 +301,7 @@
|
|
|
291
301
|
this._cancelLaunchFallback();
|
|
292
302
|
if (!this._isConnected || document.hidden) return;
|
|
293
303
|
this._log('open app timed out, run fallback');
|
|
294
|
-
this.
|
|
304
|
+
this._openLink(this._alink_fallback);
|
|
295
305
|
}, this._fallbackTime);
|
|
296
306
|
}
|
|
297
307
|
_cancelLaunchFallback() {
|
|
@@ -299,11 +309,7 @@
|
|
|
299
309
|
this._alink_click_timer = null;
|
|
300
310
|
this._clickLink = false;
|
|
301
311
|
}
|
|
302
|
-
|
|
303
|
-
if (this._useOpenInstall()) {
|
|
304
|
-
this._wakeupOpenInstall();
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
312
|
+
_openLink(href) {
|
|
307
313
|
const link = document.createElement('a');
|
|
308
314
|
link.href = href;
|
|
309
315
|
link.click();
|
|
@@ -311,11 +317,12 @@
|
|
|
311
317
|
disconnectedCallback() {
|
|
312
318
|
this._log("disconnectedCallback");
|
|
313
319
|
this._isConnected = false;
|
|
314
|
-
this._openInstallPending = false;
|
|
315
320
|
this._cancelLaunchFallback();
|
|
316
321
|
if (this._openAppTag) {
|
|
317
322
|
this._openAppTag.remove();
|
|
318
323
|
this._openAppTag = null;
|
|
324
|
+
this._openInstallButton.remove();
|
|
325
|
+
this._openInstallButton = null;
|
|
319
326
|
}
|
|
320
327
|
if (this._alink) {
|
|
321
328
|
this._alink.remove();
|
|
@@ -334,10 +341,10 @@
|
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
_useOpenInstall() {
|
|
337
|
-
return this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
344
|
+
return this._isMobile && !this._isApp && this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
338
345
|
}
|
|
339
346
|
_initOpenInstall() {
|
|
340
|
-
if (!this._isConnected ||
|
|
347
|
+
if (!this._isConnected || !this._useOpenInstall()) return;
|
|
341
348
|
const key = this._appInfo.openinstall_app_key;
|
|
342
349
|
if (this._openInstallKey === key && this._openInstallPromise) return;
|
|
343
350
|
this._openInstallKey = key;
|
|
@@ -347,14 +354,9 @@
|
|
|
347
354
|
promise.then(instance => {
|
|
348
355
|
if (this._openInstallPromise !== promise) return;
|
|
349
356
|
this._openInstall = instance;
|
|
350
|
-
if (this._openInstallPending && this._isConnected && this._useOpenInstall()) {
|
|
351
|
-
this._openInstallPending = false;
|
|
352
|
-
instance.wakeupOrInstall();
|
|
353
|
-
}
|
|
354
357
|
}).catch(error => {
|
|
355
358
|
if (this._openInstallPromise !== promise) return;
|
|
356
359
|
this._openInstallPromise = null;
|
|
357
|
-
this._openInstallPending = false;
|
|
358
360
|
this._log('OpenInstall initialization failed', error);
|
|
359
361
|
this.dispatchEvent(new CustomEvent('openinstallerror', { detail: { error }, bubbles: true, composed: true }));
|
|
360
362
|
});
|
|
@@ -362,9 +364,6 @@
|
|
|
362
364
|
_wakeupOpenInstall() {
|
|
363
365
|
if (this._openInstall) {
|
|
364
366
|
this._openInstall.wakeupOrInstall();
|
|
365
|
-
} else {
|
|
366
|
-
this._openInstallPending = true;
|
|
367
|
-
this._initOpenInstall();
|
|
368
367
|
}
|
|
369
368
|
}
|
|
370
369
|
_initClipboardText() {
|
|
@@ -489,7 +488,6 @@
|
|
|
489
488
|
this._openInstallKey = '';
|
|
490
489
|
this._openInstall = null;
|
|
491
490
|
this._openInstallPromise = null;
|
|
492
|
-
this._openInstallPending = false;
|
|
493
491
|
}
|
|
494
492
|
var fallbackTime = this.getAttribute('fallback-time');
|
|
495
493
|
if (fallbackTime == null || fallbackTime === '' || isNaN(Number(fallbackTime))) {
|
|
@@ -502,8 +500,9 @@
|
|
|
502
500
|
console.error('open-diandian: appid not supported', this._appid);
|
|
503
501
|
return;
|
|
504
502
|
}
|
|
505
|
-
if (this._isConnected) {
|
|
506
|
-
|
|
503
|
+
if (this._isConnected && this._useOpenInstall()) {
|
|
504
|
+
this._cancelLaunchFallback();
|
|
505
|
+
this._cancelFinalFallback();
|
|
507
506
|
this._initOpenInstall();
|
|
508
507
|
}
|
|
509
508
|
this._log('open-diandian: appInfo', this._appInfo);
|
|
@@ -523,13 +522,13 @@
|
|
|
523
522
|
this._alink_fin_5s = this._appInfo.fallback_fin_5s || '';
|
|
524
523
|
}
|
|
525
524
|
if (this._openAppTag) {
|
|
525
|
+
const useOpenInstall = this._useOpenInstall();
|
|
526
|
+
this._openAppTag.style.display = useOpenInstall ? 'none' : '';
|
|
527
|
+
this._openInstallButton.hidden = !useOpenInstall;
|
|
526
528
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
527
529
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
528
530
|
} else if (this._alink) {
|
|
529
|
-
|
|
530
|
-
this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
|
|
531
|
-
? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
|
|
532
|
-
: this._alink_link;
|
|
531
|
+
this._alink.href = this._useOpenInstall() ? '#' : this._alink_link;
|
|
533
532
|
}
|
|
534
533
|
}
|
|
535
534
|
};
|
package/open-diandian/index.js
CHANGED
|
@@ -112,6 +112,7 @@ function createOpenDiandianElementClass() {
|
|
|
112
112
|
this._debug = false;
|
|
113
113
|
this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
|
|
114
114
|
this._openAppTag = null;
|
|
115
|
+
this._openInstallButton = null;
|
|
115
116
|
this._fallbackTime = 3000;
|
|
116
117
|
this._appid = '';
|
|
117
118
|
this._appInfo = null;
|
|
@@ -136,7 +137,6 @@ function createOpenDiandianElementClass() {
|
|
|
136
137
|
this._openInstall = null;
|
|
137
138
|
this._openInstallPromise = null;
|
|
138
139
|
this._openInstallKey = '';
|
|
139
|
-
this._openInstallPending = false;
|
|
140
140
|
}
|
|
141
141
|
_log(...args) {
|
|
142
142
|
if (this._debug) {
|
|
@@ -159,6 +159,14 @@ function createOpenDiandianElementClass() {
|
|
|
159
159
|
this._openAppTag = document.createElement('wx-open-launch-app');
|
|
160
160
|
this._openAppTag.style.background = "transparent";
|
|
161
161
|
this._openAppTag.style.opacity = 0;
|
|
162
|
+
this._openInstallButton = document.createElement('button');
|
|
163
|
+
this._openInstallButton.type = 'button';
|
|
164
|
+
this._openInstallButton.setAttribute('aria-label', '打开 App');
|
|
165
|
+
this._openInstallButton.style.width = '100%';
|
|
166
|
+
this._openInstallButton.style.height = '100%';
|
|
167
|
+
this._openInstallButton.addEventListener('click', () => {
|
|
168
|
+
if (this._useOpenInstall()) this._wakeupOpenInstall();
|
|
169
|
+
});
|
|
162
170
|
this._updateTagAttr();
|
|
163
171
|
|
|
164
172
|
var contentEle = document.createElement('div');
|
|
@@ -175,8 +183,9 @@ function createOpenDiandianElementClass() {
|
|
|
175
183
|
|
|
176
184
|
this._openAppTag.appendChild(scriptTag);
|
|
177
185
|
this._template.content.appendChild(this._openAppTag);
|
|
178
|
-
this.
|
|
179
|
-
this.shadowRoot.
|
|
186
|
+
this._template.content.appendChild(this._openInstallButton);
|
|
187
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
188
|
+
shadow.appendChild(this._template.content);
|
|
180
189
|
this._log('open-diandian: wx-open-launch-app appended');
|
|
181
190
|
// 监听打开app失败的情况,跳转fallback链接
|
|
182
191
|
this._openAppTag.addEventListener('error', (e) => {
|
|
@@ -185,10 +194,7 @@ function createOpenDiandianElementClass() {
|
|
|
185
194
|
bubbles: true,
|
|
186
195
|
composed: true,
|
|
187
196
|
}));
|
|
188
|
-
if (this._useOpenInstall())
|
|
189
|
-
this._wakeupOpenInstall();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
197
|
+
if (this._useOpenInstall()) return;
|
|
192
198
|
if (this._isHarmony || this._isSceneLink()) {
|
|
193
199
|
this._showOpenInBrowserHint();
|
|
194
200
|
return;
|
|
@@ -222,7 +228,7 @@ function createOpenDiandianElementClass() {
|
|
|
222
228
|
return;
|
|
223
229
|
}
|
|
224
230
|
this._log('open-diandian: final fallback go', this._alink_fin_5s);
|
|
225
|
-
this.
|
|
231
|
+
this._openLink(this._alink_fin_5s);
|
|
226
232
|
}, 5000);
|
|
227
233
|
}
|
|
228
234
|
});
|
|
@@ -245,8 +251,8 @@ function createOpenDiandianElementClass() {
|
|
|
245
251
|
this._alink.style.width = '100%';
|
|
246
252
|
this._alink.style.height = '100%';
|
|
247
253
|
this._template.content.appendChild(this._alink);
|
|
248
|
-
this.attachShadow({ mode: 'open' });
|
|
249
|
-
|
|
254
|
+
const shadow = this.shadowRoot || this.attachShadow({ mode: 'open' });
|
|
255
|
+
shadow.appendChild(this._template.content);
|
|
250
256
|
this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
|
|
251
257
|
this._log('open-diandian: open link appended');
|
|
252
258
|
this._clickLink = false;
|
|
@@ -270,14 +276,18 @@ function createOpenDiandianElementClass() {
|
|
|
270
276
|
}
|
|
271
277
|
}
|
|
272
278
|
_handleAlinkClick(event) {
|
|
279
|
+
const useOpenInstall = this._useOpenInstall();
|
|
280
|
+
if (useOpenInstall) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
if (!this._openInstall) return;
|
|
283
|
+
}
|
|
273
284
|
this._writeClickboard();
|
|
274
285
|
this._cancelLaunchFallback();
|
|
286
|
+
if (useOpenInstall) {
|
|
287
|
+
this._wakeupOpenInstall();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
275
290
|
if (this._alink_link === this._alink_fallback) {
|
|
276
|
-
// 没有可用的拉端链接,点击本身就是兜底。
|
|
277
|
-
if (this._useOpenInstall()) {
|
|
278
|
-
event.preventDefault();
|
|
279
|
-
this._wakeupOpenInstall();
|
|
280
|
-
}
|
|
281
291
|
return;
|
|
282
292
|
}
|
|
283
293
|
// 先使用原链接拉端,页面没有隐藏才执行兜底。
|
|
@@ -286,7 +296,7 @@ function createOpenDiandianElementClass() {
|
|
|
286
296
|
this._cancelLaunchFallback();
|
|
287
297
|
if (!this._isConnected || document.hidden) return;
|
|
288
298
|
this._log('open app timed out, run fallback');
|
|
289
|
-
this.
|
|
299
|
+
this._openLink(this._alink_fallback);
|
|
290
300
|
}, this._fallbackTime);
|
|
291
301
|
}
|
|
292
302
|
_cancelLaunchFallback() {
|
|
@@ -294,11 +304,7 @@ function createOpenDiandianElementClass() {
|
|
|
294
304
|
this._alink_click_timer = null;
|
|
295
305
|
this._clickLink = false;
|
|
296
306
|
}
|
|
297
|
-
|
|
298
|
-
if (this._useOpenInstall()) {
|
|
299
|
-
this._wakeupOpenInstall();
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
307
|
+
_openLink(href) {
|
|
302
308
|
const link = document.createElement('a');
|
|
303
309
|
link.href = href;
|
|
304
310
|
link.click();
|
|
@@ -306,11 +312,12 @@ function createOpenDiandianElementClass() {
|
|
|
306
312
|
disconnectedCallback() {
|
|
307
313
|
this._log("disconnectedCallback")
|
|
308
314
|
this._isConnected = false;
|
|
309
|
-
this._openInstallPending = false;
|
|
310
315
|
this._cancelLaunchFallback();
|
|
311
316
|
if (this._openAppTag) {
|
|
312
317
|
this._openAppTag.remove();
|
|
313
318
|
this._openAppTag = null;
|
|
319
|
+
this._openInstallButton.remove();
|
|
320
|
+
this._openInstallButton = null;
|
|
314
321
|
}
|
|
315
322
|
if (this._alink) {
|
|
316
323
|
this._alink.remove();
|
|
@@ -329,10 +336,10 @@ function createOpenDiandianElementClass() {
|
|
|
329
336
|
}
|
|
330
337
|
}
|
|
331
338
|
_useOpenInstall() {
|
|
332
|
-
return this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
339
|
+
return this._isMobile && !this._isApp && this.hasAttribute('openinstall') && !!(this._appInfo && this._appInfo.openinstall_app_key);
|
|
333
340
|
}
|
|
334
341
|
_initOpenInstall() {
|
|
335
|
-
if (!this._isConnected ||
|
|
342
|
+
if (!this._isConnected || !this._useOpenInstall()) return;
|
|
336
343
|
const key = this._appInfo.openinstall_app_key;
|
|
337
344
|
if (this._openInstallKey === key && this._openInstallPromise) return;
|
|
338
345
|
this._openInstallKey = key;
|
|
@@ -342,14 +349,9 @@ function createOpenDiandianElementClass() {
|
|
|
342
349
|
promise.then(instance => {
|
|
343
350
|
if (this._openInstallPromise !== promise) return;
|
|
344
351
|
this._openInstall = instance;
|
|
345
|
-
if (this._openInstallPending && this._isConnected && this._useOpenInstall()) {
|
|
346
|
-
this._openInstallPending = false;
|
|
347
|
-
instance.wakeupOrInstall();
|
|
348
|
-
}
|
|
349
352
|
}).catch(error => {
|
|
350
353
|
if (this._openInstallPromise !== promise) return;
|
|
351
354
|
this._openInstallPromise = null;
|
|
352
|
-
this._openInstallPending = false;
|
|
353
355
|
this._log('OpenInstall initialization failed', error);
|
|
354
356
|
this.dispatchEvent(new CustomEvent('openinstallerror', { detail: { error }, bubbles: true, composed: true }));
|
|
355
357
|
});
|
|
@@ -357,9 +359,6 @@ function createOpenDiandianElementClass() {
|
|
|
357
359
|
_wakeupOpenInstall() {
|
|
358
360
|
if (this._openInstall) {
|
|
359
361
|
this._openInstall.wakeupOrInstall();
|
|
360
|
-
} else {
|
|
361
|
-
this._openInstallPending = true;
|
|
362
|
-
this._initOpenInstall();
|
|
363
362
|
}
|
|
364
363
|
}
|
|
365
364
|
_initClipboardText() {
|
|
@@ -484,7 +483,6 @@ function createOpenDiandianElementClass() {
|
|
|
484
483
|
this._openInstallKey = '';
|
|
485
484
|
this._openInstall = null;
|
|
486
485
|
this._openInstallPromise = null;
|
|
487
|
-
this._openInstallPending = false;
|
|
488
486
|
}
|
|
489
487
|
var fallbackTime = this.getAttribute('fallback-time');
|
|
490
488
|
if (fallbackTime == null || fallbackTime === '' || isNaN(Number(fallbackTime))) {
|
|
@@ -497,8 +495,9 @@ function createOpenDiandianElementClass() {
|
|
|
497
495
|
console.error('open-diandian: appid not supported', this._appid);
|
|
498
496
|
return;
|
|
499
497
|
}
|
|
500
|
-
if (this._isConnected) {
|
|
501
|
-
|
|
498
|
+
if (this._isConnected && this._useOpenInstall()) {
|
|
499
|
+
this._cancelLaunchFallback();
|
|
500
|
+
this._cancelFinalFallback();
|
|
502
501
|
this._initOpenInstall();
|
|
503
502
|
}
|
|
504
503
|
this._log('open-diandian: appInfo', this._appInfo);
|
|
@@ -518,13 +517,13 @@ function createOpenDiandianElementClass() {
|
|
|
518
517
|
this._alink_fin_5s = this._appInfo.fallback_fin_5s || '';
|
|
519
518
|
}
|
|
520
519
|
if (this._openAppTag) {
|
|
520
|
+
const useOpenInstall = this._useOpenInstall();
|
|
521
|
+
this._openAppTag.style.display = useOpenInstall ? 'none' : '';
|
|
522
|
+
this._openInstallButton.hidden = !useOpenInstall;
|
|
521
523
|
this._openAppTag.setAttribute('appid', this._appid);
|
|
522
524
|
this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
|
|
523
525
|
} else if (this._alink) {
|
|
524
|
-
|
|
525
|
-
this._alink.href = this._useOpenInstall() && this._alink_link.startsWith('intent:')
|
|
526
|
-
? this._alink_link.replace(/;S\.browser_fallback_url=[^;]*/, '')
|
|
527
|
-
: this._alink_link;
|
|
526
|
+
this._alink.href = this._useOpenInstall() ? '#' : this._alink_link;
|
|
528
527
|
}
|
|
529
528
|
}
|
|
530
529
|
};
|