diff --git a/v3/internal/runtime/desktop/main.js b/v3/internal/runtime/desktop/main.js index 573d92e7a..18e62785a 100644 --- a/v3/internal/runtime/desktop/main.js +++ b/v3/internal/runtime/desktop/main.js @@ -1,6 +1,6 @@ /* - _ __ _ __ -| | / /___ _(_) /____ + _ __ _ __ +| | / /___ _(_) /____ | | /| / / __ `/ / / ___/ | |/ |/ / /_/ / / (__ ) |__/|__/\__,_/_/_/____/ @@ -15,6 +15,7 @@ import * as Application from './application'; import * as Screens from './screens'; import * as System from './system'; import {Plugin, Call, callErrorCallback, callCallback, CallByID, CallByName} from "./calls"; +import {clientId} from './runtime'; import {newWindow} from "./window"; import {dispatchWailsEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events"; import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs"; @@ -25,6 +26,7 @@ import {setupDrag, endDrag} from "./drag"; window.wails = { ...newRuntime(null), Capabilities: {}, + clientId: clientId, }; fetch("/wails/capabilities").then((response) => { @@ -92,4 +94,4 @@ setupDrag(); document.addEventListener("DOMContentLoaded", function() { reloadWML(); -}); \ No newline at end of file +}); diff --git a/v3/internal/runtime/desktop/runtime.js b/v3/internal/runtime/desktop/runtime.js index 107c43ae4..33a3428ad 100644 --- a/v3/internal/runtime/desktop/runtime.js +++ b/v3/internal/runtime/desktop/runtime.js @@ -1,6 +1,6 @@ /* - _ __ _ __ -| | / /___ _(_) /____ + _ __ _ __ +| | / /___ _(_) /____ | | /| / / __ `/ / / ___/ | |/ |/ / /_/ / / (__ ) |__/|__/\__,_/_/_/____/ @@ -9,6 +9,7 @@ The electron alternative for Go */ /* jshint esversion: 9 */ +import { nanoid } from 'nanoid/non-secure'; const runtimeURL = window.location.origin + "/wails/runtime"; // Object Names @@ -23,6 +24,7 @@ export const objectNames = { Screens: 7, System: 8, } +export let clientId = nanoid(); function runtimeCall(method, windowName, args) { let url = new URL(runtimeURL); @@ -38,6 +40,8 @@ function runtimeCall(method, windowName, args) { if (args) { url.searchParams.append("args", JSON.stringify(args)); } + fetchOptions.headers["x-wails-client-id"] = clientId; + return new Promise((resolve, reject) => { fetch(url, fetchOptions) .then(response => { @@ -75,6 +79,7 @@ function runtimeCallWithID(objectID, method, windowName, args) { if (args) { url.searchParams.append("args", JSON.stringify(args)); } + fetchOptions.headers["x-wails-client-id"] = clientId; return new Promise((resolve, reject) => { fetch(url, fetchOptions) .then(response => { @@ -98,5 +103,3 @@ export function newRuntimeCallerWithID(object, windowName) { return runtimeCallWithID(object, method, windowName, args); }; } - -