5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 15:42:53 +08:00
wails/v3/internal/runtime/desktop/runtime.js
Lea Anthony 25577b7655
Support Clipboard.
Message Processor refactor.
2023-01-28 08:59:44 +11:00

52 lines
1.5 KiB
JavaScript

/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
/* jshint esversion: 9 */
const runtimeURL = window.location.origin + "/wails/runtime";
function runtimeCall(method, args) {
let url = new URL(runtimeURL);
url.searchParams.append("method", method);
if (args) {
for (let key in args) {
url.searchParams.append(key, args[key]);
}
}
return new Promise((resolve, reject) => {
fetch(url)
.then(response => {
if (response.ok) {
// check content type
if (response.headers.get("content-type") && response.headers.get("content-type").indexOf("application/json") !== -1) {
return response.json();
} else {
return response.text();
}
}
reject(Error(response.statusText));
})
.then(data => resolve(data))
.catch(error => reject(error));
});
}
export function newRuntimeCaller(object, id) {
if (!id || id === -1) {
return function (method, args) {
return runtimeCall(object + "." + method, args);
};
}
return function (method, args) {
args = args || {};
args["windowID"] = id;
return runtimeCall(object + "." + method, args);
}
}