@launchmenu/core
Version:
An environment for visual keyboard controlled applets
111 lines • 4.62 kB
TypeScript
import { HMRWatcher } from "@launchmenu/hmr";
import { DataCacher, Field, IDataHook } from "model-react";
import { IAppletSource } from "./_types/IAppletSource";
import { IApplet } from "./_types/IApplet";
import { LaunchMenu } from "../LaunchMenu";
import { IUUID } from "../../_types/IUUID";
import { JSONFile } from "../../settings/storage/fileTypes/JSONFile";
import { ICategory } from "../../actions/types/category/_types/ICategory";
import { ISettingsTree } from "../../settings/_types/ISettingsTree";
import { IAppletData } from "./_types/IAppletData";
declare type ISettingsConfig = {
/** The directory that settings should be stored */
directory: string;
/** The function to retrieve the settings for a given applet */
getSettings: (applet: IApplet, version: IUUID) => ISettingsTree;
/** Removes the settings of a given applet */
removeSettings: (appletID: IUUID) => void;
};
/**
* A manager of applets, takes care of loading applets given their locations
*/
export declare class AppletManager {
protected LM: LaunchMenu;
protected reloadOnChanges: boolean;
protected settingsConfig: ISettingsConfig;
protected destroyed: Field<boolean>;
protected sourceFile: JSONFile;
/** A field that can be used to dynamically add any applets to the manager (does require some manual maintenance) */
extraApplets: Field<IAppletData[]>;
/** Versions numbers of the applets, such that applets are reloaded if their version changes */
protected appletVersions: Field<Record<string, number>>;
/**
* Creates a new applet manager instances with the given sources
* @param LM The LM instance that this applet manager is for
* @param settingsDirectory The directory to retrieve the installed applets from
* @param reloadOnChanges Whether to listen for applet code changes and update the applet when such a change occurs
*/
constructor(LM: LaunchMenu, settingsConfig: ISettingsConfig, reloadOnChanges?: boolean);
/**
* Properly disposes all data associated to this applet
* @param appletData The applet data to be disposed
*/
protected disposeAppletData(appletData: IAppletData): void;
/**
* Disposes of all data
*/
destroy(): void;
/**
* Retrieves all the applets, including dynamic extra applets
* @param hook The hook to subscribe to changes
* @returns The applets data
*/
getAppletsData(hook?: IDataHook): IAppletData[];
/**
* Retrieves the loaded applets
* @param hook The hook to subscribe to changes
* @returns The applets
*/
getApplets(hook?: IDataHook): IApplet[];
/**
* Retrieves the loaded applet with the given ID
* @param ID The ID of the applet to retrieve
* @param hook The hook to subscribe to changes
* @returns The applet if found
*/
getApplet(ID: IUUID, hook?: IDataHook): IApplet | null;
/**
* Retrieves the applet and categories that items for them can be listed in
* @param hook The hook to subscribe to changes
* @returns The applets and categories
*/
getAppletCategories(hook?: IDataHook): {
applet: IApplet;
category: ICategory;
}[];
/**
* Retrieves the category for the given applet
* @param applet The applet to get the category of
* @param hook The hook to subscribe to changes
* @returns The category
*/
getAppletCategory(applet: IApplet, hook?: IDataHook): ICategory | undefined;
/**
* Initializes an applet
* @param source The source data of the applet
* @param version The new version of the applet
* @throws An exception if no valid applet was found
* @returns The applet data
*/
protected initApplet({ ID, directory }: IAppletSource, version: IUUID): IApplet;
/**
* Retrieves a file watcher for a given applet
* @param source The source of the applet
* @param applet The applet to setup the watcher for
* @returns The file watcher that was created
*/
protected setupAppletWatcher(source: IAppletSource, applet: IApplet): HMRWatcher;
/**
* The sources in an array form
*/
protected sources: DataCacher<{
ID: string;
directory: string;
}[]>;
/**
* A transformer that obtains applets from the sources, versions and whether this manager is destroyed
*/
protected applets: DataCacher<IAppletData[]>;
}
export {};
//# sourceMappingURL=AppletManager.d.ts.map