@@ -216,16 +216,25 @@ const createTemporaryBackup = async (): Promise<void> => {
216216
217217 async function pump ( ) : Promise < void > {
218218 const { done, value } = await reader . read ( ) ;
219- const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
220219
221220 if ( done ) {
222221 progressBarBackup ! . style . width = '100%' ;
223222 progressBarBackup ! . innerText = '100%' ;
224- progressBarBackup ! . classList . remove ( 'progress-bar-animated' ) ;
223+ progressBarBackup ! . classList . remove ( 'progress-bar-animated' , 'bg-primary' ) ;
224+ progressBarBackup ! . classList . add ( 'bg-success' ) ;
225225 return ;
226- } else {
227- progressBarBackup ! . style . width = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
228- progressBarBackup ! . innerText = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
226+ }
227+
228+ const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
229+ try {
230+ const data = JSON . parse ( decodedValue ) ;
231+ if ( data . progress ) {
232+ progressBarBackup ! . style . width = data . progress ;
233+ progressBarBackup ! . innerText = data . progress ;
234+ }
235+ } catch ( e ) {
236+ // Ignore JSON parse errors for incomplete chunks
237+ console . debug ( 'JSON parse error:' , e ) ;
229238 }
230239
231240 return pump ( ) ;
@@ -248,16 +257,25 @@ const installPackage = async (): Promise<void> => {
248257
249258 async function pump ( ) : Promise < void > {
250259 const { done, value } = await reader . read ( ) ;
251- const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
252260
253261 if ( done ) {
254262 progressBarInstallation ! . style . width = '100%' ;
255263 progressBarInstallation ! . innerText = '100%' ;
256- progressBarInstallation ! . classList . remove ( 'progress-bar-animated' ) ;
264+ progressBarInstallation ! . classList . remove ( 'progress-bar-animated' , 'bg-primary' ) ;
265+ progressBarInstallation ! . classList . add ( 'bg-success' ) ;
257266 return ;
258- } else {
259- progressBarInstallation ! . style . width = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
260- progressBarInstallation ! . innerText = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
267+ }
268+
269+ const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
270+ try {
271+ const data = JSON . parse ( decodedValue ) ;
272+ if ( data . progress ) {
273+ progressBarInstallation ! . style . width = data . progress ;
274+ progressBarInstallation ! . innerText = data . progress ;
275+ }
276+ } catch ( e ) {
277+ // Ignore JSON parse errors for incomplete chunks
278+ console . debug ( 'JSON parse error:' , e ) ;
261279 }
262280
263281 return pump ( ) ;
@@ -281,17 +299,26 @@ const updateDatabase = async (): Promise<void> => {
281299
282300 async function pump ( ) : Promise < void > {
283301 const { done, value } = await reader . read ( ) ;
284- const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
285302
286303 if ( done ) {
287304 progressBarInstallation ! . style . width = '100%' ;
288305 progressBarInstallation ! . innerText = '100%' ;
289- progressBarInstallation ! . classList . remove ( 'progress-bar-animated' ) ;
306+ progressBarInstallation ! . classList . remove ( 'progress-bar-animated' , 'bg-primary' ) ;
307+ progressBarInstallation ! . classList . add ( 'bg-success' ) ;
290308 card . classList . add ( 'text-bg-success' ) ;
291309 return ;
292- } else {
293- progressBarInstallation ! . style . width = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
294- progressBarInstallation ! . innerText = JSON . parse ( JSON . stringify ( decodedValue ) ) . progress ;
310+ }
311+
312+ const decodedValue : string = new TextDecoder ( ) . decode ( value ) ;
313+ try {
314+ const data = JSON . parse ( decodedValue ) ;
315+ if ( data . progress ) {
316+ progressBarInstallation ! . style . width = data . progress ;
317+ progressBarInstallation ! . innerText = data . progress ;
318+ }
319+ } catch ( e ) {
320+ // Ignore JSON parse errors for incomplete chunks
321+ console . debug ( 'JSON parse error:' , e ) ;
295322 }
296323
297324 return pump ( ) ;
0 commit comments