bugfixes + added Training Stats
This commit is contained in:
parent
973a07fef8
commit
c905753f7a
@ -2033,6 +2033,24 @@ export default function App() {
|
||||
pausedByDisk: false,
|
||||
})
|
||||
|
||||
const applyAutostartState = useCallback((data: unknown) => {
|
||||
const d = (data ?? {}) as any
|
||||
|
||||
setAutostartState({
|
||||
paused: Boolean(d?.paused),
|
||||
pausedByUser: Boolean(d?.pausedByUser),
|
||||
pausedByDisk: Boolean(d?.pausedByDisk),
|
||||
})
|
||||
}, [])
|
||||
|
||||
const loadAutostartState = useCallback(async () => {
|
||||
const s = await apiJSON<AutostartState>('/api/autostart/state', {
|
||||
cache: 'no-store' as any,
|
||||
})
|
||||
|
||||
applyAutostartState(s)
|
||||
}, [applyAutostartState])
|
||||
|
||||
useEffect(() => {
|
||||
busyRef.current = busy
|
||||
}, [busy])
|
||||
@ -2714,6 +2732,7 @@ export default function App() {
|
||||
if (!authed) return
|
||||
|
||||
let es: EventSource | null = null
|
||||
let autostartEs: EventSource | null = null
|
||||
let fallbackTimer: number | null = null
|
||||
|
||||
const stopFallbackPoll = () => {
|
||||
@ -2758,15 +2777,6 @@ export default function App() {
|
||||
}
|
||||
}
|
||||
|
||||
const applyAutostartState = (data: unknown) => {
|
||||
const d = (data ?? {}) as any
|
||||
setAutostartState({
|
||||
paused: Boolean(d?.paused),
|
||||
pausedByUser: Boolean(d?.pausedByUser),
|
||||
pausedByDisk: Boolean(d?.pausedByDisk),
|
||||
})
|
||||
}
|
||||
|
||||
const onDoneChanged = () => {
|
||||
if (selectedTabRef.current !== 'finished') return
|
||||
void loadDonePage(donePageRef.current, doneSortRef.current)
|
||||
@ -2837,20 +2847,26 @@ export default function App() {
|
||||
void loadDoneCount()
|
||||
void loadTaskStateOnce()
|
||||
|
||||
void apiJSON<AutostartState>('/api/autostart/state', { cache: 'no-store' as any })
|
||||
.then((s) => {
|
||||
setAutostartState({
|
||||
paused: Boolean(s?.paused),
|
||||
pausedByUser: Boolean(s?.pausedByUser),
|
||||
pausedByDisk: Boolean(s?.pausedByDisk),
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
void loadAutostartState().catch(() => {})
|
||||
|
||||
es = new EventSource('/api/events/stream')
|
||||
eventSourceRef.current = es
|
||||
modelEventNamesRef.current = new Set()
|
||||
|
||||
autostartEs = new EventSource('/api/autostart/state/stream')
|
||||
|
||||
autostartEs.addEventListener('autostart', (ev) => {
|
||||
try {
|
||||
applyAutostartState(JSON.parse(String((ev as MessageEvent).data ?? 'null')))
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
})
|
||||
|
||||
autostartEs.onerror = () => {
|
||||
// Falls der separate Stream ausfällt, wenigstens beim Fokus/Visibility wieder korrekt ziehen.
|
||||
}
|
||||
|
||||
es.onopen = () => {
|
||||
stopFallbackPoll()
|
||||
void loadTaskStateOnce()
|
||||
@ -2867,8 +2883,10 @@ export default function App() {
|
||||
|
||||
const onVis = () => {
|
||||
if (document.hidden) return
|
||||
|
||||
void loadJobs()
|
||||
void loadTaskStateOnce()
|
||||
void loadAutostartState().catch(() => {})
|
||||
|
||||
if (selectedTabRef.current === 'finished') {
|
||||
void loadDonePage(donePageRef.current, doneSortRef.current)
|
||||
@ -2897,10 +2915,21 @@ export default function App() {
|
||||
es.close()
|
||||
}
|
||||
|
||||
if (autostartEs) {
|
||||
autostartEs.close()
|
||||
}
|
||||
|
||||
eventSourceRef.current = null
|
||||
modelEventNamesRef.current = new Set()
|
||||
}
|
||||
}, [authed, loadJobs, loadDoneCount, loadPendingAutoStarts])
|
||||
}, [
|
||||
authed,
|
||||
loadJobs,
|
||||
loadDoneCount,
|
||||
loadPendingAutoStarts,
|
||||
applyAutostartState,
|
||||
loadAutostartState,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
const desired = new Set<string>()
|
||||
@ -3970,14 +3999,14 @@ export default function App() {
|
||||
roomStatusByModelKey={roomStatusByModelKey}
|
||||
pending={pendingWatchedRooms}
|
||||
autostartState={autostartState}
|
||||
onRefreshAutostartState={async () => {
|
||||
onRefreshAutostartState={async (next?: AutostartState) => {
|
||||
try {
|
||||
const s = await apiJSON<AutostartState>('/api/autostart/state', { cache: 'no-store' as any })
|
||||
setAutostartState({
|
||||
paused: Boolean(s?.paused),
|
||||
pausedByUser: Boolean(s?.pausedByUser),
|
||||
pausedByDisk: Boolean(s?.pausedByDisk),
|
||||
})
|
||||
if (next) {
|
||||
applyAutostartState(next)
|
||||
return
|
||||
}
|
||||
|
||||
await loadAutostartState()
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ type Props = {
|
||||
jobs: RecordJob[]
|
||||
pending?: PendingWatchedRoom[]
|
||||
autostartState?: AutostartState
|
||||
onRefreshAutostartState?: () => Promise<void> | void
|
||||
onRefreshAutostartState?: (next?: AutostartState) => Promise<void> | void
|
||||
modelsByKey?: Record<
|
||||
string,
|
||||
{
|
||||
@ -644,9 +644,9 @@ export default function Downloads({
|
||||
|
||||
const [watchedBusy, setWatchedBusy] = useState(false)
|
||||
|
||||
const refreshWatchedState = useCallback(async () => {
|
||||
const refreshWatchedState = useCallback(async (next?: AutostartState) => {
|
||||
try {
|
||||
await onRefreshAutostartState?.()
|
||||
await onRefreshAutostartState?.(next)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
@ -678,11 +678,22 @@ export default function Downloads({
|
||||
|
||||
setWatchedBusy(true)
|
||||
try {
|
||||
const res = await fetch('/api/autostart/pause', { method: 'POST' })
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
await refreshWatchedState()
|
||||
} catch {
|
||||
// ignore
|
||||
const res = await fetch('/api/autostart/pause', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
cache: 'no-store' as any,
|
||||
body: JSON.stringify({ paused: true }),
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '')
|
||||
throw new Error(text || `HTTP ${res.status}`)
|
||||
}
|
||||
|
||||
const data = await res.json().catch(() => null)
|
||||
await refreshWatchedState(data ?? undefined)
|
||||
} catch (e) {
|
||||
console.warn('Autostart pausieren fehlgeschlagen:', e)
|
||||
} finally {
|
||||
setWatchedBusy(false)
|
||||
}
|
||||
@ -693,11 +704,20 @@ export default function Downloads({
|
||||
|
||||
setWatchedBusy(true)
|
||||
try {
|
||||
const res = await fetch('/api/autostart/resume', { method: 'POST' })
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
await refreshWatchedState()
|
||||
} catch {
|
||||
// ignore
|
||||
const res = await fetch('/api/autostart/resume', {
|
||||
method: 'POST',
|
||||
cache: 'no-store' as any,
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '')
|
||||
throw new Error(text || `HTTP ${res.status}`)
|
||||
}
|
||||
|
||||
const data = await res.json().catch(() => null)
|
||||
await refreshWatchedState(data ?? undefined)
|
||||
} catch (e) {
|
||||
console.warn('Autostart fortsetzen fehlgeschlagen:', e)
|
||||
} finally {
|
||||
setWatchedBusy(false)
|
||||
}
|
||||
@ -1578,8 +1598,8 @@ export default function Downloads({
|
||||
}
|
||||
leadingIcon={
|
||||
watchedPaused
|
||||
? <PauseIcon className="size-4 shrink-0" />
|
||||
: <PlayIcon className="size-4 shrink-0" />
|
||||
? <PlayIcon className="size-4 shrink-0" />
|
||||
: <PauseIcon className="size-4 shrink-0" />
|
||||
}
|
||||
>
|
||||
Autostart
|
||||
@ -1652,8 +1672,8 @@ export default function Downloads({
|
||||
}
|
||||
leadingIcon={
|
||||
watchedPaused
|
||||
? <PauseIcon className="size-4 shrink-0" />
|
||||
: <PlayIcon className="size-4 shrink-0" />
|
||||
? <PlayIcon className="size-4 shrink-0" />
|
||||
: <PauseIcon className="size-4 shrink-0" />
|
||||
}
|
||||
>
|
||||
Autostart
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user