[GENERIC viewer] Avoid data loss in forms, by triggering saving when the document is closed (issue 12257)
As discussed in the issue, this is a small/simple patch that should help to prevent *outright* data loss in forms when a new document is opened in the GENERIC viewer. While the implementation is perhaps a bit "simplistic", it does seem to work and should be fine given that this is an edge-case only relevant for the GENERIC viewer.
This commit is contained in:
		
							parent
							
								
									5b28a0bf97
								
							
						
					
					
						commit
						3f59d4201a
					
				
							
								
								
									
										28
									
								
								web/app.js
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								web/app.js
									
									
									
									
									
								
							@ -802,7 +802,19 @@ const PDFViewerApplication = {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!this.pdfLoadingTask) {
 | 
					    if (!this.pdfLoadingTask) {
 | 
				
			||||||
      return undefined;
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (
 | 
				
			||||||
 | 
					      (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
 | 
				
			||||||
 | 
					      this.pdfDocument?.annotationStorage.size > 0 &&
 | 
				
			||||||
 | 
					      this._annotationStorageModified
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        // Trigger saving, to prevent data loss in forms; see issue 12257.
 | 
				
			||||||
 | 
					        await this.save({ sourceEventType: "save" });
 | 
				
			||||||
 | 
					      } catch (reason) {
 | 
				
			||||||
 | 
					        // Ignoring errors, to ensure that document closing won't break.
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const promises = [];
 | 
					    const promises = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -851,8 +863,6 @@ const PDFViewerApplication = {
 | 
				
			|||||||
      PDFBug.cleanup();
 | 
					      PDFBug.cleanup();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    await Promise.all(promises);
 | 
					    await Promise.all(promises);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    return undefined;
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
@ -1707,11 +1717,19 @@ const PDFViewerApplication = {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    const { annotationStorage } = pdfDocument;
 | 
					    const { annotationStorage } = pdfDocument;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    annotationStorage.onSetModified = function () {
 | 
					    annotationStorage.onSetModified = () => {
 | 
				
			||||||
      window.addEventListener("beforeunload", beforeUnload);
 | 
					      window.addEventListener("beforeunload", beforeUnload);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
 | 
				
			||||||
 | 
					        this._annotationStorageModified = true;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    annotationStorage.onResetModified = function () {
 | 
					    annotationStorage.onResetModified = () => {
 | 
				
			||||||
      window.removeEventListener("beforeunload", beforeUnload);
 | 
					      window.removeEventListener("beforeunload", beforeUnload);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
 | 
				
			||||||
 | 
					        delete this._annotationStorageModified;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user