import type { Jsonifiable } from "type-fest"; /** * Manages settings for a given namespace. * * This class should not be instantiated directly; use {@link init init()} for convenience and reliability. * * The {@link SettingsManager.load load()} method copies the namespaces' settings data from the file system into the manager. * All communication between a `SettingsManager` and the file system occurs synchronously over IPC. * * Once the settings data has been copied into the `SettingsManager`, it can be read and written synchronously. * The `SettingsManager` automatically queues and dispatches updates to the file system in the background. */ export declare class SettingsManager, D extends keyof T> { #private; /** * Namespace for these settings. */ namespace: string; /** * Creates a SettingsManager. This does not load any settings from storage; call the {@link SettingsManager.load load()} method * before attempting to manage any settings. * * Prefer calling {@link init} over constructing instances of this class directly, as `init()` automatically loads * settings from the file system. * @param namespace Namespace of settings to manage. */ constructor(namespace: string, defaultSettings?: Partial); /** * Gets a setting. * @param key Key of the setting to retrieve. * @param fallback Value to return if the key does not already exist. * @returns The value of the setting, or the fallback value if it does not already exist. */ get, F extends T[K] | undefined>(key: K, fallback?: F): K extends D ? NonNullable : F extends null | undefined ? T[K] | undefined : NonNullable | F; /** * Use a setting's value in React. * @param key Key of the setting to retrieve. * @param fallback Value to return if the key does not already exist. * @returns The value of the setting, or the fallback value if it does not already exist. */ useValue, F extends T[K] | undefined>(key: K, fallback?: F): K extends D ? NonNullable : F extends null | undefined ? T[K] | undefined : NonNullable | F; /** * Sets a setting. * @param key Key of the setting to set. * @param value Value to set for the setting. */ set>(key: K, value: T[K]): void; /** * Determines whether a setting exists for this namespace. * @param key Key to look for. * @returns Whether the setting already exists for this namespace. */ has(key: Extract): boolean; /** * Deletes a setting. * @param key Key of the setting to delete. * @returns Whether the setting was successfully deleted. */ delete(key: Extract): boolean; /** * Returns a copy of the settings data stored in this manager. * @returns Current values of all settings in this manager's namespace. */ all(): T; /** * Loads the latest stored settings for this namespace from the user's file system into this manager. This must be called * before managing any settings, unless you have created an instance using {@link init init()}, which calls this method. */ load(): void; } /** * Creates, initializes, and returns a {@link SettingsManager} for the given settings namespace. If a manager for the namespace already exists, * then that instance will be returned. Use this function rather than creating instances of `SettingsManager` directly. * * Settings are stored synchronously in the window, and updates are dispatched synchronously to the file system. * See {@link SettingsManager} for more information on how this works. * * Here's an example of how to use this in a plugin: * * ```ts * import { settings } from "replugged"; * * const defaultSettings = { * hello: "world", * }; * * const cfg = settings.init<{ hello: string; something: string }, "something">( * "dev.replugged.Example", * { something: "everything" }, * ); * * export function start() { * cfg.set("hello", "world"); * console.log(cfg.get("hello")); // world * * cfg.get("hello", "world"); // "world" will be used if there is no value for hello * cfg.get("something"); // "everything" will be used if there is no value for something * } * * ``` * @template T Type definition for the settings to manage in the namespace. * This will be an object with strings as keys, and JSON-serializable values. * @template D Keys in `T` that will always have a value. These keys will not be nullable. * @param namespace Namespace to manage. A namespace is an ID (for example, the ID of a plugin) that uniquely identifies it. * All settings are grouped into namespaces. * Settings for a namespace are stored in `settings/NAMESPACE.json` within the [Replugged data folder](https://docs.replugged.dev/#installing-plugins-and-themes). * @param defaultSettings Default values for the settings in the namespace. These will be used if no value is set for a setting. Using the `fallback` parameter of {@link SettingsManager.get get()} will override these defaults. * @returns Manager for the namespace. */ export declare function init, D extends keyof T = never>(namespace: string, defaultSettings?: Partial): SettingsManager;