|
@@ -12,42 +12,24 @@ import { _shouldShowDeepLinkingDesktopPage }
|
12
|
12
|
from './shouldShowDeepLinkingDesktopPage';
|
13
|
13
|
|
14
|
14
|
/**
|
15
|
|
- * Indicates whether the window load event was already received.
|
|
15
|
+ * Promise that resolves when the window load event is received.
|
16
|
16
|
*
|
17
|
|
- * @type {boolean}
|
|
17
|
+ * @type {Promise<void>}
|
18
|
18
|
*/
|
19
|
|
-let windowIsLoaded = false;
|
20
|
|
-
|
21
|
|
-/**
|
22
|
|
- * Handler for the window load event.
|
23
|
|
- *
|
24
|
|
- * @returns {void}
|
25
|
|
- */
|
26
|
|
-function onWindowLoad() {
|
27
|
|
- windowIsLoaded = true;
|
28
|
|
- window.removeEventListener('load', onWindowLoad);
|
29
|
|
-}
|
|
19
|
+const windowLoadedPromise = new Promise(resolve => {
|
|
20
|
+ /**
|
|
21
|
+ * Handler for the window load event.
|
|
22
|
+ *
|
|
23
|
+ * @returns {void}
|
|
24
|
+ */
|
|
25
|
+ function onWindowLoad() {
|
|
26
|
+ resolve();
|
|
27
|
+ window.removeEventListener('load', onWindowLoad);
|
|
28
|
+ }
|
30
|
29
|
|
31
|
|
-window.addEventListener('load', onWindowLoad);
|
|
30
|
+ window.addEventListener('load', onWindowLoad);
|
|
31
|
+});
|
32
|
32
|
|
33
|
|
-/**
|
34
|
|
- * Executes the passed function after the window load event was received.
|
35
|
|
- *
|
36
|
|
- * @param {Function} fn - The function that will be executed.
|
37
|
|
- * @returns {void}
|
38
|
|
- */
|
39
|
|
-function executeAfterWindowLoad(fn) {
|
40
|
|
- if (windowIsLoaded) {
|
41
|
|
- fn();
|
42
|
|
- } else {
|
43
|
|
- const loadHandler = () => {
|
44
|
|
- fn();
|
45
|
|
- window.removeEventListener('load', loadHandler);
|
46
|
|
- };
|
47
|
|
-
|
48
|
|
- window.addEventListener('load', loadHandler);
|
49
|
|
- }
|
50
|
|
-}
|
51
|
33
|
|
52
|
34
|
/**
|
53
|
35
|
* Generates a deep linking URL based on the current window URL.
|
|
@@ -114,7 +96,7 @@ export function getDeepLinkingPage(state) {
|
114
|
96
|
* @returns {void}
|
115
|
97
|
*/
|
116
|
98
|
export function openDesktopApp() {
|
117
|
|
- executeAfterWindowLoad(() => {
|
|
99
|
+ windowLoadedPromise.then(() => {
|
118
|
100
|
// If the code for opening the deep link is executed before the window
|
119
|
101
|
// load event, something with the internal chrome state goes wrong. The
|
120
|
102
|
// result is that no window load event is received which is the cause
|