decentraland-ui2 0.27.0 → 0.27.1-17685773876.commit-bcabe46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/jumpIn.d.ts +14 -8
- package/dist/modules/jumpIn.js +62 -90
- package/dist/modules/jumpIn.js.map +1 -1
- package/package.json +2 -2
package/dist/modules/jumpIn.d.ts
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* and return a boolean that represents if a loss of focus was detected on the current window
|
4
|
-
* (assuming it was due to the interaction generated by the desktop version)
|
5
|
-
*/
|
6
|
-
declare const launchDesktopApp: (options: {
|
1
|
+
import { AdvancedNavigatorUAData } from "@dcl/hooks/cjs/hooks/useAdvancedUserAgentData";
|
2
|
+
type JumpInOptions = {
|
7
3
|
position?: string;
|
8
4
|
realm?: string;
|
9
|
-
|
10
|
-
|
5
|
+
timeoutMs?: number;
|
6
|
+
userAgentData?: AdvancedNavigatorUAData;
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* Attempts to open the desktop app and resolves:
|
10
|
+
* - true if it detects visibility/focus loss within the timeout
|
11
|
+
* - rejects with error if it doesn't detect anything within the timeout
|
12
|
+
*
|
13
|
+
* IMPORTANT: call within a user gesture (onclick).
|
14
|
+
*/
|
15
|
+
export declare function launchDesktopApp(opts?: JumpInOptions): Promise<boolean>;
|
16
|
+
export {};
|
package/dist/modules/jumpIn.js
CHANGED
@@ -1,98 +1,70 @@
|
|
1
|
-
function
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
1
|
+
function buildDecentralandUrl(opts) {
|
2
|
+
const params = new URLSearchParams();
|
3
|
+
if (opts.position)
|
4
|
+
params.set("position", opts.position);
|
5
|
+
if (opts.realm)
|
6
|
+
params.set("realm", opts.realm);
|
7
|
+
return `decentraland://?${params.toString()}`;
|
9
8
|
}
|
10
|
-
|
11
|
-
|
12
|
-
/Android/i.test(navigator.userAgent)) {
|
13
|
-
return true;
|
14
|
-
}
|
15
|
-
if (/iPad|iPhone|iPod/.test(navigator.platform)) {
|
16
|
-
return true;
|
17
|
-
}
|
18
|
-
if (/Macintosh/i.test(navigator.userAgent) &&
|
19
|
-
navigator.maxTouchPoints &&
|
20
|
-
navigator.maxTouchPoints > 1) {
|
21
|
-
// iPad pro
|
22
|
-
return true;
|
23
|
-
}
|
24
|
-
return false;
|
25
|
-
});
|
26
|
-
const isElectron = callOnce(() => {
|
27
|
-
// Renderer process
|
28
|
-
if (typeof window !== "undefined" &&
|
9
|
+
function isElectronApp() {
|
10
|
+
return ((typeof window !== "undefined" &&
|
29
11
|
typeof window.process === "object" &&
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
return true;
|
40
|
-
}
|
41
|
-
// Detect the user agent when the `nodeIntegration` option is set to true
|
42
|
-
if (typeof navigator === "object" &&
|
43
|
-
typeof navigator.userAgent === "string" &&
|
44
|
-
navigator.userAgent.indexOf("Electron") >= 0) {
|
45
|
-
return true;
|
46
|
-
}
|
47
|
-
return false;
|
48
|
-
});
|
12
|
+
window.process.type === "renderer") ||
|
13
|
+
(typeof process !== "undefined" &&
|
14
|
+
typeof process.versions ===
|
15
|
+
"object" &&
|
16
|
+
!!process.versions.electron) ||
|
17
|
+
(typeof navigator === "object" &&
|
18
|
+
typeof navigator.userAgent === "string" &&
|
19
|
+
navigator.userAgent.includes("Electron")));
|
20
|
+
}
|
49
21
|
/**
|
50
|
-
*
|
51
|
-
*
|
52
|
-
*
|
22
|
+
* Attempts to open the desktop app and resolves:
|
23
|
+
* - true if it detects visibility/focus loss within the timeout
|
24
|
+
* - rejects with error if it doesn't detect anything within the timeout
|
25
|
+
*
|
26
|
+
* IMPORTANT: call within a user gesture (onclick).
|
53
27
|
*/
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
const customProtocolParams = [];
|
60
|
-
if (options.position) {
|
61
|
-
customProtocolParams.push(`position=${options.position}`);
|
28
|
+
export function launchDesktopApp(opts = {}) {
|
29
|
+
const { timeoutMs = 750, userAgentData } = opts;
|
30
|
+
const isMobile = userAgentData?.mobile || userAgentData?.tablet;
|
31
|
+
if (isMobile || isElectronApp()) {
|
32
|
+
return Promise.resolve(false);
|
62
33
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
34
|
+
const target = buildDecentralandUrl(opts);
|
35
|
+
let opened = false;
|
36
|
+
const onLoseFocus = () => {
|
37
|
+
opened = true;
|
38
|
+
};
|
39
|
+
const cleanup = () => {
|
40
|
+
document.removeEventListener("visibilitychange", onVis);
|
41
|
+
window.removeEventListener("pagehide", onLoseFocus);
|
42
|
+
window.removeEventListener("blur", onLoseFocus);
|
72
43
|
};
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
44
|
+
const onVis = () => {
|
45
|
+
if (document.visibilityState === "hidden")
|
46
|
+
onLoseFocus();
|
47
|
+
};
|
48
|
+
document.addEventListener("visibilitychange", onVis, { passive: true });
|
49
|
+
window.addEventListener("pagehide", onLoseFocus, { passive: true });
|
50
|
+
window.addEventListener("blur", onLoseFocus, { passive: true });
|
51
|
+
window.location.assign(target);
|
52
|
+
return new Promise((resolve, reject) => {
|
53
|
+
const t = setTimeout(() => {
|
54
|
+
cleanup();
|
55
|
+
const success = opened;
|
56
|
+
if (!success) {
|
57
|
+
reject(new Error("Failed to open desktop app"));
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
resolve(success);
|
61
|
+
}
|
62
|
+
}, timeoutMs);
|
63
|
+
if (opened) {
|
64
|
+
clearTimeout(t);
|
65
|
+
cleanup();
|
66
|
+
resolve(true);
|
67
|
+
}
|
95
68
|
});
|
96
|
-
}
|
97
|
-
export { launchDesktopApp };
|
69
|
+
}
|
98
70
|
//# sourceMappingURL=jumpIn.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jumpIn.js","sourceRoot":"","sources":["../../src/modules/jumpIn.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"jumpIn.js","sourceRoot":"","sources":["../../src/modules/jumpIn.ts"],"names":[],"mappings":"AAYA,SAAS,oBAAoB,CAAC,IAAmB;IAC/C,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA;IACpC,IAAI,IAAI,CAAC,QAAQ;QAAE,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IACxD,IAAI,IAAI,CAAC,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/C,OAAO,mBAAmB,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAA;AAC/C,CAAC;AAED,SAAS,aAAa;IACpB,OAAO,CACL,CAAC,OAAO,MAAM,KAAK,WAAW;QAC5B,OAAQ,MAAuC,CAAC,OAAO,KAAK,QAAQ;QACnE,MAAuC,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC;QACvE,CAAC,OAAO,OAAO,KAAK,WAAW;YAC7B,OAAQ,OAA0C,CAAC,QAAQ;gBACzD,QAAQ;YACV,CAAC,CAAE,OAA0C,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAClE,CAAC,OAAO,SAAS,KAAK,QAAQ;YAC5B,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ;YACvC,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAC5C,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,M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AAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,OAAO,EAAE,CAAA;YACT,MAAM,OAAO,GAAG,MAAM,CAAA;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAA;YACjD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,OAAO,CAAC,CAAA;YAClB,CAAC;QACH,CAAC,EAAE,SAAS,CAAC,CAAA;QACb,IAAI,MAAM,EAAE,CAAC;YACX,YAAY,CAAC,CAAC,CAAC,CAAA;YACf,OAAO,EAAE,CAAA;YACT,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "decentraland-ui2",
|
3
|
-
"version": "0.27.
|
3
|
+
"version": "0.27.1-17685773876.commit-bcabe46",
|
4
4
|
"description": "Decentraland's UI components and styles",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -98,5 +98,5 @@
|
|
98
98
|
"files": [
|
99
99
|
"dist"
|
100
100
|
],
|
101
|
-
"commit": "
|
101
|
+
"commit": "bcabe461b469338c8434f1609043f29c35a25982"
|
102
102
|
}
|