0.12.0-3 Plugin Integration

This commit is contained in:
michael committed 2026-03-21 15:58:57 +00:00
1 parent d9969dfbe5
commit e99cdf1895
20 files changed
+928 -115

No files matched your search

+117 -8
View File
@@ -28,6 +28,15 @@ function clampPercent(value) {
return Math.max(0, Math.min(100, parsed));
}
function normalizeStage(value) {
return String(value || '').trim().toUpperCase();
}
function isTerminalStage(value) {
const normalized = normalizeStage(value);
return normalized === 'FINISHED' || normalized === 'ERROR' || normalized === 'CANCELLED';
}
function formatBytes(value) {
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 0) {
@@ -297,8 +306,49 @@ function App() {
: null;
setPipeline((prev) => {
const next = { ...prev };
const normalizedProgressJobId = normalizeJobId(progressJobId);
const progressStage = normalizeStage(payload?.state);
const isCdProgressStage = progressStage === 'CD_ANALYZING'
|| progressStage === 'CD_RIPPING'
|| progressStage === 'CD_ENCODING';
const incomingIsTerminal = isTerminalStage(progressStage);
const prevActiveJobId = normalizeJobId(prev?.activeJobId || prev?.context?.jobId);
const prevJobProgress = normalizedProgressJobId
? (prev?.jobProgress?.[normalizedProgressJobId] || null)
: null;
const prevJobProgressState = normalizeStage(prevJobProgress?.state);
const prevJobProgressIsTerminal = isTerminalStage(prevJobProgressState);
const matchingCdDriveEntry = normalizedProgressJobId
? Object.values(prev?.cdDrives || {}).find((driveState) => normalizeJobId(driveState?.jobId) === normalizedProgressJobId)
: null;
const matchingCdDriveIsTerminal = isTerminalStage(matchingCdDriveEntry?.state);
const hasKnownBinding = Boolean(
normalizedProgressJobId
&& (
prevActiveJobId === normalizedProgressJobId
|| prevJobProgress
|| matchingCdDriveEntry
)
);
// Ignore late/stale progress packets that arrive after a terminal state
// or for jobs that are no longer bound in pipeline state.
if (
normalizedProgressJobId
&& !incomingIsTerminal
&& (
prevJobProgressIsTerminal
|| matchingCdDriveIsTerminal
|| !hasKnownBinding
)
) {
return prev;
}
if (progressJobId != null) {
const previousJobProgress = prev?.jobProgress?.[progressJobId] || {};
const previousJobStage = normalizeStage(previousJobProgress?.state);
const keepPreviousJobStage = isTerminalStage(previousJobStage) && !incomingIsTerminal;
const mergedJobContext = contextPatch
? {
...(previousJobProgress?.context && typeof previousJobProgress.context === 'object'
@@ -313,19 +363,21 @@ function App() {
...(prev?.jobProgress || {}),
[progressJobId]: {
...previousJobProgress,
state: payload.state,
progress: payload.progress,
eta: payload.eta,
statusText: payload.statusText,
state: keepPreviousJobStage ? previousJobProgress.state : payload.state,
progress: keepPreviousJobStage ? previousJobProgress.progress : payload.progress,
eta: keepPreviousJobStage ? previousJobProgress.eta : payload.eta,
statusText: keepPreviousJobStage ? previousJobProgress.statusText : payload.statusText,
...(mergedJobContext !== undefined ? { context: mergedJobContext } : {})
}
};
}
if (progressJobId === prev?.activeJobId || progressJobId == null) {
next.state = payload.state ?? prev?.state;
next.progress = payload.progress ?? prev?.progress;
next.eta = payload.eta ?? prev?.eta;
next.statusText = payload.statusText ?? prev?.statusText;
const previousGlobalStage = normalizeStage(prev?.state);
const keepPreviousGlobalStage = isTerminalStage(previousGlobalStage) && !incomingIsTerminal;
next.state = keepPreviousGlobalStage ? prev?.state : (payload.state ?? prev?.state);
next.progress = keepPreviousGlobalStage ? prev?.progress : (payload.progress ?? prev?.progress);
next.eta = keepPreviousGlobalStage ? prev?.eta : (payload.eta ?? prev?.eta);
next.statusText = keepPreviousGlobalStage ? prev?.statusText : (payload.statusText ?? prev?.statusText);
if (contextPatch) {
next.context = {
...(prev?.context && typeof prev.context === 'object' ? prev.context : {}),
@@ -333,6 +385,63 @@ function App() {
};
}
}
// Keep per-drive CD progress in sync with live progress events.
// Backend sends frequent PIPELINE_PROGRESS updates, while cdDrives
// snapshots are only broadcast on state transitions.
if (isCdProgressStage && prev?.cdDrives && typeof prev.cdDrives === 'object') {
const cdDrivesEntries = Object.entries(prev.cdDrives);
const nextCdDrives = { ...prev.cdDrives };
const patchDrive = (driveState) => {
const currentDriveStage = normalizeStage(driveState?.state);
if (isTerminalStage(currentDriveStage) && !incomingIsTerminal) {
return driveState;
}
const mergedContext = contextPatch
? {
...(driveState?.context && typeof driveState.context === 'object' ? driveState.context : {}),
...contextPatch
}
: driveState?.context;
return {
...driveState,
state: payload?.state ?? driveState?.state,
progress: payload?.progress ?? driveState?.progress,
eta: payload?.eta ?? driveState?.eta,
statusText: payload?.statusText ?? driveState?.statusText,
...(mergedContext !== undefined ? { context: mergedContext } : {})
};
};
let updated = false;
if (normalizedProgressJobId) {
for (const [drivePath, driveState] of cdDrivesEntries) {
if (normalizeJobId(driveState?.jobId) === normalizedProgressJobId) {
nextCdDrives[drivePath] = patchDrive(driveState);
updated = true;
}
}
}
if (!updated) {
const activeCdEntries = cdDrivesEntries.filter(([, driveState]) => {
const driveStage = String(driveState?.state || '').trim().toUpperCase();
return driveStage === 'CD_ANALYZING'
|| driveStage === 'CD_RIPPING'
|| driveStage === 'CD_ENCODING';
});
if (activeCdEntries.length === 1) {
const [drivePath, driveState] = activeCdEntries[0];
nextCdDrives[drivePath] = patchDrive(driveState);
updated = true;
}
}
if (updated) {
next.cdDrives = nextCdDrives;
}
}
return next;
});
}