-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathremote.js
35 lines (29 loc) · 1013 Bytes
/
remote.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* globals NSThread */
var threadDictionary = NSThread.mainThread().threadDictionary()
module.exports.getWebview = function (identifier) {
return require('./lib').fromId(identifier) // eslint-disable-line
}
module.exports.isWebviewPresent = function isWebviewPresent(identifier) {
return !!threadDictionary[identifier]
}
module.exports.sendToWebview = function sendToWebview(identifier, evalString) {
if (!module.exports.isWebviewPresent(identifier)) {
return
}
var panel = threadDictionary[identifier]
var webview = null
var subviews = panel.contentView().subviews()
for (var i = 0; i < subviews.length; i += 1) {
if (
!webview &&
!subviews[i].isKindOfClass(WKInspectorWKWebView) &&
subviews[i].isKindOfClass(WKWebView)
) {
webview = subviews[i]
}
}
if (!webview || !webview.evaluateJavaScript_completionHandler) {
throw new Error('Webview ' + identifier + ' not found')
}
webview.evaluateJavaScript_completionHandler(evalString, null)
}