mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-22 16:23:50 +02:00
42 lines
1.4 KiB
JavaScript
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();
|