Files
VRCX/src/ipc-electron/interopApi.js
2025-10-15 12:24:14 +11:00

42 lines
1.4 KiB
JavaScript

class InteropApi {
constructor() {
return new Proxy(this, {
get(target, prop) {
if (WINDOWS) {
return undefined;
}
// If the property is not a method of InteropApi,
// treat it as a .NET class name
if (typeof prop === 'string' && !target[prop]) {
return new Proxy(
{},
{
get(_, methodName) {
// Return a method that calls the .NET method dynamically
return async (...args) => {
return await target.callMethod(
prop,
methodName,
...args
);
};
}
}
);
}
return target[prop];
}
});
}
async callMethod(className, methodName, ...args) {
return window.interopApi
.callDotNetMethod(className, methodName, args)
.then((result) => {
return result;
});
}
}
export default new InteropApi();