tauri-settings
Version:
A user settings manager for Tauri inspired by electron-settings.
64 lines (63 loc) • 2.75 kB
TypeScript
import { ConfigOptions } from '../config/config';
import type { Path, PathValue } from '../types/dot-notation';
export declare class SettingsManager<SettingsSchema extends {} = any> {
/**
* @internal
*/
settings: SettingsSchema;
/**
* The default values for the settings
*/
default: SettingsSchema;
/**
* @internal
*/
path: string;
options: ConfigOptions;
constructor(defaultSettings: SettingsSchema, options?: ConfigOptions);
/**
* Initializes a settings file with the defaults. If settings exist, load them.
* @returns The entire settings object
*/
initialize(): Promise<SettingsSchema>;
/**
* @internal
*/
protected saveSettings(): Promise<void>;
/**
* Checks whether a key exists in the settings cache.
* @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation.
*/
hasCache<K extends Path<SettingsSchema>>(key: K): boolean;
/**
* Gets the value of a setting from the cache.
* @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation.
* @returns The value of the setting
*/
getCache<K extends Path<SettingsSchema>>(key: K): PathValue<SettingsSchema, K>;
/**
* Sets the value for a setting. Only updates cache.
* @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation.
* @param value The new value for the setting
* @returns The entire settings object
*/
setCache<K extends Path<SettingsSchema>, V extends PathValue<SettingsSchema, K>>(key: K, value: V): V;
/**
* Gets the value of a setting directly from the storage. Also updates cache.
* @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation.
* @returns The value of the setting
*/
get<K extends Path<SettingsSchema>>(key: K): Promise<PathValue<SettingsSchema, K>>;
/**
* Sets the value for a setting directly to the storage. Also updates cache.
* @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation.
* @param value The new value for the setting
* @returns The entire settings object
*/
set<K extends Path<SettingsSchema>, V extends PathValue<SettingsSchema, K>>(key: K, value: V): Promise<SettingsSchema>;
/**
* Saves the current settings cache to the storage.
* @returns The entire settings object
*/
syncCache(): Promise<SettingsSchema>;
}