Skip to content

Commit 5292c1c

Browse files
authored
Merge pull request #15 from dteoh/14-integration-fixes
Integration script updates
2 parents 52552ee + 7d74a0b commit 5292c1c

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

devdocs-macos/DocumentationViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ class DocumentationViewController: NSViewController {
195195
self.documentURL = URL(string: location)
196196
hideSearchControl()
197197
}
198+
199+
private func handleAppReboot() {
200+
webView.reload()
201+
}
198202
}
199203

200204
// MARK:- WKUIDelegate
@@ -256,6 +260,8 @@ extension DocumentationViewController: WKScriptMessageHandler {
256260
return
257261
}
258262
handleLocationNotification(args)
263+
case "appReboot":
264+
handleAppReboot()
259265
default:
260266
return
261267
}
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
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+
app.reboot = () => {
26+
window.webkit.messageHandlers.vcBus.postMessage({
27+
type: 'appReboot'
28+
})
29+
}
30+
31+
window.matchMedia = original
32+
window.webkit.messageHandlers.vcBus.postMessage({ type: 'afterInit' })
1833
}())

0 commit comments

Comments
 (0)