diff --git a/app/components/@settings/tabs/update/UpdateTab.tsx b/app/components/@settings/tabs/update/UpdateTab.tsx index 45fdddb6..a279af47 100644 --- a/app/components/@settings/tabs/update/UpdateTab.tsx +++ b/app/components/@settings/tabs/update/UpdateTab.tsx @@ -19,6 +19,7 @@ interface UpdateProgress { totalSize?: string; currentCommit?: string; remoteCommit?: string; + updateReady?: boolean; }; } @@ -113,7 +114,10 @@ const UpdateTab = () => { headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ branch: branchToCheck }), + body: JSON.stringify({ + branch: branchToCheck, + autoUpdate: updateSettings.autoUpdate, + }), }); if (!response.ok) { @@ -152,10 +156,11 @@ const UpdateTab = () => { setIsChecking(false); if (!progress.error) { - // Update was successful + // Update check completed toast.success('Update check completed'); - if (progress.details?.changedFiles?.length) { + // Show update dialog only if there are changes and auto-update is disabled + if (progress.details?.changedFiles?.length && progress.details.updateReady) { setShowUpdateDialog(true); } } @@ -176,6 +181,69 @@ const UpdateTab = () => { } }; + const handleUpdate = async () => { + setShowUpdateDialog(false); + + try { + const branchToCheck = isLatestBranch ? 'main' : 'stable'; + + // Start the update with autoUpdate set to true to force the update + const response = await fetch('/api/update', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + branch: branchToCheck, + autoUpdate: true, + }), + }); + + if (!response.ok) { + throw new Error(`Update failed: ${response.statusText}`); + } + + // Handle the update progress stream + const reader = response.body?.getReader(); + + if (!reader) { + throw new Error('No response stream available'); + } + + while (true) { + const { done, value } = await reader.read(); + + if (done) { + break; + } + + const chunk = new TextDecoder().decode(value); + const lines = chunk.split('\n').filter(Boolean); + + for (const line of lines) { + try { + const progress = JSON.parse(line) as UpdateProgress; + setUpdateProgress(progress); + + if (progress.error) { + setError(progress.error); + toast.error('Update failed'); + } + + if (progress.stage === 'complete' && !progress.error) { + toast.success('Update completed successfully'); + } + } catch (e) { + console.error('Error parsing update progress:', e); + } + } + } + } catch (error) { + setError(error instanceof Error ? error.message : 'Unknown error occurred'); + toast.error('Update failed'); + } + }; + return (