import { reactive, watch } from "vue"; const SETTINGS_LOCALE = "settings_locale"; const SETTINGS_THEME = "settings_theme"; const SETTINGS_UNIT = "settings_unit"; function read(key) { return window.localStorage[key]; } function save(key) { return (value) => { try { if (value) { window.localStorage[key] = value; } else { delete window.localStorage[key]; } } catch (e) { console.error("unable to write to localstorage", { key, value }); } }; } const settings = reactive({ telemetry: null, locale: read(SETTINGS_LOCALE), theme: read(SETTINGS_THEME), unit: read(SETTINGS_UNIT), }); watch(() => settings.locale, save(SETTINGS_LOCALE)); watch(() => settings.theme, save(SETTINGS_THEME)); watch(() => settings.unit, save(SETTINGS_UNIT)); export default settings;