diff --git a/src/lib/components/modal.svelte b/src/lib/components/modal.svelte index af08125..1272c84 100644 --- a/src/lib/components/modal.svelte +++ b/src/lib/components/modal.svelte @@ -1,11 +1,14 @@ + + +

+ Capture your thoughts for later by writing a quick note. Add tags to categorize it and organize + your notes. +

+

+ This app keeps all of its data on your device. Your notes are private, never sent to an external + server. +

+ +
diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index b28d793..584cbb5 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -3,10 +3,12 @@ import { NotesStore } from './notes'; import { ThemeStore, type Theme } from './theme'; import { TagsStore } from './tags'; import { SettingsStore } from './settings'; +import { PersistenceStore } from './persistence'; export const tags = new TagsStore(); export const notes = new NotesStore(tags); +export const persistence = new PersistenceStore(); export const settings = new SettingsStore(); export const theme = new ThemeStore(); diff --git a/src/lib/stores/persistence.ts b/src/lib/stores/persistence.ts new file mode 100644 index 0000000..2c4090a --- /dev/null +++ b/src/lib/stores/persistence.ts @@ -0,0 +1,39 @@ +import { writable, type Readable } from 'svelte/store'; + +export class PersistenceStore implements Readable { + private persistence = writable(null); + + get prompted() { + return !!localStorage.promptedForPersistence; + } + private set prompted(value: boolean) { + localStorage.promptedForPersistence = value; + } + + constructor() { + this.check(); + } + + subscribe = this.persistence.subscribe; + + async check() { + if (navigator.storage && navigator.storage.persisted) { + let persisted: boolean | null = await navigator.storage.persisted(); + + if (persisted !== true) { + persisted = this.prompted ? false : null; + } + + this.persistence.set(persisted); + } + } + + async prompt() { + this.prompted = true; + + if (navigator.storage && navigator.storage.persist) { + const persisted = await navigator.storage.persist(); + this.persistence.set(persisted); + } + } +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index e6878d6..2ed84d9 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -5,6 +5,7 @@ import NoteListPlaceholder from '$lib/components/notes/note-list-placeholder.svelte'; import NoteList from '$lib/components/notes/note-list.svelte'; import SettingsModal from '$lib/components/settings/settings-modal.svelte'; + import WelcomeModal from '$lib/components/welcome-modal.svelte'; import { notes, tags } from '$lib/stores'; const notesCount = notes.count; @@ -24,6 +25,7 @@ +