mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 08:52:59 +00:00
feat: de-clutter navbar
fix: backup option not working refactor: persistent writable stores [deploy]
This commit is contained in:
@@ -3,6 +3,8 @@ import {CharaDevice} from "$lib/serial/device"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import type {Writable} from "svelte/store"
|
||||
import type {CharaLayout} from "$lib/serialization/layout"
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {userPreferences} from "$lib/preferences"
|
||||
|
||||
export const serialPort = writable<CharaDevice>()
|
||||
|
||||
@@ -13,9 +15,13 @@ export interface SerialLogEntry {
|
||||
|
||||
export const serialLog = writable<SerialLogEntry[]>([])
|
||||
|
||||
export const chords = writable<Chord[]>([])
|
||||
export const chords = persistentWritable<Chord[]>("chord-library", [], () => get(userPreferences).backup)
|
||||
|
||||
export const layout = writable<CharaLayout>([[], [], []])
|
||||
export const layout = persistentWritable<CharaLayout>(
|
||||
"layout",
|
||||
[[], [], []],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
|
||||
export const settings = writable({})
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import {chords, layout} from "$lib/serial/connection"
|
||||
import {userPreferences} from "$lib/preferences"
|
||||
|
||||
const PROFILE_KEY = "profiles"
|
||||
const CHORD_LIBRARY_STORAGE_KEY = "chord-library"
|
||||
const LAYOUT_STORAGE_KEY = "layouts"
|
||||
const PREFERENCES = "user-preferences"
|
||||
|
||||
export function initLocalStorage() {
|
||||
const storedPreferences = localStorage.getItem(PREFERENCES)
|
||||
if (storedPreferences) {
|
||||
userPreferences.set(JSON.parse(storedPreferences))
|
||||
}
|
||||
userPreferences.subscribe(preferences => {
|
||||
localStorage.setItem(PREFERENCES, JSON.stringify(preferences))
|
||||
})
|
||||
|
||||
const storedLayout = localStorage.getItem(LAYOUT_STORAGE_KEY)
|
||||
if (storedLayout) {
|
||||
layout.set(JSON.parse(storedLayout))
|
||||
}
|
||||
const storedChords = localStorage.getItem(CHORD_LIBRARY_STORAGE_KEY)
|
||||
if (storedChords) {
|
||||
chords.set(JSON.parse(storedChords))
|
||||
}
|
||||
|
||||
layout.subscribe(layout => {
|
||||
localStorage.setItem(LAYOUT_STORAGE_KEY, JSON.stringify(layout))
|
||||
})
|
||||
chords.subscribe(chords => {
|
||||
localStorage.setItem(CHORD_LIBRARY_STORAGE_KEY, JSON.stringify(chords))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user