mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 05:11:29 +08:00

* Tidy up runtime JS * Initial implementation of runtime over http * Update runtime deps. Fix test task. * Support Clipboard. Message Processor refactor. * Add `Window.Screen()` Clipboard `GetText` -> `Text` * Support most dialogs Better JS->Go object mapping Implement Go->JS callback mechanism Rename `window.runtime` -> `window.wails` to better reflect the Go API * Support SaveFile dialog * Remove go.work * Tidy up * Event->CustomEvent to prevent potential clash with native JS Event object Support Eventing * Support application calls * Support logging * Support named windows Remove debug info * Update v3 changes
50 lines
1.4 KiB
JavaScript
50 lines
1.4 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) {
|
|
url.searchParams.append("args", JSON.stringify(args));
|
|
}
|
|
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);
|
|
}
|
|
} |