Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/renderer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ConvertDialog from '$lib/components/ConvertDialog.svelte'
import AnalysisDialog from '$lib/components/AnalysisDialog.svelte'
import type { AnalysisSettings } from '$lib/analysis.svelte'
import type { SettingsSection } from '$lib/components/SettingsDialog.svelte'
import type { SettingsSection } from '$lib/components/settings/sections'

const library = new Library()
const decks = new Decks()
Expand Down
9 changes: 9 additions & 0 deletions app/src/renderer/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@
@utility tabular {
font-variant-numeric: tabular-nums;
}

@utility selected-row {
background-color: var(--color-select);
color: var(--color-fg);

& .text-faint {
color: var(--color-muted);
}
}
30 changes: 22 additions & 8 deletions app/src/renderer/src/lib/analysis.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AnalysisSettings {

const STORAGE_KEY = 'analysisSettings'

const DEFAULTS: AnalysisSettings = {
export const DEFAULT_ANALYSIS_SETTINGS: Readonly<AnalysisSettings> = {
auto: true,
gridMode: 'normal',
minBpm: 88,
Expand All @@ -40,23 +40,24 @@ const DEFAULTS: AnalysisSettings = {
key: true,
concurrency: 3
}
const SETTING_KEYS = Object.keys(DEFAULT_ANALYSIS_SETTINGS) as (keyof AnalysisSettings)[]

function load(): AnalysisSettings {
try {
const stored = JSON.parse(getSetting(STORAGE_KEY) ?? '{}') as Partial<AnalysisSettings>
const out = { ...DEFAULTS }
for (const key of Object.keys(DEFAULTS) as (keyof AnalysisSettings)[]) {
if (typeof stored[key] === typeof DEFAULTS[key]) Object.assign(out, { [key]: stored[key] })
const out = { ...DEFAULT_ANALYSIS_SETTINGS }
for (const key of SETTING_KEYS) {
if (typeof stored[key] === typeof DEFAULT_ANALYSIS_SETTINGS[key]) Object.assign(out, { [key]: stored[key] })
}
if (!BPM_RANGES.some(([lo, hi]) => lo === out.minBpm && hi === out.maxBpm)) {
out.minBpm = DEFAULTS.minBpm
out.maxBpm = DEFAULTS.maxBpm
out.minBpm = DEFAULT_ANALYSIS_SETTINGS.minBpm
out.maxBpm = DEFAULT_ANALYSIS_SETTINGS.maxBpm
}
if (out.gridMode !== 'normal' && out.gridMode !== 'dynamic') out.gridMode = DEFAULTS.gridMode
if (out.gridMode !== 'normal' && out.gridMode !== 'dynamic') out.gridMode = DEFAULT_ANALYSIS_SETTINGS.gridMode
out.concurrency = Math.max(1, Math.min(MAX_CONCURRENCY, Math.round(out.concurrency)))
return out
} catch {
return { ...DEFAULTS }
return { ...DEFAULT_ANALYSIS_SETTINGS }
}
}

Expand Down Expand Up @@ -93,9 +94,22 @@ export class Analysis {

set<K extends keyof AnalysisSettings>(key: K, value: AnalysisSettings[K]): void {
this.settings[key] = value
this.save()
}

private save(): void {
setSetting(STORAGE_KEY, JSON.stringify($state.snapshot(this.settings)))
}

get settingsAreDefault(): boolean {
return SETTING_KEYS.every((key) => this.settings[key] === DEFAULT_ANALYSIS_SETTINGS[key])
}

resetSettings(): void {
this.settings = { ...DEFAULT_ANALYSIS_SETTINGS }
this.save()
}

setRange(minBpm: number, maxBpm: number): void {
this.set('minBpm', minBpm)
this.set('maxBpm', maxBpm)
Expand Down
16 changes: 15 additions & 1 deletion app/src/renderer/src/lib/backups.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,25 @@ export class Backups {
}
}

get settingsAreDefault(): boolean {
return (Object.keys(DEFAULT_BACKUP_SETTINGS) as (keyof BackupSettings)[]).every(
(key) => this.settings[key] === DEFAULT_BACKUP_SETTINGS[key]
)
}

resetSettings(): Promise<void> {
return this.setSettings(DEFAULT_BACKUP_SETTINGS)
}

async setSettings(change: Partial<BackupSettings>): Promise<void> {
const previous = this.settings
this.settings = { ...previous, ...change }
try {
this.settings = await api.setBackupSettings(change)
await this.refresh()
const mayHavePruned = change.keep !== undefined && change.keep < previous.keep
if (mayHavePruned) this.list = await api.backupList()
} catch (e) {
this.settings = previous
this.error = (e as Error).message
}
}
Expand Down
Loading
Loading