fix(export): tu dong dong modal khi hoan tat + throttle setProgress 150ms (toc do export) + dong modal path server
This commit is contained in:
+17
-2
@@ -28101,6 +28101,8 @@ const App = () => {
|
||||
a.click();
|
||||
}
|
||||
});
|
||||
// Export server hoàn tất → tự đóng modal (toast Tải về vẫn hiện).
|
||||
setShowExportPanel(false);
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.error || 'Server processing failed');
|
||||
@@ -28486,6 +28488,7 @@ const App = () => {
|
||||
// Yield 1 frame → React vẽ thanh "Đang xử lý..." trước khi graph build +
|
||||
// OfflineAudioContext render chặn main thread.
|
||||
await new Promise(res => setTimeout(res, 30));
|
||||
let lastPaint = 0; // throttle setProgress 150ms — tránh re-render toàn App mỗi chunk
|
||||
try {
|
||||
const targetRate = parseInt(exportSettings.sampleRate);
|
||||
const isFloatWav = exportSettings.bitDepth === 'float';
|
||||
@@ -28602,7 +28605,11 @@ const App = () => {
|
||||
let mix = null;
|
||||
let vstTi = 0;
|
||||
for (const t of activeTracks) {
|
||||
setExportProgress(10 + Math.round((vstTi / Math.max(1, activeTracks.length)) * 40));
|
||||
const now = Date.now();
|
||||
if (now - lastPaint >= 150) {
|
||||
setExportProgress(10 + Math.round((vstTi / Math.max(1, activeTracks.length)) * 40));
|
||||
lastPaint = now;
|
||||
}
|
||||
vstTi++;
|
||||
const chain = activeVstChain(t.vstFxChain || []);
|
||||
const tctx = new OfflineAudioContext(2, Math.ceil(targetRate * Math.max(0.1, durationLimit)), targetRate);
|
||||
@@ -28703,7 +28710,13 @@ const App = () => {
|
||||
offset += bytesPerSample;
|
||||
}
|
||||
}
|
||||
setExportProgress(60 + Math.round((encEnd / Math.max(1, exportLength)) * 32));
|
||||
// Throttle setState 150ms → tránh re-render toàn App (1.7MB JSX) mỗi
|
||||
// chunk — đó là thứ làm export chậm rõ rệt.
|
||||
const now = Date.now();
|
||||
if (now - lastPaint >= 150) {
|
||||
setExportProgress(60 + Math.round((encEnd / Math.max(1, exportLength)) * 32));
|
||||
lastPaint = now;
|
||||
}
|
||||
await new Promise(res => setTimeout(res, 0));
|
||||
}
|
||||
if (peak < 0.001) {
|
||||
@@ -28779,6 +28792,8 @@ const App = () => {
|
||||
showToast("Xuất bản âm thanh hoàn tất!", "success");
|
||||
}
|
||||
}
|
||||
// Export hoàn tất → tự đóng modal.
|
||||
setShowExportPanel(false);
|
||||
} finally {
|
||||
// Restore the LIVE master bus after offline render: initMasterBus(offlineCtx)
|
||||
// ghi đè cả `masterBus` lẫn `window.masterBus` bằng graph OfflineAudioContext
|
||||
|
||||
Reference in New Issue
Block a user