mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Unified prefs writing
This commit is contained in:
1 parent
957525393b
commit
4e9472c14a
8 files changed
+274
-69
No files matched your search
@@ -33,6 +33,7 @@ import { HotcueBar } from './HotcueBar'
|
||||
import { LoopControls, LOOP_SIZES, type LoopMode } from './LoopControls'
|
||||
import { MainWaveform, MIN_SEC, MAX_SEC, DEFAULT_SEC, type StemLane } from './MainWaveform'
|
||||
import { OverviewWaveform } from './OverviewWaveform'
|
||||
import { usePrefsWriter } from '../lib/prefs'
|
||||
|
||||
/** Keys that mute stems 1-4 (Shift = solo), by `KeyboardEvent.code`. */
|
||||
const STEM_KEYS = ['KeyQ', 'KeyW', 'KeyE', 'KeyR']
|
||||
@@ -165,11 +166,11 @@ export function PrepStrip({
|
||||
|
||||
// Main-waveform zoom persists to userprefs.json so it survives track switches
|
||||
// (MainWaveform unmounts during each load) and app restarts. Hydrate once from
|
||||
// the shared ['prefs'] query, then persist changes debounced (mirrors the
|
||||
// column-layout prefs flow in App).
|
||||
// the shared ['prefs'] query, then persist changes through the shared,
|
||||
// debounced prefs writer (as App's column layout does).
|
||||
const prefsQuery = useQuery({ queryKey: ['prefs'], queryFn: api.getPrefs })
|
||||
const zoomHydratedRef = useRef(false)
|
||||
const zoomSaveTimer = useRef<number | null>(null)
|
||||
const writePrefs = usePrefsWriter()
|
||||
useEffect(() => {
|
||||
if (zoomHydratedRef.current || !prefsQuery.data) return
|
||||
zoomHydratedRef.current = true
|
||||
@@ -180,20 +181,13 @@ export function PrepStrip({
|
||||
}, [prefsQuery.data])
|
||||
useEffect(() => {
|
||||
if (!zoomHydratedRef.current) return // don't clobber saved prefs pre-hydration
|
||||
if (zoomSaveTimer.current) window.clearTimeout(zoomSaveTimer.current)
|
||||
zoomSaveTimer.current = window.setTimeout(() => {
|
||||
api.patchPrefs({ mainZoomSec: secPerView }).catch(() => {})
|
||||
}, 500)
|
||||
return () => {
|
||||
if (zoomSaveTimer.current) window.clearTimeout(zoomSaveTimer.current)
|
||||
}
|
||||
}, [secPerView])
|
||||
writePrefs({ mainZoomSec: secPerView })
|
||||
}, [secPerView, writePrefs])
|
||||
|
||||
// The loop/jump size persists the same way (survives track switches +
|
||||
// restarts). `beatJumpBeats` is its name from when only beat jump had a size;
|
||||
// it is read once so an upgrade keeps the user's choice.
|
||||
const sizeHydratedRef = useRef(false)
|
||||
const sizeSaveTimer = useRef<number | null>(null)
|
||||
useEffect(() => {
|
||||
if (sizeHydratedRef.current || !prefsQuery.data) return
|
||||
sizeHydratedRef.current = true
|
||||
@@ -203,14 +197,8 @@ export function PrepStrip({
|
||||
}, [prefsQuery.data])
|
||||
useEffect(() => {
|
||||
if (!sizeHydratedRef.current) return // don't clobber saved prefs pre-hydration
|
||||
if (sizeSaveTimer.current) window.clearTimeout(sizeSaveTimer.current)
|
||||
sizeSaveTimer.current = window.setTimeout(() => {
|
||||
api.patchPrefs({ beatSize }).catch(() => {})
|
||||
}, 500)
|
||||
return () => {
|
||||
if (sizeSaveTimer.current) window.clearTimeout(sizeSaveTimer.current)
|
||||
}
|
||||
}, [beatSize])
|
||||
writePrefs({ beatSize })
|
||||
}, [beatSize, writePrefs])
|
||||
|
||||
const getCtx = (): AudioContext => {
|
||||
if (!audioCtxRef.current) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createPortal } from 'react-dom'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { api } from '../api'
|
||||
import { flushPrefs } from '../lib/prefs'
|
||||
|
||||
/**
|
||||
* Ask before quitting with unsaved changes: Save · Discard · Cancel.
|
||||
@@ -46,6 +47,7 @@ export function QuitGuard() {
|
||||
.then((s) => s.dirty)
|
||||
.catch(() => false) // no library loaded: nothing to lose
|
||||
if (!unsaved) {
|
||||
await flushPrefs(1000)
|
||||
await invoke('quit_now')
|
||||
return
|
||||
}
|
||||
@@ -73,6 +75,7 @@ export function QuitGuard() {
|
||||
}, [dirty])
|
||||
|
||||
const quit = async () => {
|
||||
await flushPrefs(1000) // a layout change made just before quitting still lands
|
||||
const { invoke } = await import('@tauri-apps/api/core')
|
||||
await invoke('quit_now')
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user