@@ -298,11 +298,44 @@ async function saveMode() {
298
298
data = treeContext . proofHistory ;
299
299
}
300
300
301
- //Slow Download
302
- if ( "showSaveFilePicker" in window ) {
303
- const saveHandle = await window . showSaveFilePicker ( {
301
+ //Errors caused due to file handler or html download element should not be displayed
302
+ try {
303
+ //Slow Download
304
+ if ( "showSaveFilePicker" in window ) {
305
+ const saveHandle = await window . showSaveFilePicker ( {
306
+ excludeAcceptAllOption : true ,
307
+ suggestedName : name ,
308
+ startIn : "downloads" ,
309
+ types : [
310
+ {
311
+ description : "JSON Files" ,
312
+ accept : {
313
+ "text/json" : [ ".json" ] ,
314
+ } ,
315
+ } ,
316
+ ] ,
317
+ } ) ;
318
+ saveFile ( saveHandle , data ) ;
319
+ } else {
320
+ //Quick Download
321
+ const f = document . createElement ( "a" ) ;
322
+ f . href = JSON . stringify ( data , null , "\t" ) ;
323
+ f . download = name + ".json" ;
324
+ f . click ( ) ;
325
+ }
326
+ } catch ( error ) {
327
+ //Catch error but do nothing
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Calls the function to load the files.
333
+ */
334
+ async function loadMode ( ) {
335
+ try {
336
+ const [ fileHandle ] = await window . showOpenFilePicker ( {
304
337
excludeAcceptAllOption : true ,
305
- suggestedName : name ,
338
+ multiple : false ,
306
339
startIn : "downloads" ,
307
340
types : [
308
341
{
@@ -313,52 +346,28 @@ async function saveMode() {
313
346
} ,
314
347
] ,
315
348
} ) ;
316
- saveFile ( saveHandle , data ) ;
317
- } else {
318
- //Quick Download
319
- const f = document . createElement ( "a" ) ;
320
- f . href = JSON . stringify ( data , null , "\t" ) ;
321
- f . download = name + ".json" ;
322
- f . click ( ) ;
323
- }
324
- }
325
349
326
- /**
327
- * Calls the function to load the files.
328
- */
329
- async function loadMode ( ) {
330
- const [ fileHandle ] = await window . showOpenFilePicker ( {
331
- excludeAcceptAllOption : true ,
332
- multiple : false ,
333
- startIn : "downloads" ,
334
- types : [
335
- {
336
- description : "JSON Files" ,
337
- accept : {
338
- "text/json" : [ ".json" ] ,
339
- } ,
340
- } ,
341
- ] ,
342
- } ) ;
343
-
344
- const file = await fileHandle . getFile ( ) ;
345
- const reader = new FileReader ( ) ;
346
- reader . addEventListener ( "load" , ( ) => {
347
- const aegData = reader . result ;
348
- if ( typeof aegData === "string" ) {
349
- const loadData = loadFile ( treeContext . modeState , aegData ) ;
350
- if ( treeContext . modeState === "Draw" ) {
351
- treeContext . tree = loadData as AEGTree ;
352
- redrawTree ( treeContext . tree ) ;
353
- } else if ( treeContext . modeState === "Proof" ) {
354
- treeContext . proofHistory = loadData as ProofNode [ ] ;
355
- redrawProof ( ) ;
350
+ const file = await fileHandle . getFile ( ) ;
351
+ const reader = new FileReader ( ) ;
352
+ reader . addEventListener ( "load" , ( ) => {
353
+ const aegData = reader . result ;
354
+ if ( typeof aegData === "string" ) {
355
+ const loadData = loadFile ( treeContext . modeState , aegData ) ;
356
+ if ( treeContext . modeState === "Draw" ) {
357
+ treeContext . tree = loadData as AEGTree ;
358
+ redrawTree ( treeContext . tree ) ;
359
+ } else if ( treeContext . modeState === "Proof" ) {
360
+ treeContext . proofHistory = loadData as ProofNode [ ] ;
361
+ redrawProof ( ) ;
362
+ }
363
+ } else {
364
+ console . log ( "Loading failed because reading the file was unsuccessful" ) ;
356
365
}
357
- } else {
358
- throw Error ( "Loading failed because reading the file was unsuccessful" ) ;
359
- }
360
- } ) ;
361
- reader . readAsText ( file ) ;
366
+ } ) ;
367
+ reader . readAsText ( file ) ;
368
+ } catch ( error ) {
369
+ //Do nothing
370
+ }
362
371
}
363
372
364
373
/**
0 commit comments