-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ipc.js
39 lines (35 loc) · 961 Bytes
/
ipc.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
36
37
38
39
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 6 */
/**
* WailsInvoke sends the given message to the backend
*
* @param {string} message
*/
(function () {
// Credit: https://stackoverflow.com/a/2631521
let _deeptest = function (s) {
var obj = window[s.shift()];
while (obj && s.length) obj = obj[s.shift()];
return obj;
};
let windows = _deeptest(["chrome", "webview", "postMessage"]);
let mac_linux = _deeptest(["webkit", "messageHandlers", "external", "postMessage"]);
if (!windows && !mac_linux) {
console.error("Unsupported Platform");
return;
}
if (windows) {
window.WailsInvoke = (message) => window.chrome.webview.postMessage(message);
}
if (mac_linux) {
window.WailsInvoke = (message) => window.webkit.messageHandlers.external.postMessage(message);
}
})();