5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 05:11:29 +08:00
wails/v3/internal/runtime/desktop/ipc.js
Lea Anthony 293d730708
[v3] Updated runtime to take window id into consideration
[v3] Ported most of the window functions for JS
2023-01-26 20:43:26 +11:00

46 lines
1.0 KiB
JavaScript

/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 9 */
let postMessage = null;
(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) {
postMessage = (message) => window.chrome.webview.postMessage(message);
}
if (mac_linux) {
postMessage = (message) => window.webkit.messageHandlers.external.postMessage(message);
}
})();
export function invoke(message, id) {
if( id && id !== -1) {
postMessage("WINDOWID:"+ id + ":" + message);
} else {
postMessage(message);
}
}