mirror of
https://github.com/SteamDeckHomebrew/decky-frontend-lib.git
synced 2026-05-21 02:19:12 +02:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { ComponentType } from 'react';
|
|
import { RouteProps } from 'react-router';
|
|
|
|
export interface Plugin {
|
|
title: JSX.Element;
|
|
icon: JSX.Element;
|
|
content: JSX.Element;
|
|
onDismount?(): void;
|
|
}
|
|
|
|
interface ServerResponseSuccess<TRes> {
|
|
success: true;
|
|
result: TRes;
|
|
}
|
|
|
|
interface ServerResponseError {
|
|
success: false;
|
|
result: string;
|
|
}
|
|
|
|
type ServerResponse<TRes> = ServerResponseSuccess<TRes> | ServerResponseError;
|
|
|
|
interface RouterHook {
|
|
addRoute(path: string, component: ComponentType, props?: Omit<RouteProps, 'path' | 'children'>): void;
|
|
removeRoute(path: string): void;
|
|
}
|
|
|
|
export interface ServerAPI {
|
|
routerHook: RouterHook;
|
|
callPluginMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
|
|
callServerMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
|
|
fetchNoCors<TRes = {}>(url: string, request: RequestInfo): Promise<ServerResponse<TRes>>;
|
|
executeInTab(tab: string, runAsync: boolean, code: string): Promise<unknown>;
|
|
removeCssFromTab(tab: string, cssId: string): Promise<unknown>;
|
|
}
|
|
|
|
type DefinePluginFn = (serverAPI: ServerAPI) => Plugin;
|
|
|
|
// TypeScript helper function
|
|
export const definePlugin = (fn: DefinePluginFn): DefinePluginFn => {
|
|
return (...args) => {
|
|
// TODO: Maybe wrap this
|
|
return fn(...args);
|
|
};
|
|
};
|