UNPKG

tauri-settings

Version:

A user settings manager for Tauri inspired by electron-settings.

64 lines (63 loc) 2.91 kB
import { IConfigOptions } from '../utils/config'; import { Path, PathValue } from '../utils/dot-notation'; export declare class SettingsManager<SettingsSchema extends {} = any> { /** * The default values for the settings */ default: SettingsSchema; /** * Configuration for the settings manager */ config: IConfigOptions; /** @internal */ configId: number; constructor(defaultSettings: SettingsSchema, config?: IConfigOptions); /** * Initializes a settings file with the defaults. If settings exist, load them. * @returns The entire settings object */ initialize(): Promise<void>; /** * @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): Promise<boolean>; /** * Sets 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): Promise<any>; /** * 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 */ setCache<K extends Path<SettingsSchema>, V extends PathValue<SettingsSchema, K>>(key: K, value: V): Promise<void>; /** * Checks whether a key exists in the settings file. * @param key The key for the setting. Key supports dot notation. See https://github.com/harshkhandeparkar/tauri-settings#dot-notation. */ has<K extends Path<SettingsSchema>>(key: K): Promise<boolean>; /** * 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 */ set<K extends Path<SettingsSchema>, V extends PathValue<SettingsSchema, K>>(key: K, value: V): Promise<void>; /** * Saves the current settings cache to the storage. * @returns The entire settings object */ syncCache(): Promise<void>; }