// Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { getConfigJson, getMetaJson, getProfileConfigJson, setConfigJson, setMetaJson, setProfileConfigJson, } from "@generated/backend"; async function getSettingJson(key: string, backendGetter: (key: string) => Promise): Promise { const decoder = new TextDecoder(); const json = decoder.decode((await backendGetter(key)).json); return JSON.parse(json); } async function setSettingJson( key: string, value: any, backendSetter: (key: string, value: any) => Promise, ): Promise { const encoder = new TextEncoder(); const json = JSON.stringify(value); await backendSetter(key, encoder.encode(json)); } export async function getProfileConfig(key: string): Promise { return getSettingJson(key, async (k) => await getProfileConfigJson({ val: k })); } export async function setProfileConfig(key: string, value: any): Promise { return await setSettingJson(key, value, async (k, v) => await setProfileConfigJson({ key: k, valueJson: v })); } export async function getMeta(key: string): Promise { return getSettingJson(key, async (k) => await getMetaJson({ val: k })); } export async function setMeta(key: string, value: any): Promise { return await setSettingJson(key, value, async (k, v) => await setMetaJson({ key: k, valueJson: v })); } export async function getColConfig(key: string): Promise { return await getSettingJson(key, async (k) => await getConfigJson({ val: k })); } export async function setColConfig(key: string, value: any): Promise { return await setSettingJson( key, value, async (k, v) => await setConfigJson({ key: k, valueJson: v, undoable: true }), ); }