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.
@@ -1,10 +1,16 @@
1
- /**
2
- * Try to launch the desktop version using the custom protocol `decentraland://position=x,y&realm=zzz`
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
- }) => Promise<boolean>;
10
- export { launchDesktopApp };
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 {};
@@ -1,98 +1,70 @@
1
- function callOnce(fun) {
2
- let result = null;
3
- return () => {
4
- if (!result) {
5
- result = { value: fun() };
6
- }
7
- return result.value;
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
- const isMobile = callOnce(() => {
11
- if (/Mobi/i.test(navigator.userAgent) ||
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- window.process.type === "renderer") {
32
- return true;
33
- }
34
- // Main process
35
- if (typeof process !== "undefined" &&
36
- typeof process.versions === "object" &&
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- !!process.versions.electron) {
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
- * Try to launch the desktop version using the custom protocol `decentraland://position=x,y&realm=zzz`
51
- * and return a boolean that represents if a loss of focus was detected on the current window
52
- * (assuming it was due to the interaction generated by the desktop version)
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
- const launchDesktopApp = async (options) => {
55
- // prevent launch for desktop and mobile
56
- if (isElectron() || isMobile()) {
57
- return false;
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
- if (options.realm) {
64
- customProtocolParams.push(`realm=${options.realm}`);
65
- }
66
- const customProtocolTarget = `decentraland://?${customProtocolParams.join("&")}`;
67
- // assume that the desktop version is installed only if
68
- // we detect a loss of focus on window
69
- let installed = false;
70
- const isInstalled = () => {
71
- installed = true;
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
- window.addEventListener("blur", isInstalled);
74
- // inject an iframe that open the desktop version
75
- // NOTE: this can be also achieved with
76
- // ```js
77
- // window.location.href = customProtocolTarget
78
- // ```
79
- // but in safari redirects into an invalid url if the desktop
80
- // client is not installed
81
- const iframe = document.createElement("iframe");
82
- iframe.setAttribute("style", "display: none");
83
- iframe.src = customProtocolTarget;
84
- document.body.appendChild(iframe);
85
- // wait half of a second to detect the loss of focus because
86
- // the time it takes for the `blur` event to be fired varies
87
- // depending on the browser
88
- return new Promise((resolve) => {
89
- setTimeout(() => {
90
- window.removeEventListener("blur", isInstalled);
91
- document.body.removeChild(iframe);
92
- console.log("installed", installed);
93
- resolve(installed);
94
- }, 500);
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
  //# sourceMappingUR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;YAAE,WAAW,EAAE,CAAA;IAC1D,CAAC,CAAA;IAED,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACvE,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACnE,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAE/D,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAE9B,OAAO,IAAI,OAAO,CAAU,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.0",
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": "4c426ca1d58a94ed78837658a85505d3d73e631c"
101
+ "commit": "bcabe461b469338c8434f1609043f29c35a25982"
102
102
  }