Skip to content

Commit

Permalink
feat: Reworked callServerMethod for better reusability
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwmtr committed Nov 28, 2024
1 parent df0f153 commit f637f84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "millennium-lib",
"version": "3.6.11",
"version": "3.7.11",
"description": "A support library for creating plugins with Millennium.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
22 changes: 20 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
}
}

type IPC_types = (string | number | boolean)
/**
* Steam window popup manager.
*/
Expand Down Expand Up @@ -122,14 +123,31 @@ window.Millennium = {
Global Millennium API for developers.
*/
type Millennium = {
/* call a backend server method */
/**
* @brief Call a method on the backend
* @deprecated Use `callable` instead.
* Example usage:
* ```typescript
* // before
* const result = await Millennium.callServerMethod('methodName', { arg1: 'value' });
* // after
* const method = callable<[{ arg1: string }]>("methodName");
*
* const result1 = await method({ arg1: 'value1' });
* const result2 = await method({ arg1: 'value2' });
*/
callServerMethod: (methodName: string, kwargs?: object) => Promise<any>,
AddWindowCreateHook: (callback: (context: object) => void) => void,
findElement: (privateDocument: Document, querySelector: string, timeOut?: number) => Promise<NodeListOf<Element>>,
/* Expose a function to mainworld so it can be called from the backend */
exposeObj: <T extends object>(obj: T) => any
};

const callable = <Args extends any[] = [], Return = (void | IPC_types)>(
route: string
): ((...args: Args) => Promise<Return>) => {
return (...args: Args) => Millennium.callServerMethod(route, ...args);
};

const m_private_context: any = undefined

Expand All @@ -146,4 +164,4 @@ const m_private_context: any = undefined
const pluginSelf: any = m_private_context
const Millennium: Millennium = window.Millennium

export { Millennium, pluginSelf }
export { Millennium, pluginSelf, callable }
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"noImplicitAny": true,
"strict": true,
"ignoreDeprecations": "5.0",
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
Expand Down

0 comments on commit f637f84

Please sign in to comment.