Self-hosted, federated location sharing app and server that prioritizes user privacy and security
end-to-end-encryption location-sharing privacy self-hosted federated
at consistent-ui 41 lines 1.1 kB view raw
1import { Store as TauriStore } from "@tauri-apps/plugin-store"; 2 3type Settings = { 4 server_url: string; 5 user_id: string; 6 friends: { name: string; id: string }[]; 7 is_admin: boolean; 8 priv_key: string; 9 is_sharing: boolean; 10}; 11 12export const Store = { 13 async get<T extends keyof Settings>(key: T): Promise<Settings[T]> { 14 const store = await TauriStore.load("settings.json"); 15 const value = await store.get<Settings[T]>(key); 16 if (value === undefined) { 17 alert(`Key ${key} not found in store`); 18 throw new Error(`Key ${key} not found in store`); 19 } 20 return value; 21 }, 22 23 async set<T extends keyof Settings>(key: T, value: Settings[T]): Promise<void> { 24 const store = await TauriStore.load("settings.json"); 25 await store.set(key, value); 26 await store.save(); 27 }, 28 29 async isLoggedIn(): Promise<boolean> { 30 const store = await TauriStore.load("settings.json"); 31 const user_id = await store.get<string>("user_id"); 32 return user_id !== undefined; 33 }, 34 35 // FOR TESTING ONLY 36 async reset(): Promise<void> { 37 const store = await TauriStore.load("settings.json"); 38 await store.reset(); 39 await store.save(); 40 }, 41};