native-fn 1.0.24 → 1.0.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.
- package/README.md +206 -0
- package/dist/native.cjs +100 -76
- package/dist/native.mjs +100 -76
- package/dist/native.umd.js +100 -76
- package/dist/src/constants/app.d.ts +1 -0
- package/dist/src/types/app.d.ts +1 -0
- package/dist/src/utils/try-open-url.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Native.App API Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Native.App provides a unified interface for opening native applications across different platforms with cross-platform compatibility.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Interface
|
|
9
|
+
|
|
10
|
+
### App
|
|
11
|
+
Main interface for native app operations.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
interface App {
|
|
15
|
+
open: (options: AppOpenOptions, target?: WindowProxy) => Promise<AppOpenState>;
|
|
16
|
+
messenger: Messenger;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Methods
|
|
23
|
+
|
|
24
|
+
### `Native.App.open()`
|
|
25
|
+
|
|
26
|
+
Opens a native application with platform-specific configurations.
|
|
27
|
+
|
|
28
|
+
#### Syntax
|
|
29
|
+
```typescript
|
|
30
|
+
Native.App.open(options: AppOpenOptions, target?: WindowProxy): Promise<AppOpenState>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### Parameters
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Required | Description |
|
|
36
|
+
|-----------|------|----------|-------------|
|
|
37
|
+
| `options` | `AppOpenOptions` | ✅ | Platform-specific app configuration |
|
|
38
|
+
| `target` | `WindowProxy` | ❌ | Target window (default: current window) |
|
|
39
|
+
|
|
40
|
+
#### Platform Options
|
|
41
|
+
|
|
42
|
+
Each platform requires different configuration parameters:
|
|
43
|
+
|
|
44
|
+
##### Android
|
|
45
|
+
```typescript
|
|
46
|
+
{
|
|
47
|
+
[Native.Constant.OS.Android]: {
|
|
48
|
+
scheme: string; // App URL scheme
|
|
49
|
+
packageName: string; // Android package name
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
##### iOS
|
|
55
|
+
```typescript
|
|
56
|
+
{
|
|
57
|
+
[Native.Constant.OS.iOS]: {
|
|
58
|
+
scheme: string; // App URL scheme
|
|
59
|
+
packageName: string; // Bundle ID
|
|
60
|
+
trackId?: string; // App Store track ID (optional)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
##### Windows
|
|
66
|
+
```typescript
|
|
67
|
+
{
|
|
68
|
+
[Native.Constant.OS.Windows]: {
|
|
69
|
+
scheme: string; // App URL scheme
|
|
70
|
+
productId: string; // Microsoft Store product ID
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
##### macOS
|
|
76
|
+
```typescript
|
|
77
|
+
{
|
|
78
|
+
[Native.Constant.OS.MacOS]: {
|
|
79
|
+
scheme: string; // App URL scheme
|
|
80
|
+
packageName: string; // Bundle ID
|
|
81
|
+
trackId?: string; // App Store track ID (optional)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Examples
|
|
89
|
+
|
|
90
|
+
### Basic Usage
|
|
91
|
+
|
|
92
|
+
Open Microsoft Excel across all platforms:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Create a new tab for the app to open in
|
|
96
|
+
const newTab: WindowProxy = window.open("about:blank");
|
|
97
|
+
|
|
98
|
+
// Configure Excel for all platforms
|
|
99
|
+
const excelConfig = {
|
|
100
|
+
[Native.Constant.OS.Android]: {
|
|
101
|
+
scheme: "excel://",
|
|
102
|
+
packageName: "com.microsoft.office.excel",
|
|
103
|
+
},
|
|
104
|
+
[Native.Constant.OS.iOS]: {
|
|
105
|
+
scheme: "excel://",
|
|
106
|
+
packageName: "com.microsoft.Office.Excel",
|
|
107
|
+
// trackId: "586683407", // Uncomment if needed
|
|
108
|
+
},
|
|
109
|
+
[Native.Constant.OS.Windows]: {
|
|
110
|
+
scheme: "excel://",
|
|
111
|
+
productId: "cfq7ttc0k5bf",
|
|
112
|
+
},
|
|
113
|
+
[Native.Constant.OS.MacOS]: {
|
|
114
|
+
scheme: "excel://",
|
|
115
|
+
packageName: "com.microsoft.Excel",
|
|
116
|
+
// trackId: "462058435", // Uncomment if needed
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Open Excel
|
|
121
|
+
try {
|
|
122
|
+
const result = await Native.App.open(excelConfig, newTab);
|
|
123
|
+
console.log('Excel opened successfully:', result);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Failed to open Excel:', error);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Single Platform Example
|
|
130
|
+
|
|
131
|
+
Open an app on a specific platform:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
// Android only
|
|
135
|
+
const androidConfig = {
|
|
136
|
+
[Native.Constant.OS.Android]: {
|
|
137
|
+
scheme: "myapp://",
|
|
138
|
+
packageName: "com.example.myapp",
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
await Native.App.open(androidConfig);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Return Value
|
|
148
|
+
|
|
149
|
+
Returns `Promise<AppOpenState>` with information about the app opening state.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Error Handling
|
|
154
|
+
|
|
155
|
+
The method may reject with errors in the following cases:
|
|
156
|
+
- App is not installed on the device
|
|
157
|
+
- Invalid configuration parameters
|
|
158
|
+
- Platform not supported
|
|
159
|
+
- Network connectivity issues
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
try {
|
|
163
|
+
await Native.App.open(config);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error.code === 'APP_NOT_FOUND') {
|
|
166
|
+
// Handle app not installed
|
|
167
|
+
} else if (error.code === 'INVALID_CONFIG') {
|
|
168
|
+
// Handle configuration error
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Best Practices
|
|
176
|
+
|
|
177
|
+
### ✅ Do
|
|
178
|
+
- Always provide configurations for all target platforms
|
|
179
|
+
- Use `window.open("about:blank")` for better user experience
|
|
180
|
+
- Handle errors gracefully with try-catch blocks
|
|
181
|
+
- Test on all target platforms
|
|
182
|
+
|
|
183
|
+
### ❌ Don't
|
|
184
|
+
- Hardcode platform detection in your application logic
|
|
185
|
+
- Ignore error handling
|
|
186
|
+
- Use deprecated package names or schemes
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Platform-Specific Notes
|
|
191
|
+
|
|
192
|
+
### Android
|
|
193
|
+
- Package names follow reverse domain notation
|
|
194
|
+
- Ensure the app supports the specified URL scheme
|
|
195
|
+
|
|
196
|
+
### iOS
|
|
197
|
+
- Bundle IDs are case-sensitive
|
|
198
|
+
- Track IDs are optional but recommended for App Store linking
|
|
199
|
+
|
|
200
|
+
### Windows
|
|
201
|
+
- Product IDs can be found in the Microsoft Store URL
|
|
202
|
+
- Some apps may require additional permissions
|
|
203
|
+
|
|
204
|
+
### macOS
|
|
205
|
+
- Bundle IDs should match the app's Info.plist
|
|
206
|
+
- Track IDs link to Mac App Store entries
|
package/dist/native.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var version = "1.0.
|
|
3
|
+
var version = "1.0.26";
|
|
4
4
|
var packageJSON = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
7
|
+
var USER_AGENT = navigator.userAgent;
|
|
8
|
+
|
|
7
9
|
var AppOpenState;
|
|
8
10
|
(function (AppOpenState) {
|
|
9
11
|
AppOpenState[AppOpenState["Scheme"] = 0] = "Scheme";
|
|
@@ -18,8 +20,7 @@ var Messengers;
|
|
|
18
20
|
Messengers["Message"] = "message";
|
|
19
21
|
Messengers["Mail"] = "mail";
|
|
20
22
|
})(Messengers || (Messengers = {}));
|
|
21
|
-
|
|
22
|
-
var USER_AGENT = navigator.userAgent;
|
|
23
|
+
var IS_SUPPORT_INTENT = !/firefox|opr/i.test(USER_AGENT);
|
|
23
24
|
|
|
24
25
|
var OS;
|
|
25
26
|
(function (OS) {
|
|
@@ -204,46 +205,63 @@ var Platform = {
|
|
|
204
205
|
isStandalone: IS_STANDALONE,
|
|
205
206
|
};
|
|
206
207
|
|
|
207
|
-
function
|
|
208
|
+
function getTopmostWindow() {
|
|
209
|
+
if (window.top !== null)
|
|
210
|
+
return window.top;
|
|
211
|
+
return window;
|
|
212
|
+
}
|
|
213
|
+
function openURLViaHref(url, index) {
|
|
214
|
+
var top = getTopmostWindow();
|
|
208
215
|
var a = undefined;
|
|
209
216
|
try {
|
|
210
|
-
|
|
211
|
-
|
|
217
|
+
if (index === 0) {
|
|
218
|
+
top.location.href = url;
|
|
212
219
|
return;
|
|
213
|
-
|
|
220
|
+
}
|
|
221
|
+
a = top.document.createElement("a");
|
|
214
222
|
a.href = url;
|
|
215
223
|
a.style.display = "none";
|
|
216
224
|
a.setAttribute("aria-hidden", "true");
|
|
217
|
-
|
|
225
|
+
top.document.body.appendChild(a);
|
|
218
226
|
var fake = void 0;
|
|
219
227
|
try {
|
|
220
228
|
fake = new MouseEvent("click", {
|
|
221
229
|
bubbles: true,
|
|
222
230
|
cancelable: true,
|
|
223
|
-
view:
|
|
231
|
+
view: top
|
|
224
232
|
});
|
|
225
233
|
}
|
|
226
234
|
catch (_) {
|
|
227
|
-
fake =
|
|
228
|
-
fake.initMouseEvent("click", true, true,
|
|
235
|
+
fake = top.document.createEvent("MouseEvents");
|
|
236
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
229
237
|
}
|
|
230
238
|
a.dispatchEvent(fake);
|
|
231
|
-
if (a.click !== undefined)
|
|
232
|
-
a.click();
|
|
233
|
-
window.location.assign(url);
|
|
234
239
|
}
|
|
235
240
|
catch (_) {
|
|
236
241
|
}
|
|
237
242
|
finally {
|
|
238
243
|
if (a !== undefined)
|
|
239
|
-
|
|
244
|
+
top.document.body.removeChild(a);
|
|
240
245
|
}
|
|
241
246
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
247
|
+
function openURLViaIframe(url) {
|
|
248
|
+
var top = getTopmostWindow();
|
|
249
|
+
var iframe = document.createElement("iframe");
|
|
250
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
251
|
+
iframe.style.display = "none";
|
|
252
|
+
iframe.src = url;
|
|
253
|
+
top.document.body.appendChild(iframe);
|
|
254
|
+
window.setTimeout(function () {
|
|
255
|
+
try {
|
|
256
|
+
top.document.removeChild(iframe);
|
|
257
|
+
}
|
|
258
|
+
catch (_) {
|
|
259
|
+
}
|
|
260
|
+
}, 100);
|
|
244
261
|
}
|
|
245
|
-
function isDocumentHidden(
|
|
246
|
-
var
|
|
262
|
+
function isDocumentHidden() {
|
|
263
|
+
var top = getTopmostWindow();
|
|
264
|
+
var doc = top.document;
|
|
247
265
|
if (doc.visibilityState === "hidden")
|
|
248
266
|
return true;
|
|
249
267
|
if (doc.hidden !== undefined)
|
|
@@ -254,36 +272,18 @@ function isDocumentHidden(self) {
|
|
|
254
272
|
return !doc.hasFocus();
|
|
255
273
|
return true;
|
|
256
274
|
}
|
|
257
|
-
function tryOpenUrl(
|
|
258
|
-
var
|
|
259
|
-
var scopeDocument;
|
|
260
|
-
if (isIframeWindow(self)) {
|
|
261
|
-
try {
|
|
262
|
-
var top_1 = self.top;
|
|
263
|
-
if (top_1 === null)
|
|
264
|
-
return Promise.reject();
|
|
265
|
-
scopeWindow = top_1;
|
|
266
|
-
scopeDocument = scopeWindow.document;
|
|
267
|
-
}
|
|
268
|
-
catch (_) {
|
|
269
|
-
scopeWindow = self;
|
|
270
|
-
scopeDocument = scopeWindow.document;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
scopeWindow = self;
|
|
275
|
-
scopeDocument = self.document;
|
|
276
|
-
}
|
|
275
|
+
function tryOpenUrl(url, index, timeout) {
|
|
276
|
+
var top = getTopmostWindow();
|
|
277
277
|
if (Platform.os === OS.iOS) {
|
|
278
278
|
var visibilitychange_1;
|
|
279
279
|
var eventTarget_1;
|
|
280
280
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
281
281
|
visibilitychange_1 = "visibilitychange";
|
|
282
|
-
eventTarget_1 =
|
|
282
|
+
eventTarget_1 = top.document;
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
285
285
|
visibilitychange_1 = "pagehide";
|
|
286
|
-
eventTarget_1 =
|
|
286
|
+
eventTarget_1 = top;
|
|
287
287
|
}
|
|
288
288
|
return new Promise(function (resolve, reject) {
|
|
289
289
|
var timeoutId;
|
|
@@ -309,7 +309,7 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
function onVisibilityChange() {
|
|
312
|
-
if (isDocumentHidden(
|
|
312
|
+
if (isDocumentHidden())
|
|
313
313
|
done(true);
|
|
314
314
|
}
|
|
315
315
|
timeoutId = window.setTimeout(function () {
|
|
@@ -317,7 +317,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
317
317
|
}, timeout);
|
|
318
318
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
319
319
|
try {
|
|
320
|
-
|
|
320
|
+
openURLViaIframe(url);
|
|
321
|
+
openURLViaHref(url, index);
|
|
321
322
|
}
|
|
322
323
|
catch (_) {
|
|
323
324
|
done(false);
|
|
@@ -331,8 +332,9 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
331
332
|
function cleanup() {
|
|
332
333
|
if (timeoutId)
|
|
333
334
|
clearTimeout(timeoutId);
|
|
334
|
-
|
|
335
|
-
|
|
335
|
+
top.removeEventListener("blur", onBlur);
|
|
336
|
+
top.removeEventListener("focus", onFocus);
|
|
337
|
+
top.document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
336
338
|
}
|
|
337
339
|
function done(success) {
|
|
338
340
|
if (!resolved) {
|
|
@@ -351,18 +353,24 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
351
353
|
}
|
|
352
354
|
function onBlur() {
|
|
353
355
|
clearTimeout(timeoutId);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
+
top.removeEventListener("blur", onBlur);
|
|
357
|
+
top.addEventListener("focus", onFocus);
|
|
356
358
|
}
|
|
357
359
|
function onFocus() {
|
|
358
360
|
done(true);
|
|
359
361
|
}
|
|
362
|
+
function onVisibilityChange() {
|
|
363
|
+
if (isDocumentHidden())
|
|
364
|
+
done(true);
|
|
365
|
+
}
|
|
360
366
|
timeoutId = window.setTimeout(function () {
|
|
361
367
|
done(false);
|
|
362
368
|
}, timeout);
|
|
363
|
-
|
|
369
|
+
top.addEventListener("blur", onBlur);
|
|
370
|
+
top.document.addEventListener("visibilitychange", onVisibilityChange);
|
|
364
371
|
try {
|
|
365
|
-
|
|
372
|
+
openURLViaIframe(url);
|
|
373
|
+
openURLViaHref(url, index);
|
|
366
374
|
}
|
|
367
375
|
catch (_) {
|
|
368
376
|
done(false);
|
|
@@ -497,20 +505,29 @@ function getDefaultTimeoutByOS(os) {
|
|
|
497
505
|
default: return 750;
|
|
498
506
|
}
|
|
499
507
|
}
|
|
500
|
-
function open(options
|
|
501
|
-
if (self === void 0) { self = window; }
|
|
508
|
+
function open(options) {
|
|
502
509
|
var os = OS_NAME;
|
|
503
510
|
var urls = [];
|
|
511
|
+
var tried = [];
|
|
504
512
|
var timeout;
|
|
513
|
+
function getURLOpenError() {
|
|
514
|
+
var triedUrlString = "";
|
|
515
|
+
for (var i = 0; i < urls.length; i++)
|
|
516
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
517
|
+
if (triedUrlString.length > 0)
|
|
518
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
519
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
520
|
+
}
|
|
505
521
|
if (os === OS.Android) {
|
|
506
522
|
var option = options[OS.Android];
|
|
507
523
|
if (option === undefined)
|
|
508
|
-
return Promise.reject();
|
|
524
|
+
return Promise.reject(getURLOpenError());
|
|
509
525
|
timeout = option.timeout;
|
|
510
526
|
var scheme = option.scheme;
|
|
511
527
|
var intent = option.intent;
|
|
512
528
|
var packageName = option.packageName;
|
|
513
529
|
var fallback = option.fallback;
|
|
530
|
+
var allowWebStore = option.allowWebStore;
|
|
514
531
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
515
532
|
var parsed = parseIntentURL(intent);
|
|
516
533
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -522,25 +539,28 @@ function open(options, self) {
|
|
|
522
539
|
}
|
|
523
540
|
if (scheme !== undefined && intent === undefined)
|
|
524
541
|
intent = createIntentURL(scheme, packageName, fallback);
|
|
525
|
-
if (intent !== undefined)
|
|
542
|
+
if (intent !== undefined && IS_SUPPORT_INTENT)
|
|
526
543
|
urls.push([intent, AppOpenState.Intent]);
|
|
527
544
|
if (scheme !== undefined)
|
|
528
545
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
529
546
|
if (fallback !== undefined)
|
|
530
547
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
531
548
|
if (packageName !== undefined)
|
|
532
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
549
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
550
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
551
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
533
552
|
}
|
|
534
553
|
else if (os === OS.iOS) {
|
|
535
554
|
var option = options[OS.iOS];
|
|
536
555
|
if (option === undefined)
|
|
537
|
-
return Promise.reject();
|
|
556
|
+
return Promise.reject(getURLOpenError());
|
|
538
557
|
timeout = option.timeout;
|
|
539
558
|
var scheme = option.scheme;
|
|
540
559
|
var packageName = option.packageName;
|
|
541
560
|
var trackId = option.trackId;
|
|
542
561
|
var universal = option.universal;
|
|
543
562
|
var fallback = option.fallback;
|
|
563
|
+
var allowWebStore = option.allowWebStore;
|
|
544
564
|
if (packageName !== undefined && trackId === undefined)
|
|
545
565
|
trackId = getTrackId(packageName);
|
|
546
566
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -550,32 +570,38 @@ function open(options, self) {
|
|
|
550
570
|
if (fallback !== undefined)
|
|
551
571
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
552
572
|
if (trackId !== undefined)
|
|
553
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
573
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
574
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
575
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
554
576
|
}
|
|
555
577
|
else if (os === OS.Windows) {
|
|
556
578
|
var option = options[OS.Windows];
|
|
557
579
|
if (option === undefined)
|
|
558
|
-
return Promise.reject();
|
|
580
|
+
return Promise.reject(getURLOpenError());
|
|
559
581
|
timeout = option.timeout;
|
|
560
582
|
var scheme = option.scheme;
|
|
561
583
|
var productId = option.productId;
|
|
562
584
|
var fallback = option.fallback;
|
|
585
|
+
var allowWebStore = option.allowWebStore;
|
|
563
586
|
if (scheme !== undefined)
|
|
564
587
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
565
588
|
if (fallback !== undefined)
|
|
566
589
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
567
590
|
if (productId !== undefined)
|
|
568
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
591
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
592
|
+
if (productId !== undefined && allowWebStore === true)
|
|
593
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
569
594
|
}
|
|
570
595
|
else if (os === OS.MacOS) {
|
|
571
596
|
var option = options[OS.MacOS];
|
|
572
597
|
if (option === undefined)
|
|
573
|
-
return Promise.reject();
|
|
598
|
+
return Promise.reject(getURLOpenError());
|
|
574
599
|
timeout = option.timeout;
|
|
575
600
|
var scheme = option.scheme;
|
|
576
601
|
var packageName = option.packageName;
|
|
577
602
|
var trackId = option.trackId;
|
|
578
603
|
var fallback = option.fallback;
|
|
604
|
+
var allowWebStore = option.allowWebStore;
|
|
579
605
|
if (packageName !== undefined && trackId === undefined)
|
|
580
606
|
trackId = getTrackId(packageName);
|
|
581
607
|
if (scheme !== undefined)
|
|
@@ -583,25 +609,26 @@ function open(options, self) {
|
|
|
583
609
|
if (fallback !== undefined)
|
|
584
610
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
585
611
|
if (trackId !== undefined)
|
|
586
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
612
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
613
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
614
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
587
615
|
}
|
|
588
616
|
if (timeout === undefined)
|
|
589
617
|
timeout = getDefaultTimeoutByOS(os);
|
|
590
618
|
return new Promise(function (resolve, reject) {
|
|
591
|
-
var tried = "\n";
|
|
592
619
|
function openURLSequential(index) {
|
|
593
620
|
if (index === void 0) { index = 0; }
|
|
594
621
|
if (index >= urls.length)
|
|
595
|
-
return reject(
|
|
622
|
+
return reject(getURLOpenError());
|
|
596
623
|
var entry = urls[index];
|
|
597
624
|
var url = entry[0];
|
|
598
|
-
tried =
|
|
599
|
-
return tryOpenUrl(
|
|
625
|
+
tried[index] = url;
|
|
626
|
+
return tryOpenUrl(url, index, timeout)
|
|
600
627
|
.then(function () {
|
|
601
628
|
resolve(entry[1]);
|
|
602
629
|
})
|
|
603
630
|
.catch(function () {
|
|
604
|
-
openURLSequential(
|
|
631
|
+
openURLSequential(index + 1);
|
|
605
632
|
});
|
|
606
633
|
}
|
|
607
634
|
return openURLSequential();
|
|
@@ -721,25 +748,22 @@ function normalize(value) {
|
|
|
721
748
|
result.body = "";
|
|
722
749
|
return result;
|
|
723
750
|
}
|
|
724
|
-
function openMessenger(options,
|
|
751
|
+
function openMessenger(options, type) {
|
|
725
752
|
options = normalize(options);
|
|
726
|
-
return tryOpenUrl(
|
|
753
|
+
return tryOpenUrl(type + ":" + options.to
|
|
727
754
|
+ "?cc=" + options.cc
|
|
728
755
|
+ "&bcc=" + options.bcc
|
|
729
756
|
+ "&subject=" + options.subject
|
|
730
757
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
731
758
|
}
|
|
732
|
-
function openMessengerTelephone(options
|
|
733
|
-
|
|
734
|
-
return openMessenger(options, self, "tel");
|
|
759
|
+
function openMessengerTelephone(options) {
|
|
760
|
+
return openMessenger(options, "tel");
|
|
735
761
|
}
|
|
736
|
-
function openMessengerMessage(options
|
|
737
|
-
|
|
738
|
-
return openMessenger(options, self, "sms");
|
|
762
|
+
function openMessengerMessage(options) {
|
|
763
|
+
return openMessenger(options, "sms");
|
|
739
764
|
}
|
|
740
|
-
function openMessengerMail(options
|
|
741
|
-
|
|
742
|
-
return openMessenger(options, self, "mailto");
|
|
765
|
+
function openMessengerMail(options) {
|
|
766
|
+
return openMessenger(options, "mailto");
|
|
743
767
|
}
|
|
744
768
|
|
|
745
769
|
var EasingError = createCustomError("EasingError");
|
package/dist/native.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
var version = "1.0.
|
|
1
|
+
var version = "1.0.26";
|
|
2
2
|
var packageJSON = {
|
|
3
3
|
version: version};
|
|
4
4
|
|
|
5
|
+
var USER_AGENT = navigator.userAgent;
|
|
6
|
+
|
|
5
7
|
var AppOpenState;
|
|
6
8
|
(function (AppOpenState) {
|
|
7
9
|
AppOpenState[AppOpenState["Scheme"] = 0] = "Scheme";
|
|
@@ -16,8 +18,7 @@ var Messengers;
|
|
|
16
18
|
Messengers["Message"] = "message";
|
|
17
19
|
Messengers["Mail"] = "mail";
|
|
18
20
|
})(Messengers || (Messengers = {}));
|
|
19
|
-
|
|
20
|
-
var USER_AGENT = navigator.userAgent;
|
|
21
|
+
var IS_SUPPORT_INTENT = !/firefox|opr/i.test(USER_AGENT);
|
|
21
22
|
|
|
22
23
|
var OS;
|
|
23
24
|
(function (OS) {
|
|
@@ -202,46 +203,63 @@ var Platform = {
|
|
|
202
203
|
isStandalone: IS_STANDALONE,
|
|
203
204
|
};
|
|
204
205
|
|
|
205
|
-
function
|
|
206
|
+
function getTopmostWindow() {
|
|
207
|
+
if (window.top !== null)
|
|
208
|
+
return window.top;
|
|
209
|
+
return window;
|
|
210
|
+
}
|
|
211
|
+
function openURLViaHref(url, index) {
|
|
212
|
+
var top = getTopmostWindow();
|
|
206
213
|
var a = undefined;
|
|
207
214
|
try {
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
if (index === 0) {
|
|
216
|
+
top.location.href = url;
|
|
210
217
|
return;
|
|
211
|
-
|
|
218
|
+
}
|
|
219
|
+
a = top.document.createElement("a");
|
|
212
220
|
a.href = url;
|
|
213
221
|
a.style.display = "none";
|
|
214
222
|
a.setAttribute("aria-hidden", "true");
|
|
215
|
-
|
|
223
|
+
top.document.body.appendChild(a);
|
|
216
224
|
var fake = void 0;
|
|
217
225
|
try {
|
|
218
226
|
fake = new MouseEvent("click", {
|
|
219
227
|
bubbles: true,
|
|
220
228
|
cancelable: true,
|
|
221
|
-
view:
|
|
229
|
+
view: top
|
|
222
230
|
});
|
|
223
231
|
}
|
|
224
232
|
catch (_) {
|
|
225
|
-
fake =
|
|
226
|
-
fake.initMouseEvent("click", true, true,
|
|
233
|
+
fake = top.document.createEvent("MouseEvents");
|
|
234
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
227
235
|
}
|
|
228
236
|
a.dispatchEvent(fake);
|
|
229
|
-
if (a.click !== undefined)
|
|
230
|
-
a.click();
|
|
231
|
-
window.location.assign(url);
|
|
232
237
|
}
|
|
233
238
|
catch (_) {
|
|
234
239
|
}
|
|
235
240
|
finally {
|
|
236
241
|
if (a !== undefined)
|
|
237
|
-
|
|
242
|
+
top.document.body.removeChild(a);
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
245
|
+
function openURLViaIframe(url) {
|
|
246
|
+
var top = getTopmostWindow();
|
|
247
|
+
var iframe = document.createElement("iframe");
|
|
248
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
249
|
+
iframe.style.display = "none";
|
|
250
|
+
iframe.src = url;
|
|
251
|
+
top.document.body.appendChild(iframe);
|
|
252
|
+
window.setTimeout(function () {
|
|
253
|
+
try {
|
|
254
|
+
top.document.removeChild(iframe);
|
|
255
|
+
}
|
|
256
|
+
catch (_) {
|
|
257
|
+
}
|
|
258
|
+
}, 100);
|
|
242
259
|
}
|
|
243
|
-
function isDocumentHidden(
|
|
244
|
-
var
|
|
260
|
+
function isDocumentHidden() {
|
|
261
|
+
var top = getTopmostWindow();
|
|
262
|
+
var doc = top.document;
|
|
245
263
|
if (doc.visibilityState === "hidden")
|
|
246
264
|
return true;
|
|
247
265
|
if (doc.hidden !== undefined)
|
|
@@ -252,36 +270,18 @@ function isDocumentHidden(self) {
|
|
|
252
270
|
return !doc.hasFocus();
|
|
253
271
|
return true;
|
|
254
272
|
}
|
|
255
|
-
function tryOpenUrl(
|
|
256
|
-
var
|
|
257
|
-
var scopeDocument;
|
|
258
|
-
if (isIframeWindow(self)) {
|
|
259
|
-
try {
|
|
260
|
-
var top_1 = self.top;
|
|
261
|
-
if (top_1 === null)
|
|
262
|
-
return Promise.reject();
|
|
263
|
-
scopeWindow = top_1;
|
|
264
|
-
scopeDocument = scopeWindow.document;
|
|
265
|
-
}
|
|
266
|
-
catch (_) {
|
|
267
|
-
scopeWindow = self;
|
|
268
|
-
scopeDocument = scopeWindow.document;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
scopeWindow = self;
|
|
273
|
-
scopeDocument = self.document;
|
|
274
|
-
}
|
|
273
|
+
function tryOpenUrl(url, index, timeout) {
|
|
274
|
+
var top = getTopmostWindow();
|
|
275
275
|
if (Platform.os === OS.iOS) {
|
|
276
276
|
var visibilitychange_1;
|
|
277
277
|
var eventTarget_1;
|
|
278
278
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
279
279
|
visibilitychange_1 = "visibilitychange";
|
|
280
|
-
eventTarget_1 =
|
|
280
|
+
eventTarget_1 = top.document;
|
|
281
281
|
}
|
|
282
282
|
else {
|
|
283
283
|
visibilitychange_1 = "pagehide";
|
|
284
|
-
eventTarget_1 =
|
|
284
|
+
eventTarget_1 = top;
|
|
285
285
|
}
|
|
286
286
|
return new Promise(function (resolve, reject) {
|
|
287
287
|
var timeoutId;
|
|
@@ -307,7 +307,7 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
function onVisibilityChange() {
|
|
310
|
-
if (isDocumentHidden(
|
|
310
|
+
if (isDocumentHidden())
|
|
311
311
|
done(true);
|
|
312
312
|
}
|
|
313
313
|
timeoutId = window.setTimeout(function () {
|
|
@@ -315,7 +315,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
315
315
|
}, timeout);
|
|
316
316
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
317
317
|
try {
|
|
318
|
-
|
|
318
|
+
openURLViaIframe(url);
|
|
319
|
+
openURLViaHref(url, index);
|
|
319
320
|
}
|
|
320
321
|
catch (_) {
|
|
321
322
|
done(false);
|
|
@@ -329,8 +330,9 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
329
330
|
function cleanup() {
|
|
330
331
|
if (timeoutId)
|
|
331
332
|
clearTimeout(timeoutId);
|
|
332
|
-
|
|
333
|
-
|
|
333
|
+
top.removeEventListener("blur", onBlur);
|
|
334
|
+
top.removeEventListener("focus", onFocus);
|
|
335
|
+
top.document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
334
336
|
}
|
|
335
337
|
function done(success) {
|
|
336
338
|
if (!resolved) {
|
|
@@ -349,18 +351,24 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
349
351
|
}
|
|
350
352
|
function onBlur() {
|
|
351
353
|
clearTimeout(timeoutId);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
top.removeEventListener("blur", onBlur);
|
|
355
|
+
top.addEventListener("focus", onFocus);
|
|
354
356
|
}
|
|
355
357
|
function onFocus() {
|
|
356
358
|
done(true);
|
|
357
359
|
}
|
|
360
|
+
function onVisibilityChange() {
|
|
361
|
+
if (isDocumentHidden())
|
|
362
|
+
done(true);
|
|
363
|
+
}
|
|
358
364
|
timeoutId = window.setTimeout(function () {
|
|
359
365
|
done(false);
|
|
360
366
|
}, timeout);
|
|
361
|
-
|
|
367
|
+
top.addEventListener("blur", onBlur);
|
|
368
|
+
top.document.addEventListener("visibilitychange", onVisibilityChange);
|
|
362
369
|
try {
|
|
363
|
-
|
|
370
|
+
openURLViaIframe(url);
|
|
371
|
+
openURLViaHref(url, index);
|
|
364
372
|
}
|
|
365
373
|
catch (_) {
|
|
366
374
|
done(false);
|
|
@@ -495,20 +503,29 @@ function getDefaultTimeoutByOS(os) {
|
|
|
495
503
|
default: return 750;
|
|
496
504
|
}
|
|
497
505
|
}
|
|
498
|
-
function open(options
|
|
499
|
-
if (self === void 0) { self = window; }
|
|
506
|
+
function open(options) {
|
|
500
507
|
var os = OS_NAME;
|
|
501
508
|
var urls = [];
|
|
509
|
+
var tried = [];
|
|
502
510
|
var timeout;
|
|
511
|
+
function getURLOpenError() {
|
|
512
|
+
var triedUrlString = "";
|
|
513
|
+
for (var i = 0; i < urls.length; i++)
|
|
514
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
515
|
+
if (triedUrlString.length > 0)
|
|
516
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
517
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
518
|
+
}
|
|
503
519
|
if (os === OS.Android) {
|
|
504
520
|
var option = options[OS.Android];
|
|
505
521
|
if (option === undefined)
|
|
506
|
-
return Promise.reject();
|
|
522
|
+
return Promise.reject(getURLOpenError());
|
|
507
523
|
timeout = option.timeout;
|
|
508
524
|
var scheme = option.scheme;
|
|
509
525
|
var intent = option.intent;
|
|
510
526
|
var packageName = option.packageName;
|
|
511
527
|
var fallback = option.fallback;
|
|
528
|
+
var allowWebStore = option.allowWebStore;
|
|
512
529
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
513
530
|
var parsed = parseIntentURL(intent);
|
|
514
531
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -520,25 +537,28 @@ function open(options, self) {
|
|
|
520
537
|
}
|
|
521
538
|
if (scheme !== undefined && intent === undefined)
|
|
522
539
|
intent = createIntentURL(scheme, packageName, fallback);
|
|
523
|
-
if (intent !== undefined)
|
|
540
|
+
if (intent !== undefined && IS_SUPPORT_INTENT)
|
|
524
541
|
urls.push([intent, AppOpenState.Intent]);
|
|
525
542
|
if (scheme !== undefined)
|
|
526
543
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
527
544
|
if (fallback !== undefined)
|
|
528
545
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
529
546
|
if (packageName !== undefined)
|
|
530
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
547
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
548
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
549
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
531
550
|
}
|
|
532
551
|
else if (os === OS.iOS) {
|
|
533
552
|
var option = options[OS.iOS];
|
|
534
553
|
if (option === undefined)
|
|
535
|
-
return Promise.reject();
|
|
554
|
+
return Promise.reject(getURLOpenError());
|
|
536
555
|
timeout = option.timeout;
|
|
537
556
|
var scheme = option.scheme;
|
|
538
557
|
var packageName = option.packageName;
|
|
539
558
|
var trackId = option.trackId;
|
|
540
559
|
var universal = option.universal;
|
|
541
560
|
var fallback = option.fallback;
|
|
561
|
+
var allowWebStore = option.allowWebStore;
|
|
542
562
|
if (packageName !== undefined && trackId === undefined)
|
|
543
563
|
trackId = getTrackId(packageName);
|
|
544
564
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -548,32 +568,38 @@ function open(options, self) {
|
|
|
548
568
|
if (fallback !== undefined)
|
|
549
569
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
550
570
|
if (trackId !== undefined)
|
|
551
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
571
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
572
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
573
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
552
574
|
}
|
|
553
575
|
else if (os === OS.Windows) {
|
|
554
576
|
var option = options[OS.Windows];
|
|
555
577
|
if (option === undefined)
|
|
556
|
-
return Promise.reject();
|
|
578
|
+
return Promise.reject(getURLOpenError());
|
|
557
579
|
timeout = option.timeout;
|
|
558
580
|
var scheme = option.scheme;
|
|
559
581
|
var productId = option.productId;
|
|
560
582
|
var fallback = option.fallback;
|
|
583
|
+
var allowWebStore = option.allowWebStore;
|
|
561
584
|
if (scheme !== undefined)
|
|
562
585
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
563
586
|
if (fallback !== undefined)
|
|
564
587
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
565
588
|
if (productId !== undefined)
|
|
566
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
589
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
590
|
+
if (productId !== undefined && allowWebStore === true)
|
|
591
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
567
592
|
}
|
|
568
593
|
else if (os === OS.MacOS) {
|
|
569
594
|
var option = options[OS.MacOS];
|
|
570
595
|
if (option === undefined)
|
|
571
|
-
return Promise.reject();
|
|
596
|
+
return Promise.reject(getURLOpenError());
|
|
572
597
|
timeout = option.timeout;
|
|
573
598
|
var scheme = option.scheme;
|
|
574
599
|
var packageName = option.packageName;
|
|
575
600
|
var trackId = option.trackId;
|
|
576
601
|
var fallback = option.fallback;
|
|
602
|
+
var allowWebStore = option.allowWebStore;
|
|
577
603
|
if (packageName !== undefined && trackId === undefined)
|
|
578
604
|
trackId = getTrackId(packageName);
|
|
579
605
|
if (scheme !== undefined)
|
|
@@ -581,25 +607,26 @@ function open(options, self) {
|
|
|
581
607
|
if (fallback !== undefined)
|
|
582
608
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
583
609
|
if (trackId !== undefined)
|
|
584
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
610
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
611
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
612
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
585
613
|
}
|
|
586
614
|
if (timeout === undefined)
|
|
587
615
|
timeout = getDefaultTimeoutByOS(os);
|
|
588
616
|
return new Promise(function (resolve, reject) {
|
|
589
|
-
var tried = "\n";
|
|
590
617
|
function openURLSequential(index) {
|
|
591
618
|
if (index === void 0) { index = 0; }
|
|
592
619
|
if (index >= urls.length)
|
|
593
|
-
return reject(
|
|
620
|
+
return reject(getURLOpenError());
|
|
594
621
|
var entry = urls[index];
|
|
595
622
|
var url = entry[0];
|
|
596
|
-
tried =
|
|
597
|
-
return tryOpenUrl(
|
|
623
|
+
tried[index] = url;
|
|
624
|
+
return tryOpenUrl(url, index, timeout)
|
|
598
625
|
.then(function () {
|
|
599
626
|
resolve(entry[1]);
|
|
600
627
|
})
|
|
601
628
|
.catch(function () {
|
|
602
|
-
openURLSequential(
|
|
629
|
+
openURLSequential(index + 1);
|
|
603
630
|
});
|
|
604
631
|
}
|
|
605
632
|
return openURLSequential();
|
|
@@ -719,25 +746,22 @@ function normalize(value) {
|
|
|
719
746
|
result.body = "";
|
|
720
747
|
return result;
|
|
721
748
|
}
|
|
722
|
-
function openMessenger(options,
|
|
749
|
+
function openMessenger(options, type) {
|
|
723
750
|
options = normalize(options);
|
|
724
|
-
return tryOpenUrl(
|
|
751
|
+
return tryOpenUrl(type + ":" + options.to
|
|
725
752
|
+ "?cc=" + options.cc
|
|
726
753
|
+ "&bcc=" + options.bcc
|
|
727
754
|
+ "&subject=" + options.subject
|
|
728
755
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
729
756
|
}
|
|
730
|
-
function openMessengerTelephone(options
|
|
731
|
-
|
|
732
|
-
return openMessenger(options, self, "tel");
|
|
757
|
+
function openMessengerTelephone(options) {
|
|
758
|
+
return openMessenger(options, "tel");
|
|
733
759
|
}
|
|
734
|
-
function openMessengerMessage(options
|
|
735
|
-
|
|
736
|
-
return openMessenger(options, self, "sms");
|
|
760
|
+
function openMessengerMessage(options) {
|
|
761
|
+
return openMessenger(options, "sms");
|
|
737
762
|
}
|
|
738
|
-
function openMessengerMail(options
|
|
739
|
-
|
|
740
|
-
return openMessenger(options, self, "mailto");
|
|
763
|
+
function openMessengerMail(options) {
|
|
764
|
+
return openMessenger(options, "mailto");
|
|
741
765
|
}
|
|
742
766
|
|
|
743
767
|
var EasingError = createCustomError("EasingError");
|
package/dist/native.umd.js
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Native = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
-
var version = "1.0.
|
|
7
|
+
var version = "1.0.26";
|
|
8
8
|
var packageJSON = {
|
|
9
9
|
version: version};
|
|
10
10
|
|
|
11
|
+
var USER_AGENT = navigator.userAgent;
|
|
12
|
+
|
|
11
13
|
var AppOpenState;
|
|
12
14
|
(function (AppOpenState) {
|
|
13
15
|
AppOpenState[AppOpenState["Scheme"] = 0] = "Scheme";
|
|
@@ -22,8 +24,7 @@
|
|
|
22
24
|
Messengers["Message"] = "message";
|
|
23
25
|
Messengers["Mail"] = "mail";
|
|
24
26
|
})(Messengers || (Messengers = {}));
|
|
25
|
-
|
|
26
|
-
var USER_AGENT = navigator.userAgent;
|
|
27
|
+
var IS_SUPPORT_INTENT = !/firefox|opr/i.test(USER_AGENT);
|
|
27
28
|
|
|
28
29
|
var OS;
|
|
29
30
|
(function (OS) {
|
|
@@ -208,46 +209,63 @@
|
|
|
208
209
|
isStandalone: IS_STANDALONE,
|
|
209
210
|
};
|
|
210
211
|
|
|
211
|
-
function
|
|
212
|
+
function getTopmostWindow() {
|
|
213
|
+
if (window.top !== null)
|
|
214
|
+
return window.top;
|
|
215
|
+
return window;
|
|
216
|
+
}
|
|
217
|
+
function openURLViaHref(url, index) {
|
|
218
|
+
var top = getTopmostWindow();
|
|
212
219
|
var a = undefined;
|
|
213
220
|
try {
|
|
214
|
-
|
|
215
|
-
|
|
221
|
+
if (index === 0) {
|
|
222
|
+
top.location.href = url;
|
|
216
223
|
return;
|
|
217
|
-
|
|
224
|
+
}
|
|
225
|
+
a = top.document.createElement("a");
|
|
218
226
|
a.href = url;
|
|
219
227
|
a.style.display = "none";
|
|
220
228
|
a.setAttribute("aria-hidden", "true");
|
|
221
|
-
|
|
229
|
+
top.document.body.appendChild(a);
|
|
222
230
|
var fake = void 0;
|
|
223
231
|
try {
|
|
224
232
|
fake = new MouseEvent("click", {
|
|
225
233
|
bubbles: true,
|
|
226
234
|
cancelable: true,
|
|
227
|
-
view:
|
|
235
|
+
view: top
|
|
228
236
|
});
|
|
229
237
|
}
|
|
230
238
|
catch (_) {
|
|
231
|
-
fake =
|
|
232
|
-
fake.initMouseEvent("click", true, true,
|
|
239
|
+
fake = top.document.createEvent("MouseEvents");
|
|
240
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
233
241
|
}
|
|
234
242
|
a.dispatchEvent(fake);
|
|
235
|
-
if (a.click !== undefined)
|
|
236
|
-
a.click();
|
|
237
|
-
window.location.assign(url);
|
|
238
243
|
}
|
|
239
244
|
catch (_) {
|
|
240
245
|
}
|
|
241
246
|
finally {
|
|
242
247
|
if (a !== undefined)
|
|
243
|
-
|
|
248
|
+
top.document.body.removeChild(a);
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
251
|
+
function openURLViaIframe(url) {
|
|
252
|
+
var top = getTopmostWindow();
|
|
253
|
+
var iframe = document.createElement("iframe");
|
|
254
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
255
|
+
iframe.style.display = "none";
|
|
256
|
+
iframe.src = url;
|
|
257
|
+
top.document.body.appendChild(iframe);
|
|
258
|
+
window.setTimeout(function () {
|
|
259
|
+
try {
|
|
260
|
+
top.document.removeChild(iframe);
|
|
261
|
+
}
|
|
262
|
+
catch (_) {
|
|
263
|
+
}
|
|
264
|
+
}, 100);
|
|
248
265
|
}
|
|
249
|
-
function isDocumentHidden(
|
|
250
|
-
var
|
|
266
|
+
function isDocumentHidden() {
|
|
267
|
+
var top = getTopmostWindow();
|
|
268
|
+
var doc = top.document;
|
|
251
269
|
if (doc.visibilityState === "hidden")
|
|
252
270
|
return true;
|
|
253
271
|
if (doc.hidden !== undefined)
|
|
@@ -258,36 +276,18 @@
|
|
|
258
276
|
return !doc.hasFocus();
|
|
259
277
|
return true;
|
|
260
278
|
}
|
|
261
|
-
function tryOpenUrl(
|
|
262
|
-
var
|
|
263
|
-
var scopeDocument;
|
|
264
|
-
if (isIframeWindow(self)) {
|
|
265
|
-
try {
|
|
266
|
-
var top_1 = self.top;
|
|
267
|
-
if (top_1 === null)
|
|
268
|
-
return Promise.reject();
|
|
269
|
-
scopeWindow = top_1;
|
|
270
|
-
scopeDocument = scopeWindow.document;
|
|
271
|
-
}
|
|
272
|
-
catch (_) {
|
|
273
|
-
scopeWindow = self;
|
|
274
|
-
scopeDocument = scopeWindow.document;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
scopeWindow = self;
|
|
279
|
-
scopeDocument = self.document;
|
|
280
|
-
}
|
|
279
|
+
function tryOpenUrl(url, index, timeout) {
|
|
280
|
+
var top = getTopmostWindow();
|
|
281
281
|
if (Platform.os === OS.iOS) {
|
|
282
282
|
var visibilitychange_1;
|
|
283
283
|
var eventTarget_1;
|
|
284
284
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
285
285
|
visibilitychange_1 = "visibilitychange";
|
|
286
|
-
eventTarget_1 =
|
|
286
|
+
eventTarget_1 = top.document;
|
|
287
287
|
}
|
|
288
288
|
else {
|
|
289
289
|
visibilitychange_1 = "pagehide";
|
|
290
|
-
eventTarget_1 =
|
|
290
|
+
eventTarget_1 = top;
|
|
291
291
|
}
|
|
292
292
|
return new Promise(function (resolve, reject) {
|
|
293
293
|
var timeoutId;
|
|
@@ -313,7 +313,7 @@
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
function onVisibilityChange() {
|
|
316
|
-
if (isDocumentHidden(
|
|
316
|
+
if (isDocumentHidden())
|
|
317
317
|
done(true);
|
|
318
318
|
}
|
|
319
319
|
timeoutId = window.setTimeout(function () {
|
|
@@ -321,7 +321,8 @@
|
|
|
321
321
|
}, timeout);
|
|
322
322
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
323
323
|
try {
|
|
324
|
-
|
|
324
|
+
openURLViaIframe(url);
|
|
325
|
+
openURLViaHref(url, index);
|
|
325
326
|
}
|
|
326
327
|
catch (_) {
|
|
327
328
|
done(false);
|
|
@@ -335,8 +336,9 @@
|
|
|
335
336
|
function cleanup() {
|
|
336
337
|
if (timeoutId)
|
|
337
338
|
clearTimeout(timeoutId);
|
|
338
|
-
|
|
339
|
-
|
|
339
|
+
top.removeEventListener("blur", onBlur);
|
|
340
|
+
top.removeEventListener("focus", onFocus);
|
|
341
|
+
top.document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
340
342
|
}
|
|
341
343
|
function done(success) {
|
|
342
344
|
if (!resolved) {
|
|
@@ -355,18 +357,24 @@
|
|
|
355
357
|
}
|
|
356
358
|
function onBlur() {
|
|
357
359
|
clearTimeout(timeoutId);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
top.removeEventListener("blur", onBlur);
|
|
361
|
+
top.addEventListener("focus", onFocus);
|
|
360
362
|
}
|
|
361
363
|
function onFocus() {
|
|
362
364
|
done(true);
|
|
363
365
|
}
|
|
366
|
+
function onVisibilityChange() {
|
|
367
|
+
if (isDocumentHidden())
|
|
368
|
+
done(true);
|
|
369
|
+
}
|
|
364
370
|
timeoutId = window.setTimeout(function () {
|
|
365
371
|
done(false);
|
|
366
372
|
}, timeout);
|
|
367
|
-
|
|
373
|
+
top.addEventListener("blur", onBlur);
|
|
374
|
+
top.document.addEventListener("visibilitychange", onVisibilityChange);
|
|
368
375
|
try {
|
|
369
|
-
|
|
376
|
+
openURLViaIframe(url);
|
|
377
|
+
openURLViaHref(url, index);
|
|
370
378
|
}
|
|
371
379
|
catch (_) {
|
|
372
380
|
done(false);
|
|
@@ -501,20 +509,29 @@
|
|
|
501
509
|
default: return 750;
|
|
502
510
|
}
|
|
503
511
|
}
|
|
504
|
-
function open(options
|
|
505
|
-
if (self === void 0) { self = window; }
|
|
512
|
+
function open(options) {
|
|
506
513
|
var os = OS_NAME;
|
|
507
514
|
var urls = [];
|
|
515
|
+
var tried = [];
|
|
508
516
|
var timeout;
|
|
517
|
+
function getURLOpenError() {
|
|
518
|
+
var triedUrlString = "";
|
|
519
|
+
for (var i = 0; i < urls.length; i++)
|
|
520
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
521
|
+
if (triedUrlString.length > 0)
|
|
522
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
523
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
524
|
+
}
|
|
509
525
|
if (os === OS.Android) {
|
|
510
526
|
var option = options[OS.Android];
|
|
511
527
|
if (option === undefined)
|
|
512
|
-
return Promise.reject();
|
|
528
|
+
return Promise.reject(getURLOpenError());
|
|
513
529
|
timeout = option.timeout;
|
|
514
530
|
var scheme = option.scheme;
|
|
515
531
|
var intent = option.intent;
|
|
516
532
|
var packageName = option.packageName;
|
|
517
533
|
var fallback = option.fallback;
|
|
534
|
+
var allowWebStore = option.allowWebStore;
|
|
518
535
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
519
536
|
var parsed = parseIntentURL(intent);
|
|
520
537
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -526,25 +543,28 @@
|
|
|
526
543
|
}
|
|
527
544
|
if (scheme !== undefined && intent === undefined)
|
|
528
545
|
intent = createIntentURL(scheme, packageName, fallback);
|
|
529
|
-
if (intent !== undefined)
|
|
546
|
+
if (intent !== undefined && IS_SUPPORT_INTENT)
|
|
530
547
|
urls.push([intent, AppOpenState.Intent]);
|
|
531
548
|
if (scheme !== undefined)
|
|
532
549
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
533
550
|
if (fallback !== undefined)
|
|
534
551
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
535
552
|
if (packageName !== undefined)
|
|
536
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
553
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
554
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
555
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
537
556
|
}
|
|
538
557
|
else if (os === OS.iOS) {
|
|
539
558
|
var option = options[OS.iOS];
|
|
540
559
|
if (option === undefined)
|
|
541
|
-
return Promise.reject();
|
|
560
|
+
return Promise.reject(getURLOpenError());
|
|
542
561
|
timeout = option.timeout;
|
|
543
562
|
var scheme = option.scheme;
|
|
544
563
|
var packageName = option.packageName;
|
|
545
564
|
var trackId = option.trackId;
|
|
546
565
|
var universal = option.universal;
|
|
547
566
|
var fallback = option.fallback;
|
|
567
|
+
var allowWebStore = option.allowWebStore;
|
|
548
568
|
if (packageName !== undefined && trackId === undefined)
|
|
549
569
|
trackId = getTrackId(packageName);
|
|
550
570
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -554,32 +574,38 @@
|
|
|
554
574
|
if (fallback !== undefined)
|
|
555
575
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
556
576
|
if (trackId !== undefined)
|
|
557
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
577
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
578
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
579
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
558
580
|
}
|
|
559
581
|
else if (os === OS.Windows) {
|
|
560
582
|
var option = options[OS.Windows];
|
|
561
583
|
if (option === undefined)
|
|
562
|
-
return Promise.reject();
|
|
584
|
+
return Promise.reject(getURLOpenError());
|
|
563
585
|
timeout = option.timeout;
|
|
564
586
|
var scheme = option.scheme;
|
|
565
587
|
var productId = option.productId;
|
|
566
588
|
var fallback = option.fallback;
|
|
589
|
+
var allowWebStore = option.allowWebStore;
|
|
567
590
|
if (scheme !== undefined)
|
|
568
591
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
569
592
|
if (fallback !== undefined)
|
|
570
593
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
571
594
|
if (productId !== undefined)
|
|
572
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
595
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
596
|
+
if (productId !== undefined && allowWebStore === true)
|
|
597
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
573
598
|
}
|
|
574
599
|
else if (os === OS.MacOS) {
|
|
575
600
|
var option = options[OS.MacOS];
|
|
576
601
|
if (option === undefined)
|
|
577
|
-
return Promise.reject();
|
|
602
|
+
return Promise.reject(getURLOpenError());
|
|
578
603
|
timeout = option.timeout;
|
|
579
604
|
var scheme = option.scheme;
|
|
580
605
|
var packageName = option.packageName;
|
|
581
606
|
var trackId = option.trackId;
|
|
582
607
|
var fallback = option.fallback;
|
|
608
|
+
var allowWebStore = option.allowWebStore;
|
|
583
609
|
if (packageName !== undefined && trackId === undefined)
|
|
584
610
|
trackId = getTrackId(packageName);
|
|
585
611
|
if (scheme !== undefined)
|
|
@@ -587,25 +613,26 @@
|
|
|
587
613
|
if (fallback !== undefined)
|
|
588
614
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
589
615
|
if (trackId !== undefined)
|
|
590
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
616
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
617
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
618
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
591
619
|
}
|
|
592
620
|
if (timeout === undefined)
|
|
593
621
|
timeout = getDefaultTimeoutByOS(os);
|
|
594
622
|
return new Promise(function (resolve, reject) {
|
|
595
|
-
var tried = "\n";
|
|
596
623
|
function openURLSequential(index) {
|
|
597
624
|
if (index === void 0) { index = 0; }
|
|
598
625
|
if (index >= urls.length)
|
|
599
|
-
return reject(
|
|
626
|
+
return reject(getURLOpenError());
|
|
600
627
|
var entry = urls[index];
|
|
601
628
|
var url = entry[0];
|
|
602
|
-
tried =
|
|
603
|
-
return tryOpenUrl(
|
|
629
|
+
tried[index] = url;
|
|
630
|
+
return tryOpenUrl(url, index, timeout)
|
|
604
631
|
.then(function () {
|
|
605
632
|
resolve(entry[1]);
|
|
606
633
|
})
|
|
607
634
|
.catch(function () {
|
|
608
|
-
openURLSequential(
|
|
635
|
+
openURLSequential(index + 1);
|
|
609
636
|
});
|
|
610
637
|
}
|
|
611
638
|
return openURLSequential();
|
|
@@ -725,25 +752,22 @@
|
|
|
725
752
|
result.body = "";
|
|
726
753
|
return result;
|
|
727
754
|
}
|
|
728
|
-
function openMessenger(options,
|
|
755
|
+
function openMessenger(options, type) {
|
|
729
756
|
options = normalize(options);
|
|
730
|
-
return tryOpenUrl(
|
|
757
|
+
return tryOpenUrl(type + ":" + options.to
|
|
731
758
|
+ "?cc=" + options.cc
|
|
732
759
|
+ "&bcc=" + options.bcc
|
|
733
760
|
+ "&subject=" + options.subject
|
|
734
761
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
735
762
|
}
|
|
736
|
-
function openMessengerTelephone(options
|
|
737
|
-
|
|
738
|
-
return openMessenger(options, self, "tel");
|
|
763
|
+
function openMessengerTelephone(options) {
|
|
764
|
+
return openMessenger(options, "tel");
|
|
739
765
|
}
|
|
740
|
-
function openMessengerMessage(options
|
|
741
|
-
|
|
742
|
-
return openMessenger(options, self, "sms");
|
|
766
|
+
function openMessengerMessage(options) {
|
|
767
|
+
return openMessenger(options, "sms");
|
|
743
768
|
}
|
|
744
|
-
function openMessengerMail(options
|
|
745
|
-
|
|
746
|
-
return openMessenger(options, self, "mailto");
|
|
769
|
+
function openMessengerMail(options) {
|
|
770
|
+
return openMessenger(options, "mailto");
|
|
747
771
|
}
|
|
748
772
|
|
|
749
773
|
var EasingError = createCustomError("EasingError");
|
package/dist/src/types/app.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function tryOpenUrl(
|
|
1
|
+
export default function tryOpenUrl(url: string, index: number, timeout: number): Promise<void>;
|