native-fn 1.0.24 → 1.0.25
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 +90 -73
- package/dist/native.mjs +90 -73
- package/dist/native.umd.js +90 -73
- 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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var version = "1.0.
|
|
3
|
+
var version = "1.0.25";
|
|
4
4
|
var packageJSON = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
@@ -204,46 +204,63 @@ var Platform = {
|
|
|
204
204
|
isStandalone: IS_STANDALONE,
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
function
|
|
207
|
+
function getTopmostWindow() {
|
|
208
|
+
if (window.top !== null)
|
|
209
|
+
return window.top;
|
|
210
|
+
return window;
|
|
211
|
+
}
|
|
212
|
+
function openURLViaHref(url, index) {
|
|
213
|
+
var top = getTopmostWindow();
|
|
208
214
|
var a = undefined;
|
|
209
215
|
try {
|
|
210
|
-
|
|
211
|
-
|
|
216
|
+
if (index === 0) {
|
|
217
|
+
top.location.href = url;
|
|
212
218
|
return;
|
|
213
|
-
|
|
219
|
+
}
|
|
220
|
+
a = top.document.createElement("a");
|
|
214
221
|
a.href = url;
|
|
215
222
|
a.style.display = "none";
|
|
216
223
|
a.setAttribute("aria-hidden", "true");
|
|
217
|
-
|
|
224
|
+
top.document.body.appendChild(a);
|
|
218
225
|
var fake = void 0;
|
|
219
226
|
try {
|
|
220
227
|
fake = new MouseEvent("click", {
|
|
221
228
|
bubbles: true,
|
|
222
229
|
cancelable: true,
|
|
223
|
-
view:
|
|
230
|
+
view: top
|
|
224
231
|
});
|
|
225
232
|
}
|
|
226
233
|
catch (_) {
|
|
227
|
-
fake =
|
|
228
|
-
fake.initMouseEvent("click", true, true,
|
|
234
|
+
fake = top.document.createEvent("MouseEvents");
|
|
235
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
229
236
|
}
|
|
230
237
|
a.dispatchEvent(fake);
|
|
231
|
-
if (a.click !== undefined)
|
|
232
|
-
a.click();
|
|
233
|
-
window.location.assign(url);
|
|
234
238
|
}
|
|
235
239
|
catch (_) {
|
|
236
240
|
}
|
|
237
241
|
finally {
|
|
238
242
|
if (a !== undefined)
|
|
239
|
-
|
|
243
|
+
top.document.body.removeChild(a);
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
246
|
+
function openURLViaIframe(url) {
|
|
247
|
+
var top = getTopmostWindow();
|
|
248
|
+
var iframe = document.createElement("iframe");
|
|
249
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
250
|
+
iframe.style.display = "none";
|
|
251
|
+
iframe.src = url;
|
|
252
|
+
top.document.body.appendChild(iframe);
|
|
253
|
+
window.setTimeout(function () {
|
|
254
|
+
try {
|
|
255
|
+
top.document.removeChild(iframe);
|
|
256
|
+
}
|
|
257
|
+
catch (_) {
|
|
258
|
+
}
|
|
259
|
+
}, 100);
|
|
244
260
|
}
|
|
245
|
-
function isDocumentHidden(
|
|
246
|
-
var
|
|
261
|
+
function isDocumentHidden() {
|
|
262
|
+
var top = getTopmostWindow();
|
|
263
|
+
var doc = top.document;
|
|
247
264
|
if (doc.visibilityState === "hidden")
|
|
248
265
|
return true;
|
|
249
266
|
if (doc.hidden !== undefined)
|
|
@@ -254,36 +271,18 @@ function isDocumentHidden(self) {
|
|
|
254
271
|
return !doc.hasFocus();
|
|
255
272
|
return true;
|
|
256
273
|
}
|
|
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
|
-
}
|
|
274
|
+
function tryOpenUrl(url, index, timeout) {
|
|
275
|
+
var top = getTopmostWindow();
|
|
277
276
|
if (Platform.os === OS.iOS) {
|
|
278
277
|
var visibilitychange_1;
|
|
279
278
|
var eventTarget_1;
|
|
280
279
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
281
280
|
visibilitychange_1 = "visibilitychange";
|
|
282
|
-
eventTarget_1 =
|
|
281
|
+
eventTarget_1 = top.document;
|
|
283
282
|
}
|
|
284
283
|
else {
|
|
285
284
|
visibilitychange_1 = "pagehide";
|
|
286
|
-
eventTarget_1 =
|
|
285
|
+
eventTarget_1 = top;
|
|
287
286
|
}
|
|
288
287
|
return new Promise(function (resolve, reject) {
|
|
289
288
|
var timeoutId;
|
|
@@ -309,7 +308,7 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
309
308
|
}
|
|
310
309
|
}
|
|
311
310
|
function onVisibilityChange() {
|
|
312
|
-
if (isDocumentHidden(
|
|
311
|
+
if (isDocumentHidden())
|
|
313
312
|
done(true);
|
|
314
313
|
}
|
|
315
314
|
timeoutId = window.setTimeout(function () {
|
|
@@ -317,7 +316,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
317
316
|
}, timeout);
|
|
318
317
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
319
318
|
try {
|
|
320
|
-
|
|
319
|
+
openURLViaIframe(url);
|
|
320
|
+
openURLViaHref(url, index);
|
|
321
321
|
}
|
|
322
322
|
catch (_) {
|
|
323
323
|
done(false);
|
|
@@ -331,8 +331,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
331
331
|
function cleanup() {
|
|
332
332
|
if (timeoutId)
|
|
333
333
|
clearTimeout(timeoutId);
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
top.removeEventListener("blur", onBlur);
|
|
335
|
+
top.removeEventListener("focus", onFocus);
|
|
336
336
|
}
|
|
337
337
|
function done(success) {
|
|
338
338
|
if (!resolved) {
|
|
@@ -351,8 +351,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
351
351
|
}
|
|
352
352
|
function onBlur() {
|
|
353
353
|
clearTimeout(timeoutId);
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
top.removeEventListener("blur", onBlur);
|
|
355
|
+
top.addEventListener("focus", onFocus);
|
|
356
356
|
}
|
|
357
357
|
function onFocus() {
|
|
358
358
|
done(true);
|
|
@@ -360,9 +360,10 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
360
360
|
timeoutId = window.setTimeout(function () {
|
|
361
361
|
done(false);
|
|
362
362
|
}, timeout);
|
|
363
|
-
|
|
363
|
+
top.addEventListener("blur", onBlur);
|
|
364
364
|
try {
|
|
365
|
-
|
|
365
|
+
openURLViaIframe(url);
|
|
366
|
+
openURLViaHref(url, index);
|
|
366
367
|
}
|
|
367
368
|
catch (_) {
|
|
368
369
|
done(false);
|
|
@@ -497,20 +498,29 @@ function getDefaultTimeoutByOS(os) {
|
|
|
497
498
|
default: return 750;
|
|
498
499
|
}
|
|
499
500
|
}
|
|
500
|
-
function open(options
|
|
501
|
-
if (self === void 0) { self = window; }
|
|
501
|
+
function open(options) {
|
|
502
502
|
var os = OS_NAME;
|
|
503
503
|
var urls = [];
|
|
504
|
+
var tried = [];
|
|
504
505
|
var timeout;
|
|
506
|
+
function getURLOpenError() {
|
|
507
|
+
var triedUrlString = "";
|
|
508
|
+
for (var i = 0; i < urls.length; i++)
|
|
509
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
510
|
+
if (triedUrlString.length > 0)
|
|
511
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
512
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
513
|
+
}
|
|
505
514
|
if (os === OS.Android) {
|
|
506
515
|
var option = options[OS.Android];
|
|
507
516
|
if (option === undefined)
|
|
508
|
-
return Promise.reject();
|
|
517
|
+
return Promise.reject(getURLOpenError());
|
|
509
518
|
timeout = option.timeout;
|
|
510
519
|
var scheme = option.scheme;
|
|
511
520
|
var intent = option.intent;
|
|
512
521
|
var packageName = option.packageName;
|
|
513
522
|
var fallback = option.fallback;
|
|
523
|
+
var allowWebStore = option.allowWebStore;
|
|
514
524
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
515
525
|
var parsed = parseIntentURL(intent);
|
|
516
526
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -529,18 +539,21 @@ function open(options, self) {
|
|
|
529
539
|
if (fallback !== undefined)
|
|
530
540
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
531
541
|
if (packageName !== undefined)
|
|
532
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
542
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
543
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
544
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
533
545
|
}
|
|
534
546
|
else if (os === OS.iOS) {
|
|
535
547
|
var option = options[OS.iOS];
|
|
536
548
|
if (option === undefined)
|
|
537
|
-
return Promise.reject();
|
|
549
|
+
return Promise.reject(getURLOpenError());
|
|
538
550
|
timeout = option.timeout;
|
|
539
551
|
var scheme = option.scheme;
|
|
540
552
|
var packageName = option.packageName;
|
|
541
553
|
var trackId = option.trackId;
|
|
542
554
|
var universal = option.universal;
|
|
543
555
|
var fallback = option.fallback;
|
|
556
|
+
var allowWebStore = option.allowWebStore;
|
|
544
557
|
if (packageName !== undefined && trackId === undefined)
|
|
545
558
|
trackId = getTrackId(packageName);
|
|
546
559
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -550,32 +563,38 @@ function open(options, self) {
|
|
|
550
563
|
if (fallback !== undefined)
|
|
551
564
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
552
565
|
if (trackId !== undefined)
|
|
553
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
566
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
567
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
568
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
554
569
|
}
|
|
555
570
|
else if (os === OS.Windows) {
|
|
556
571
|
var option = options[OS.Windows];
|
|
557
572
|
if (option === undefined)
|
|
558
|
-
return Promise.reject();
|
|
573
|
+
return Promise.reject(getURLOpenError());
|
|
559
574
|
timeout = option.timeout;
|
|
560
575
|
var scheme = option.scheme;
|
|
561
576
|
var productId = option.productId;
|
|
562
577
|
var fallback = option.fallback;
|
|
578
|
+
var allowWebStore = option.allowWebStore;
|
|
563
579
|
if (scheme !== undefined)
|
|
564
580
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
565
581
|
if (fallback !== undefined)
|
|
566
582
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
567
583
|
if (productId !== undefined)
|
|
568
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
584
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
585
|
+
if (productId !== undefined && allowWebStore === true)
|
|
586
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
569
587
|
}
|
|
570
588
|
else if (os === OS.MacOS) {
|
|
571
589
|
var option = options[OS.MacOS];
|
|
572
590
|
if (option === undefined)
|
|
573
|
-
return Promise.reject();
|
|
591
|
+
return Promise.reject(getURLOpenError());
|
|
574
592
|
timeout = option.timeout;
|
|
575
593
|
var scheme = option.scheme;
|
|
576
594
|
var packageName = option.packageName;
|
|
577
595
|
var trackId = option.trackId;
|
|
578
596
|
var fallback = option.fallback;
|
|
597
|
+
var allowWebStore = option.allowWebStore;
|
|
579
598
|
if (packageName !== undefined && trackId === undefined)
|
|
580
599
|
trackId = getTrackId(packageName);
|
|
581
600
|
if (scheme !== undefined)
|
|
@@ -583,25 +602,26 @@ function open(options, self) {
|
|
|
583
602
|
if (fallback !== undefined)
|
|
584
603
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
585
604
|
if (trackId !== undefined)
|
|
586
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
605
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
606
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
607
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
587
608
|
}
|
|
588
609
|
if (timeout === undefined)
|
|
589
610
|
timeout = getDefaultTimeoutByOS(os);
|
|
590
611
|
return new Promise(function (resolve, reject) {
|
|
591
|
-
var tried = "\n";
|
|
592
612
|
function openURLSequential(index) {
|
|
593
613
|
if (index === void 0) { index = 0; }
|
|
594
614
|
if (index >= urls.length)
|
|
595
|
-
return reject(
|
|
615
|
+
return reject(getURLOpenError());
|
|
596
616
|
var entry = urls[index];
|
|
597
617
|
var url = entry[0];
|
|
598
|
-
tried =
|
|
599
|
-
return tryOpenUrl(
|
|
618
|
+
tried[index] = url;
|
|
619
|
+
return tryOpenUrl(url, index, timeout)
|
|
600
620
|
.then(function () {
|
|
601
621
|
resolve(entry[1]);
|
|
602
622
|
})
|
|
603
623
|
.catch(function () {
|
|
604
|
-
openURLSequential(
|
|
624
|
+
openURLSequential(index + 1);
|
|
605
625
|
});
|
|
606
626
|
}
|
|
607
627
|
return openURLSequential();
|
|
@@ -721,25 +741,22 @@ function normalize(value) {
|
|
|
721
741
|
result.body = "";
|
|
722
742
|
return result;
|
|
723
743
|
}
|
|
724
|
-
function openMessenger(options,
|
|
744
|
+
function openMessenger(options, type) {
|
|
725
745
|
options = normalize(options);
|
|
726
|
-
return tryOpenUrl(
|
|
746
|
+
return tryOpenUrl(type + ":" + options.to
|
|
727
747
|
+ "?cc=" + options.cc
|
|
728
748
|
+ "&bcc=" + options.bcc
|
|
729
749
|
+ "&subject=" + options.subject
|
|
730
750
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
731
751
|
}
|
|
732
|
-
function openMessengerTelephone(options
|
|
733
|
-
|
|
734
|
-
return openMessenger(options, self, "tel");
|
|
752
|
+
function openMessengerTelephone(options) {
|
|
753
|
+
return openMessenger(options, "tel");
|
|
735
754
|
}
|
|
736
|
-
function openMessengerMessage(options
|
|
737
|
-
|
|
738
|
-
return openMessenger(options, self, "sms");
|
|
755
|
+
function openMessengerMessage(options) {
|
|
756
|
+
return openMessenger(options, "sms");
|
|
739
757
|
}
|
|
740
|
-
function openMessengerMail(options
|
|
741
|
-
|
|
742
|
-
return openMessenger(options, self, "mailto");
|
|
758
|
+
function openMessengerMail(options) {
|
|
759
|
+
return openMessenger(options, "mailto");
|
|
743
760
|
}
|
|
744
761
|
|
|
745
762
|
var EasingError = createCustomError("EasingError");
|
package/dist/native.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "1.0.
|
|
1
|
+
var version = "1.0.25";
|
|
2
2
|
var packageJSON = {
|
|
3
3
|
version: version};
|
|
4
4
|
|
|
@@ -202,46 +202,63 @@ var Platform = {
|
|
|
202
202
|
isStandalone: IS_STANDALONE,
|
|
203
203
|
};
|
|
204
204
|
|
|
205
|
-
function
|
|
205
|
+
function getTopmostWindow() {
|
|
206
|
+
if (window.top !== null)
|
|
207
|
+
return window.top;
|
|
208
|
+
return window;
|
|
209
|
+
}
|
|
210
|
+
function openURLViaHref(url, index) {
|
|
211
|
+
var top = getTopmostWindow();
|
|
206
212
|
var a = undefined;
|
|
207
213
|
try {
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
if (index === 0) {
|
|
215
|
+
top.location.href = url;
|
|
210
216
|
return;
|
|
211
|
-
|
|
217
|
+
}
|
|
218
|
+
a = top.document.createElement("a");
|
|
212
219
|
a.href = url;
|
|
213
220
|
a.style.display = "none";
|
|
214
221
|
a.setAttribute("aria-hidden", "true");
|
|
215
|
-
|
|
222
|
+
top.document.body.appendChild(a);
|
|
216
223
|
var fake = void 0;
|
|
217
224
|
try {
|
|
218
225
|
fake = new MouseEvent("click", {
|
|
219
226
|
bubbles: true,
|
|
220
227
|
cancelable: true,
|
|
221
|
-
view:
|
|
228
|
+
view: top
|
|
222
229
|
});
|
|
223
230
|
}
|
|
224
231
|
catch (_) {
|
|
225
|
-
fake =
|
|
226
|
-
fake.initMouseEvent("click", true, true,
|
|
232
|
+
fake = top.document.createEvent("MouseEvents");
|
|
233
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
227
234
|
}
|
|
228
235
|
a.dispatchEvent(fake);
|
|
229
|
-
if (a.click !== undefined)
|
|
230
|
-
a.click();
|
|
231
|
-
window.location.assign(url);
|
|
232
236
|
}
|
|
233
237
|
catch (_) {
|
|
234
238
|
}
|
|
235
239
|
finally {
|
|
236
240
|
if (a !== undefined)
|
|
237
|
-
|
|
241
|
+
top.document.body.removeChild(a);
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
244
|
+
function openURLViaIframe(url) {
|
|
245
|
+
var top = getTopmostWindow();
|
|
246
|
+
var iframe = document.createElement("iframe");
|
|
247
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
248
|
+
iframe.style.display = "none";
|
|
249
|
+
iframe.src = url;
|
|
250
|
+
top.document.body.appendChild(iframe);
|
|
251
|
+
window.setTimeout(function () {
|
|
252
|
+
try {
|
|
253
|
+
top.document.removeChild(iframe);
|
|
254
|
+
}
|
|
255
|
+
catch (_) {
|
|
256
|
+
}
|
|
257
|
+
}, 100);
|
|
242
258
|
}
|
|
243
|
-
function isDocumentHidden(
|
|
244
|
-
var
|
|
259
|
+
function isDocumentHidden() {
|
|
260
|
+
var top = getTopmostWindow();
|
|
261
|
+
var doc = top.document;
|
|
245
262
|
if (doc.visibilityState === "hidden")
|
|
246
263
|
return true;
|
|
247
264
|
if (doc.hidden !== undefined)
|
|
@@ -252,36 +269,18 @@ function isDocumentHidden(self) {
|
|
|
252
269
|
return !doc.hasFocus();
|
|
253
270
|
return true;
|
|
254
271
|
}
|
|
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
|
-
}
|
|
272
|
+
function tryOpenUrl(url, index, timeout) {
|
|
273
|
+
var top = getTopmostWindow();
|
|
275
274
|
if (Platform.os === OS.iOS) {
|
|
276
275
|
var visibilitychange_1;
|
|
277
276
|
var eventTarget_1;
|
|
278
277
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
279
278
|
visibilitychange_1 = "visibilitychange";
|
|
280
|
-
eventTarget_1 =
|
|
279
|
+
eventTarget_1 = top.document;
|
|
281
280
|
}
|
|
282
281
|
else {
|
|
283
282
|
visibilitychange_1 = "pagehide";
|
|
284
|
-
eventTarget_1 =
|
|
283
|
+
eventTarget_1 = top;
|
|
285
284
|
}
|
|
286
285
|
return new Promise(function (resolve, reject) {
|
|
287
286
|
var timeoutId;
|
|
@@ -307,7 +306,7 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
307
306
|
}
|
|
308
307
|
}
|
|
309
308
|
function onVisibilityChange() {
|
|
310
|
-
if (isDocumentHidden(
|
|
309
|
+
if (isDocumentHidden())
|
|
311
310
|
done(true);
|
|
312
311
|
}
|
|
313
312
|
timeoutId = window.setTimeout(function () {
|
|
@@ -315,7 +314,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
315
314
|
}, timeout);
|
|
316
315
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
317
316
|
try {
|
|
318
|
-
|
|
317
|
+
openURLViaIframe(url);
|
|
318
|
+
openURLViaHref(url, index);
|
|
319
319
|
}
|
|
320
320
|
catch (_) {
|
|
321
321
|
done(false);
|
|
@@ -329,8 +329,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
329
329
|
function cleanup() {
|
|
330
330
|
if (timeoutId)
|
|
331
331
|
clearTimeout(timeoutId);
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
top.removeEventListener("blur", onBlur);
|
|
333
|
+
top.removeEventListener("focus", onFocus);
|
|
334
334
|
}
|
|
335
335
|
function done(success) {
|
|
336
336
|
if (!resolved) {
|
|
@@ -349,8 +349,8 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
349
349
|
}
|
|
350
350
|
function onBlur() {
|
|
351
351
|
clearTimeout(timeoutId);
|
|
352
|
-
|
|
353
|
-
|
|
352
|
+
top.removeEventListener("blur", onBlur);
|
|
353
|
+
top.addEventListener("focus", onFocus);
|
|
354
354
|
}
|
|
355
355
|
function onFocus() {
|
|
356
356
|
done(true);
|
|
@@ -358,9 +358,10 @@ function tryOpenUrl(self, url, index, timeout) {
|
|
|
358
358
|
timeoutId = window.setTimeout(function () {
|
|
359
359
|
done(false);
|
|
360
360
|
}, timeout);
|
|
361
|
-
|
|
361
|
+
top.addEventListener("blur", onBlur);
|
|
362
362
|
try {
|
|
363
|
-
|
|
363
|
+
openURLViaIframe(url);
|
|
364
|
+
openURLViaHref(url, index);
|
|
364
365
|
}
|
|
365
366
|
catch (_) {
|
|
366
367
|
done(false);
|
|
@@ -495,20 +496,29 @@ function getDefaultTimeoutByOS(os) {
|
|
|
495
496
|
default: return 750;
|
|
496
497
|
}
|
|
497
498
|
}
|
|
498
|
-
function open(options
|
|
499
|
-
if (self === void 0) { self = window; }
|
|
499
|
+
function open(options) {
|
|
500
500
|
var os = OS_NAME;
|
|
501
501
|
var urls = [];
|
|
502
|
+
var tried = [];
|
|
502
503
|
var timeout;
|
|
504
|
+
function getURLOpenError() {
|
|
505
|
+
var triedUrlString = "";
|
|
506
|
+
for (var i = 0; i < urls.length; i++)
|
|
507
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
508
|
+
if (triedUrlString.length > 0)
|
|
509
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
510
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
511
|
+
}
|
|
503
512
|
if (os === OS.Android) {
|
|
504
513
|
var option = options[OS.Android];
|
|
505
514
|
if (option === undefined)
|
|
506
|
-
return Promise.reject();
|
|
515
|
+
return Promise.reject(getURLOpenError());
|
|
507
516
|
timeout = option.timeout;
|
|
508
517
|
var scheme = option.scheme;
|
|
509
518
|
var intent = option.intent;
|
|
510
519
|
var packageName = option.packageName;
|
|
511
520
|
var fallback = option.fallback;
|
|
521
|
+
var allowWebStore = option.allowWebStore;
|
|
512
522
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
513
523
|
var parsed = parseIntentURL(intent);
|
|
514
524
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -527,18 +537,21 @@ function open(options, self) {
|
|
|
527
537
|
if (fallback !== undefined)
|
|
528
538
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
529
539
|
if (packageName !== undefined)
|
|
530
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
540
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
541
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
542
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
531
543
|
}
|
|
532
544
|
else if (os === OS.iOS) {
|
|
533
545
|
var option = options[OS.iOS];
|
|
534
546
|
if (option === undefined)
|
|
535
|
-
return Promise.reject();
|
|
547
|
+
return Promise.reject(getURLOpenError());
|
|
536
548
|
timeout = option.timeout;
|
|
537
549
|
var scheme = option.scheme;
|
|
538
550
|
var packageName = option.packageName;
|
|
539
551
|
var trackId = option.trackId;
|
|
540
552
|
var universal = option.universal;
|
|
541
553
|
var fallback = option.fallback;
|
|
554
|
+
var allowWebStore = option.allowWebStore;
|
|
542
555
|
if (packageName !== undefined && trackId === undefined)
|
|
543
556
|
trackId = getTrackId(packageName);
|
|
544
557
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -548,32 +561,38 @@ function open(options, self) {
|
|
|
548
561
|
if (fallback !== undefined)
|
|
549
562
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
550
563
|
if (trackId !== undefined)
|
|
551
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
564
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
565
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
566
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
552
567
|
}
|
|
553
568
|
else if (os === OS.Windows) {
|
|
554
569
|
var option = options[OS.Windows];
|
|
555
570
|
if (option === undefined)
|
|
556
|
-
return Promise.reject();
|
|
571
|
+
return Promise.reject(getURLOpenError());
|
|
557
572
|
timeout = option.timeout;
|
|
558
573
|
var scheme = option.scheme;
|
|
559
574
|
var productId = option.productId;
|
|
560
575
|
var fallback = option.fallback;
|
|
576
|
+
var allowWebStore = option.allowWebStore;
|
|
561
577
|
if (scheme !== undefined)
|
|
562
578
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
563
579
|
if (fallback !== undefined)
|
|
564
580
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
565
581
|
if (productId !== undefined)
|
|
566
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
582
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
583
|
+
if (productId !== undefined && allowWebStore === true)
|
|
584
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
567
585
|
}
|
|
568
586
|
else if (os === OS.MacOS) {
|
|
569
587
|
var option = options[OS.MacOS];
|
|
570
588
|
if (option === undefined)
|
|
571
|
-
return Promise.reject();
|
|
589
|
+
return Promise.reject(getURLOpenError());
|
|
572
590
|
timeout = option.timeout;
|
|
573
591
|
var scheme = option.scheme;
|
|
574
592
|
var packageName = option.packageName;
|
|
575
593
|
var trackId = option.trackId;
|
|
576
594
|
var fallback = option.fallback;
|
|
595
|
+
var allowWebStore = option.allowWebStore;
|
|
577
596
|
if (packageName !== undefined && trackId === undefined)
|
|
578
597
|
trackId = getTrackId(packageName);
|
|
579
598
|
if (scheme !== undefined)
|
|
@@ -581,25 +600,26 @@ function open(options, self) {
|
|
|
581
600
|
if (fallback !== undefined)
|
|
582
601
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
583
602
|
if (trackId !== undefined)
|
|
584
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
603
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
604
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
605
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
585
606
|
}
|
|
586
607
|
if (timeout === undefined)
|
|
587
608
|
timeout = getDefaultTimeoutByOS(os);
|
|
588
609
|
return new Promise(function (resolve, reject) {
|
|
589
|
-
var tried = "\n";
|
|
590
610
|
function openURLSequential(index) {
|
|
591
611
|
if (index === void 0) { index = 0; }
|
|
592
612
|
if (index >= urls.length)
|
|
593
|
-
return reject(
|
|
613
|
+
return reject(getURLOpenError());
|
|
594
614
|
var entry = urls[index];
|
|
595
615
|
var url = entry[0];
|
|
596
|
-
tried =
|
|
597
|
-
return tryOpenUrl(
|
|
616
|
+
tried[index] = url;
|
|
617
|
+
return tryOpenUrl(url, index, timeout)
|
|
598
618
|
.then(function () {
|
|
599
619
|
resolve(entry[1]);
|
|
600
620
|
})
|
|
601
621
|
.catch(function () {
|
|
602
|
-
openURLSequential(
|
|
622
|
+
openURLSequential(index + 1);
|
|
603
623
|
});
|
|
604
624
|
}
|
|
605
625
|
return openURLSequential();
|
|
@@ -719,25 +739,22 @@ function normalize(value) {
|
|
|
719
739
|
result.body = "";
|
|
720
740
|
return result;
|
|
721
741
|
}
|
|
722
|
-
function openMessenger(options,
|
|
742
|
+
function openMessenger(options, type) {
|
|
723
743
|
options = normalize(options);
|
|
724
|
-
return tryOpenUrl(
|
|
744
|
+
return tryOpenUrl(type + ":" + options.to
|
|
725
745
|
+ "?cc=" + options.cc
|
|
726
746
|
+ "&bcc=" + options.bcc
|
|
727
747
|
+ "&subject=" + options.subject
|
|
728
748
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
729
749
|
}
|
|
730
|
-
function openMessengerTelephone(options
|
|
731
|
-
|
|
732
|
-
return openMessenger(options, self, "tel");
|
|
750
|
+
function openMessengerTelephone(options) {
|
|
751
|
+
return openMessenger(options, "tel");
|
|
733
752
|
}
|
|
734
|
-
function openMessengerMessage(options
|
|
735
|
-
|
|
736
|
-
return openMessenger(options, self, "sms");
|
|
753
|
+
function openMessengerMessage(options) {
|
|
754
|
+
return openMessenger(options, "sms");
|
|
737
755
|
}
|
|
738
|
-
function openMessengerMail(options
|
|
739
|
-
|
|
740
|
-
return openMessenger(options, self, "mailto");
|
|
756
|
+
function openMessengerMail(options) {
|
|
757
|
+
return openMessenger(options, "mailto");
|
|
741
758
|
}
|
|
742
759
|
|
|
743
760
|
var EasingError = createCustomError("EasingError");
|
package/dist/native.umd.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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.25";
|
|
8
8
|
var packageJSON = {
|
|
9
9
|
version: version};
|
|
10
10
|
|
|
@@ -208,46 +208,63 @@
|
|
|
208
208
|
isStandalone: IS_STANDALONE,
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
function
|
|
211
|
+
function getTopmostWindow() {
|
|
212
|
+
if (window.top !== null)
|
|
213
|
+
return window.top;
|
|
214
|
+
return window;
|
|
215
|
+
}
|
|
216
|
+
function openURLViaHref(url, index) {
|
|
217
|
+
var top = getTopmostWindow();
|
|
212
218
|
var a = undefined;
|
|
213
219
|
try {
|
|
214
|
-
|
|
215
|
-
|
|
220
|
+
if (index === 0) {
|
|
221
|
+
top.location.href = url;
|
|
216
222
|
return;
|
|
217
|
-
|
|
223
|
+
}
|
|
224
|
+
a = top.document.createElement("a");
|
|
218
225
|
a.href = url;
|
|
219
226
|
a.style.display = "none";
|
|
220
227
|
a.setAttribute("aria-hidden", "true");
|
|
221
|
-
|
|
228
|
+
top.document.body.appendChild(a);
|
|
222
229
|
var fake = void 0;
|
|
223
230
|
try {
|
|
224
231
|
fake = new MouseEvent("click", {
|
|
225
232
|
bubbles: true,
|
|
226
233
|
cancelable: true,
|
|
227
|
-
view:
|
|
234
|
+
view: top
|
|
228
235
|
});
|
|
229
236
|
}
|
|
230
237
|
catch (_) {
|
|
231
|
-
fake =
|
|
232
|
-
fake.initMouseEvent("click", true, true,
|
|
238
|
+
fake = top.document.createEvent("MouseEvents");
|
|
239
|
+
fake.initMouseEvent("click", true, true, top, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
233
240
|
}
|
|
234
241
|
a.dispatchEvent(fake);
|
|
235
|
-
if (a.click !== undefined)
|
|
236
|
-
a.click();
|
|
237
|
-
window.location.assign(url);
|
|
238
242
|
}
|
|
239
243
|
catch (_) {
|
|
240
244
|
}
|
|
241
245
|
finally {
|
|
242
246
|
if (a !== undefined)
|
|
243
|
-
|
|
247
|
+
top.document.body.removeChild(a);
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
250
|
+
function openURLViaIframe(url) {
|
|
251
|
+
var top = getTopmostWindow();
|
|
252
|
+
var iframe = document.createElement("iframe");
|
|
253
|
+
iframe.width = iframe.height = iframe.frameBorder = "0";
|
|
254
|
+
iframe.style.display = "none";
|
|
255
|
+
iframe.src = url;
|
|
256
|
+
top.document.body.appendChild(iframe);
|
|
257
|
+
window.setTimeout(function () {
|
|
258
|
+
try {
|
|
259
|
+
top.document.removeChild(iframe);
|
|
260
|
+
}
|
|
261
|
+
catch (_) {
|
|
262
|
+
}
|
|
263
|
+
}, 100);
|
|
248
264
|
}
|
|
249
|
-
function isDocumentHidden(
|
|
250
|
-
var
|
|
265
|
+
function isDocumentHidden() {
|
|
266
|
+
var top = getTopmostWindow();
|
|
267
|
+
var doc = top.document;
|
|
251
268
|
if (doc.visibilityState === "hidden")
|
|
252
269
|
return true;
|
|
253
270
|
if (doc.hidden !== undefined)
|
|
@@ -258,36 +275,18 @@
|
|
|
258
275
|
return !doc.hasFocus();
|
|
259
276
|
return true;
|
|
260
277
|
}
|
|
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
|
-
}
|
|
278
|
+
function tryOpenUrl(url, index, timeout) {
|
|
279
|
+
var top = getTopmostWindow();
|
|
281
280
|
if (Platform.os === OS.iOS) {
|
|
282
281
|
var visibilitychange_1;
|
|
283
282
|
var eventTarget_1;
|
|
284
283
|
if (parseInt(Platform.osVersion) >= 8) {
|
|
285
284
|
visibilitychange_1 = "visibilitychange";
|
|
286
|
-
eventTarget_1 =
|
|
285
|
+
eventTarget_1 = top.document;
|
|
287
286
|
}
|
|
288
287
|
else {
|
|
289
288
|
visibilitychange_1 = "pagehide";
|
|
290
|
-
eventTarget_1 =
|
|
289
|
+
eventTarget_1 = top;
|
|
291
290
|
}
|
|
292
291
|
return new Promise(function (resolve, reject) {
|
|
293
292
|
var timeoutId;
|
|
@@ -313,7 +312,7 @@
|
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
function onVisibilityChange() {
|
|
316
|
-
if (isDocumentHidden(
|
|
315
|
+
if (isDocumentHidden())
|
|
317
316
|
done(true);
|
|
318
317
|
}
|
|
319
318
|
timeoutId = window.setTimeout(function () {
|
|
@@ -321,7 +320,8 @@
|
|
|
321
320
|
}, timeout);
|
|
322
321
|
eventTarget_1.addEventListener(visibilitychange_1, onVisibilityChange);
|
|
323
322
|
try {
|
|
324
|
-
|
|
323
|
+
openURLViaIframe(url);
|
|
324
|
+
openURLViaHref(url, index);
|
|
325
325
|
}
|
|
326
326
|
catch (_) {
|
|
327
327
|
done(false);
|
|
@@ -335,8 +335,8 @@
|
|
|
335
335
|
function cleanup() {
|
|
336
336
|
if (timeoutId)
|
|
337
337
|
clearTimeout(timeoutId);
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
top.removeEventListener("blur", onBlur);
|
|
339
|
+
top.removeEventListener("focus", onFocus);
|
|
340
340
|
}
|
|
341
341
|
function done(success) {
|
|
342
342
|
if (!resolved) {
|
|
@@ -355,8 +355,8 @@
|
|
|
355
355
|
}
|
|
356
356
|
function onBlur() {
|
|
357
357
|
clearTimeout(timeoutId);
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
top.removeEventListener("blur", onBlur);
|
|
359
|
+
top.addEventListener("focus", onFocus);
|
|
360
360
|
}
|
|
361
361
|
function onFocus() {
|
|
362
362
|
done(true);
|
|
@@ -364,9 +364,10 @@
|
|
|
364
364
|
timeoutId = window.setTimeout(function () {
|
|
365
365
|
done(false);
|
|
366
366
|
}, timeout);
|
|
367
|
-
|
|
367
|
+
top.addEventListener("blur", onBlur);
|
|
368
368
|
try {
|
|
369
|
-
|
|
369
|
+
openURLViaIframe(url);
|
|
370
|
+
openURLViaHref(url, index);
|
|
370
371
|
}
|
|
371
372
|
catch (_) {
|
|
372
373
|
done(false);
|
|
@@ -501,20 +502,29 @@
|
|
|
501
502
|
default: return 750;
|
|
502
503
|
}
|
|
503
504
|
}
|
|
504
|
-
function open(options
|
|
505
|
-
if (self === void 0) { self = window; }
|
|
505
|
+
function open(options) {
|
|
506
506
|
var os = OS_NAME;
|
|
507
507
|
var urls = [];
|
|
508
|
+
var tried = [];
|
|
508
509
|
var timeout;
|
|
510
|
+
function getURLOpenError() {
|
|
511
|
+
var triedUrlString = "";
|
|
512
|
+
for (var i = 0; i < urls.length; i++)
|
|
513
|
+
triedUrlString += "\n" + (i + 1) + ": " + tried[i];
|
|
514
|
+
if (triedUrlString.length > 0)
|
|
515
|
+
triedUrlString = "\n" + triedUrlString + "\n";
|
|
516
|
+
return new URLOpenError("Failed to open any of the provided URLs: " + triedUrlString);
|
|
517
|
+
}
|
|
509
518
|
if (os === OS.Android) {
|
|
510
519
|
var option = options[OS.Android];
|
|
511
520
|
if (option === undefined)
|
|
512
|
-
return Promise.reject();
|
|
521
|
+
return Promise.reject(getURLOpenError());
|
|
513
522
|
timeout = option.timeout;
|
|
514
523
|
var scheme = option.scheme;
|
|
515
524
|
var intent = option.intent;
|
|
516
525
|
var packageName = option.packageName;
|
|
517
526
|
var fallback = option.fallback;
|
|
527
|
+
var allowWebStore = option.allowWebStore;
|
|
518
528
|
if (intent !== undefined && (scheme === undefined || packageName === undefined || fallback === undefined)) {
|
|
519
529
|
var parsed = parseIntentURL(intent);
|
|
520
530
|
if (parsed.scheme !== undefined && scheme === undefined)
|
|
@@ -533,18 +543,21 @@
|
|
|
533
543
|
if (fallback !== undefined)
|
|
534
544
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
535
545
|
if (packageName !== undefined)
|
|
536
|
-
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]
|
|
546
|
+
urls.push([createAppStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
547
|
+
if (packageName !== undefined && allowWebStore === true)
|
|
548
|
+
urls.push([createWebStoreURL(packageName, OS.Android), AppOpenState.Store]);
|
|
537
549
|
}
|
|
538
550
|
else if (os === OS.iOS) {
|
|
539
551
|
var option = options[OS.iOS];
|
|
540
552
|
if (option === undefined)
|
|
541
|
-
return Promise.reject();
|
|
553
|
+
return Promise.reject(getURLOpenError());
|
|
542
554
|
timeout = option.timeout;
|
|
543
555
|
var scheme = option.scheme;
|
|
544
556
|
var packageName = option.packageName;
|
|
545
557
|
var trackId = option.trackId;
|
|
546
558
|
var universal = option.universal;
|
|
547
559
|
var fallback = option.fallback;
|
|
560
|
+
var allowWebStore = option.allowWebStore;
|
|
548
561
|
if (packageName !== undefined && trackId === undefined)
|
|
549
562
|
trackId = getTrackId(packageName);
|
|
550
563
|
if (universal !== undefined && parseInt(OS_VERSION) >= 9)
|
|
@@ -554,32 +567,38 @@
|
|
|
554
567
|
if (fallback !== undefined)
|
|
555
568
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
556
569
|
if (trackId !== undefined)
|
|
557
|
-
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]
|
|
570
|
+
urls.push([createAppStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
571
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
572
|
+
urls.push([createWebStoreURL(trackId, OS.iOS), AppOpenState.Store]);
|
|
558
573
|
}
|
|
559
574
|
else if (os === OS.Windows) {
|
|
560
575
|
var option = options[OS.Windows];
|
|
561
576
|
if (option === undefined)
|
|
562
|
-
return Promise.reject();
|
|
577
|
+
return Promise.reject(getURLOpenError());
|
|
563
578
|
timeout = option.timeout;
|
|
564
579
|
var scheme = option.scheme;
|
|
565
580
|
var productId = option.productId;
|
|
566
581
|
var fallback = option.fallback;
|
|
582
|
+
var allowWebStore = option.allowWebStore;
|
|
567
583
|
if (scheme !== undefined)
|
|
568
584
|
urls.push([scheme, AppOpenState.Scheme]);
|
|
569
585
|
if (fallback !== undefined)
|
|
570
586
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
571
587
|
if (productId !== undefined)
|
|
572
|
-
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]
|
|
588
|
+
urls.push([createAppStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
589
|
+
if (productId !== undefined && allowWebStore === true)
|
|
590
|
+
urls.push([createWebStoreURL(productId, OS.Windows), AppOpenState.Store]);
|
|
573
591
|
}
|
|
574
592
|
else if (os === OS.MacOS) {
|
|
575
593
|
var option = options[OS.MacOS];
|
|
576
594
|
if (option === undefined)
|
|
577
|
-
return Promise.reject();
|
|
595
|
+
return Promise.reject(getURLOpenError());
|
|
578
596
|
timeout = option.timeout;
|
|
579
597
|
var scheme = option.scheme;
|
|
580
598
|
var packageName = option.packageName;
|
|
581
599
|
var trackId = option.trackId;
|
|
582
600
|
var fallback = option.fallback;
|
|
601
|
+
var allowWebStore = option.allowWebStore;
|
|
583
602
|
if (packageName !== undefined && trackId === undefined)
|
|
584
603
|
trackId = getTrackId(packageName);
|
|
585
604
|
if (scheme !== undefined)
|
|
@@ -587,25 +606,26 @@
|
|
|
587
606
|
if (fallback !== undefined)
|
|
588
607
|
urls.push([fallback, AppOpenState.Fallback]);
|
|
589
608
|
if (trackId !== undefined)
|
|
590
|
-
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]
|
|
609
|
+
urls.push([createAppStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
610
|
+
if (trackId !== undefined && allowWebStore === true)
|
|
611
|
+
urls.push([createWebStoreURL(trackId, OS.MacOS), AppOpenState.Store]);
|
|
591
612
|
}
|
|
592
613
|
if (timeout === undefined)
|
|
593
614
|
timeout = getDefaultTimeoutByOS(os);
|
|
594
615
|
return new Promise(function (resolve, reject) {
|
|
595
|
-
var tried = "\n";
|
|
596
616
|
function openURLSequential(index) {
|
|
597
617
|
if (index === void 0) { index = 0; }
|
|
598
618
|
if (index >= urls.length)
|
|
599
|
-
return reject(
|
|
619
|
+
return reject(getURLOpenError());
|
|
600
620
|
var entry = urls[index];
|
|
601
621
|
var url = entry[0];
|
|
602
|
-
tried =
|
|
603
|
-
return tryOpenUrl(
|
|
622
|
+
tried[index] = url;
|
|
623
|
+
return tryOpenUrl(url, index, timeout)
|
|
604
624
|
.then(function () {
|
|
605
625
|
resolve(entry[1]);
|
|
606
626
|
})
|
|
607
627
|
.catch(function () {
|
|
608
|
-
openURLSequential(
|
|
628
|
+
openURLSequential(index + 1);
|
|
609
629
|
});
|
|
610
630
|
}
|
|
611
631
|
return openURLSequential();
|
|
@@ -725,25 +745,22 @@
|
|
|
725
745
|
result.body = "";
|
|
726
746
|
return result;
|
|
727
747
|
}
|
|
728
|
-
function openMessenger(options,
|
|
748
|
+
function openMessenger(options, type) {
|
|
729
749
|
options = normalize(options);
|
|
730
|
-
return tryOpenUrl(
|
|
750
|
+
return tryOpenUrl(type + ":" + options.to
|
|
731
751
|
+ "?cc=" + options.cc
|
|
732
752
|
+ "&bcc=" + options.bcc
|
|
733
753
|
+ "&subject=" + options.subject
|
|
734
754
|
+ "&body=" + options.body, 0, getDefaultTimeoutByOS(OS_NAME));
|
|
735
755
|
}
|
|
736
|
-
function openMessengerTelephone(options
|
|
737
|
-
|
|
738
|
-
return openMessenger(options, self, "tel");
|
|
756
|
+
function openMessengerTelephone(options) {
|
|
757
|
+
return openMessenger(options, "tel");
|
|
739
758
|
}
|
|
740
|
-
function openMessengerMessage(options
|
|
741
|
-
|
|
742
|
-
return openMessenger(options, self, "sms");
|
|
759
|
+
function openMessengerMessage(options) {
|
|
760
|
+
return openMessenger(options, "sms");
|
|
743
761
|
}
|
|
744
|
-
function openMessengerMail(options
|
|
745
|
-
|
|
746
|
-
return openMessenger(options, self, "mailto");
|
|
762
|
+
function openMessengerMail(options) {
|
|
763
|
+
return openMessenger(options, "mailto");
|
|
747
764
|
}
|
|
748
765
|
|
|
749
766
|
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>;
|