import { WxtStorageItem } from "wxt/storage"; export const defaultPreferences = { favoritedPlaces: { enabled: true }, bestFriends: { enabled: true }, forumMentions: { enabled: true } } export type preferencesSchema = typeof defaultPreferences & { [key: string]: any; }; // Sync interface PreferencesStorageItem extends WxtStorageItem { /** * Wrapper for the standard `.getValue()` method that merges the user's saved preferences with the default preferences to make sure there are no unexpected errors. */ getPreferences: () => Promise; } export const preferences: PreferencesStorageItem = storage.defineItem('sync:preferences', { fallback: defaultPreferences, version: 1 }) as PreferencesStorageItem; export const _favoritedPlaces = storage.defineItem('sync:favoritedPlaces', { fallback: ["9656"], version: 1 }); export const _bestFriends = storage.defineItem('sync:bestFriends', { fallback: ["2782"], version: 1 }); //@ts-ignore: Custom method for merging settings and defaults /* const _getValue = preferences.getValue; preferences.getValue = async function() { const userPreferences = await _getValue.call(this); return { ...defaultPreferences, ...userPreferences }; }; */ preferences.getPreferences = async function() { const userPreferences = await this.getValue(); return { ...defaultPreferences, ...userPreferences }; }; // Cache export const cache = storage.defineItem('local:cache', { fallback: { favoritedPlaces: [] }, version: 1 }); // Limits export const limits = { favoritedPlaces: 15 }