Skip to content

Commit 3abf990

Browse files
committed
Patch isMobile and views.Mobile.detect
1 parent a0725db commit 3abf990

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
(function () {
1+
(async function () {
22
// Need to patch app.views.Mobile.detect internals to force desktop mode.
33
const original = window.matchMedia
44
const patcher = function () {
55
return { matches: false }
66
}
77
window.matchMedia = patcher
88

9-
const afterInit = function () {
10-
if (window.app && window.app.settings) {
11-
window.matchMedia = original
12-
window.webkit.messageHandlers.vcBus.postMessage({ type: 'afterInit' })
13-
} else {
14-
requestAnimationFrame(afterInit)
15-
}
9+
const globalDefined = (attr) => {
10+
return new Promise(function (resolve, reject) {
11+
const checker = () => {
12+
if (Object.prototype.hasOwnProperty.call(window, attr)) {
13+
resolve(window[attr])
14+
} else {
15+
requestAnimationFrame(checker)
16+
}
17+
}
18+
requestAnimationFrame(checker)
19+
})
1620
}
17-
requestAnimationFrame(afterInit)
21+
22+
const app = await globalDefined('app')
23+
app.isMobile = () => false
24+
app.views.Mobile.detect = () => false
25+
26+
window.matchMedia = original
27+
window.webkit.messageHandlers.vcBus.postMessage({ type: 'afterInit' })
1828
}())

0 commit comments

Comments
 (0)