mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
store settings
This commit is contained in:
@@ -3,6 +3,7 @@ import { GPXFile } from 'gpx';
|
||||
import { type FreezedObject, type Patch, produceWithPatches, applyPatches } from 'structurajs';
|
||||
import { writable, get, derived, type Readable, type Writable } from 'svelte/store';
|
||||
import { fileOrder, selectedFiles } from './stores';
|
||||
import { mode } from 'mode-watcher';
|
||||
|
||||
class Database extends Dexie {
|
||||
|
||||
@@ -259,4 +260,37 @@ export const dbUtils = {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dexieSettingStore(setting: string, initial: any): Writable<any> {
|
||||
let store = writable(initial);
|
||||
liveQuery(() => db.settings.get(setting)).subscribe(value => {
|
||||
if (value !== undefined) {
|
||||
store.set(value);
|
||||
}
|
||||
});
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
set: (value: any) => db.settings.put(value, setting),
|
||||
update: (callback: (value: any) => any) => {
|
||||
let newValue = callback(get(store));
|
||||
db.settings.put(newValue, setting);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const settings = {
|
||||
distanceUnits: dexieSettingStore('distanceUnits', 'metric'),
|
||||
velocityUnits: dexieSettingStore('velocityUnits', 'speed'),
|
||||
temperatureUnits: dexieSettingStore('temperatureUnits', 'celsius'),
|
||||
mode: dexieSettingStore('mode', (() => {
|
||||
let currentMode: string | undefined = get(mode);
|
||||
if (currentMode === undefined) {
|
||||
currentMode = 'system';
|
||||
}
|
||||
return currentMode;
|
||||
})()),
|
||||
routing: dexieSettingStore('routing', true),
|
||||
routingProfile: dexieSettingStore('routingProfile', 'bike'),
|
||||
privateRoads: dexieSettingStore('privateRoads', false),
|
||||
};
|
Reference in New Issue
Block a user