mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
[v2] Make ipc.js cross-platform
This commit is contained in:
@@ -10,25 +10,22 @@ The electron alternative for Go
|
||||
/* jshint esversion: 6 */
|
||||
|
||||
/**
|
||||
* SendMessage sends the given message to the backend
|
||||
* WailsInvoke sends the given message to the backend
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
|
||||
// const windows = 0;
|
||||
// const macos = 1;
|
||||
// const linux = 2;
|
||||
(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;
|
||||
};
|
||||
window.WailsInvoke = _deeptest(["chrome", "webview", "postMessage"]) ||
|
||||
_deeptest(["webkit", "messageHandlers", "external", "postMessage"]);
|
||||
|
||||
window.WailsInvoke = function (message) {
|
||||
|
||||
// Call Platform specific invoke method
|
||||
if (PLATFORM === 0) {
|
||||
window.chrome.webview.postMessage(message);
|
||||
} else if (PLATFORM === 1) {
|
||||
window.webkit.messageHandlers.external.postMessage(message);
|
||||
} else if (PLATFORM === 2) {
|
||||
console.error("Unsupported Platform");
|
||||
} else {
|
||||
if (!window.WailsInvoke) {
|
||||
console.error("Unsupported Platform");
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -1,8 +1,8 @@
|
||||
//go:build darwin
|
||||
//go:build darwin || windows
|
||||
|
||||
package runtime
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed ipc_darwin.js
|
||||
//go:embed ipc.js
|
||||
var DesktopIPC []byte
|
||||
@@ -1 +0,0 @@
|
||||
(()=>{window.WailsInvoke=function(e){window.webkit.messageHandlers.external.postMessage(e)};})();
|
||||
@@ -1,8 +0,0 @@
|
||||
//go:build windows
|
||||
|
||||
package runtime
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed ipc_windows.js
|
||||
var DesktopIPC []byte
|
||||
@@ -1 +0,0 @@
|
||||
(()=>{window.WailsInvoke=function(e){window.chrome.webview.postMessage(e)};})();
|
||||
@@ -5,8 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "run-p build:*",
|
||||
"build:ipc-windows": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_windows.js --define:PLATFORM=0",
|
||||
"build:ipc-darwin": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_darwin.js --define:PLATFORM=1",
|
||||
"build:ipc-desktop": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc.js",
|
||||
"build:ipc-dev": "cd dev && npm run build",
|
||||
"build:runtime-desktop-prod": "esbuild desktop/main.js --bundle --minify --outfile=runtime_prod_desktop.js --define:ENV=1",
|
||||
"build:runtime-desktop-dev": "esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_dev_desktop.js --define:ENV=0",
|
||||
|
||||
Reference in New Issue
Block a user