mirror of
https://github.com/SteamDeckHomebrew/decky-frontend-lib.git
synced 2026-05-20 01:50:08 +02:00
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import type { ComponentType, ReactNode } from 'react';
|
|
import { RouteProps } from 'react-router';
|
|
|
|
export interface Plugin {
|
|
title: JSX.Element;
|
|
icon: JSX.Element;
|
|
content?: JSX.Element;
|
|
onDismount?(): void;
|
|
alwaysRender?: boolean;
|
|
}
|
|
|
|
interface ServerResponseSuccess<TRes> {
|
|
success: true;
|
|
result: TRes;
|
|
}
|
|
|
|
interface ServerResponseError {
|
|
success: false;
|
|
result: string;
|
|
}
|
|
|
|
export type ServerResponse<TRes> = ServerResponseSuccess<TRes> | ServerResponseError;
|
|
|
|
export type RoutePatch = (route: RouteProps) => RouteProps;
|
|
|
|
export interface RouterHook {
|
|
addRoute(path: string, component: ComponentType, props?: Omit<RouteProps, 'path' | 'children'>): void;
|
|
addPatch(path: string, patch: RoutePatch): RoutePatch;
|
|
addGlobalComponent(name: string, component: ComponentType): void;
|
|
removeRoute(path: string): void;
|
|
removePatch(path: string, patch: RoutePatch): void;
|
|
removeGlobalComponent(name: string): void;
|
|
}
|
|
|
|
export interface ToastData {
|
|
title: ReactNode;
|
|
body: ReactNode;
|
|
onClick?: () => void;
|
|
logo?: ReactNode;
|
|
icon?: ReactNode;
|
|
className?: string;
|
|
contentClassName?: string;
|
|
duration?: number;
|
|
critical?: boolean;
|
|
eType?: number;
|
|
sound?: number;
|
|
playSound?: boolean;
|
|
showToast?: boolean;
|
|
}
|
|
|
|
export interface Toaster {
|
|
toast(toast: ToastData): void;
|
|
}
|
|
|
|
export interface FilePickerRes {
|
|
path: string;
|
|
realpath: string;
|
|
}
|
|
|
|
export enum FileSelectionType {
|
|
FILE,
|
|
FOLDER,
|
|
}
|
|
|
|
export interface ServerAPI {
|
|
routerHook: RouterHook;
|
|
toaster: Toaster;
|
|
openFilePicker(startPath: string, includeFiles?: boolean, regex?: RegExp): Promise<FilePickerRes>;
|
|
openFilePickerV2(
|
|
select: FileSelectionType,
|
|
startPath: string,
|
|
includeFiles?: boolean,
|
|
includeFolders?: boolean,
|
|
filter?: RegExp | ((file: File) => boolean),
|
|
extensions?: string[],
|
|
showHiddenFiles?: boolean,
|
|
allowAllFiles?: boolean,
|
|
max?: number,
|
|
): Promise<FilePickerRes>;
|
|
callPluginMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
|
|
callServerMethod<TArgs = {}, TRes = {}>(methodName: string, args: TArgs): Promise<ServerResponse<TRes>>;
|
|
fetchNoCors<TRes = {}>(url: RequestInfo, request?: RequestInit): Promise<ServerResponse<TRes>>;
|
|
executeInTab(tab: string, runAsync: boolean, code: string): Promise<unknown>;
|
|
injectCssIntoTab<TRes = string>(tab: string, style: string): Promise<ServerResponse<TRes>>;
|
|
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);
|
|
};
|
|
};
|