- Add telemetry consent modal - Conditionally load telemetry script - Add telemetry consent to settings - Update and clarify privacy policy - Bump version number
25 lines
839 B
TypeScript
25 lines
839 B
TypeScript
// src/stores.js
|
|
import { writable, type Writable } from "svelte/store";
|
|
import { browser } from "$app/environment";
|
|
|
|
// Initialize the store with a boolean value from local storage
|
|
export const telemetry: Writable<boolean> = writable(fromLocalStorage("telemetry", false));
|
|
toLocalStorage(telemetry, "telemetry");
|
|
|
|
function fromLocalStorage(storageKey: string, fallback: boolean): boolean {
|
|
if (browser) {
|
|
const storedValue = localStorage.getItem(storageKey);
|
|
if (storedValue !== null && storedValue !== "undefined") {
|
|
return storedValue === "true";
|
|
}
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
function toLocalStorage(store: Writable<boolean>, storageKey: string) {
|
|
if (browser) {
|
|
store.subscribe((value: boolean) => {
|
|
localStorage.setItem(storageKey, String(value));
|
|
});
|
|
}
|
|
} |