import { preferences } from '@kit.ArkData' class YTPreferences { private static declare instance: YTPreferences private preferencesName: string = 'preferencesName' private declare preference: preferences.Preferences private constructor() { } static getInstance() { if (!YTPreferences.instance) { YTPreferences.instance = new YTPreferences() } return YTPreferences.instance } init(context: Context) { this.preference = preferences.getPreferencesSync(context, { name: this.preferencesName }) } setData(key: string, data: ESObject) { this.preference.putSync(key, data) this.preference.flushSync() } getData(key: string): ESObject { return this.preference.getSync(key, undefined) } removeData(key: string) { this.preference.deleteSync(key) } clear() { this.preference.clearSync() this.preference.flushSync() } } export const yTPreferences = YTPreferences.getInstance()