Cleanup, progress storing and settings handling

This commit is contained in:
ZXY101
2023-09-21 09:32:44 +02:00
parent 8e4c105f6c
commit da342e14e9
9 changed files with 235 additions and 120 deletions

View File

@@ -1,6 +1,21 @@
import { browser } from "$app/environment";
import { writable } from "svelte/store";
type FontSize = 'auto' |
'9' |
'10' |
'11' |
'12' |
'14' |
'16' |
'18' |
'20' |
'24' |
'32' |
'40' |
'48' |
'60'
type Settings = {
zoomMode: 'keep' | 'something'
rightToLeft: boolean;
@@ -9,26 +24,36 @@ type Settings = {
textBoxBorders: boolean;
displayOCR: boolean;
boldFont: boolean;
pageNum: boolean;
hasCover: boolean;
backgroundColor: string;
fontSize: FontSize;
};
export type SettingsKey = keyof Settings
const defaultSettings: Settings = {
zoomMode: 'keep',
rightToLeft: true,
singlePageView: true,
hasCover: false,
displayOCR: true,
textEditable: false,
textBoxBorders: false,
boldFont: false,
backgroundColor: '#0d0d0f'
pageNum: true,
backgroundColor: '#0d0d0f',
fontSize: 'auto'
}
const stored = browser ? window.localStorage.getItem('settings') : undefined
const initialSettings: Settings = stored && browser ? JSON.parse(stored) : defaultSettings
export * from './progress'
export const settings = writable<Settings>(initialSettings);
export function updateSetting(key: string, value: any) {
export function updateSetting(key: SettingsKey, value: any) {
settings.update((settings) => {
return {
...settings,