@@ -2214,6 +2214,29 @@ else if (command.equalsIgnoreCase("Calculation")) {
22142214 }
22152215 }
22162216
2217+ /**
2218+ * Show a warning on saving file in an unsafe folder that will be removed after closing JGEX.
2219+ * In a Flathub sandbox, this is an important message for the user because the OS
2220+ * does not inform the user on saving a file in a temporary folder.
2221+ * @param file The user wants to use as the saved file.
2222+ */
2223+ private void showWarningUnsafeFolder (File file ) {
2224+ // Linux Flathub related code.
2225+ String absolutePath = file .getAbsolutePath ();
2226+ String documentsDir = System .getenv ("XDG_DOCUMENTS_DIR" );
2227+ String downloadDir = System .getenv ("XDG_DOWNLOAD_DIR" );
2228+ String flatpakId = System .getenv ("FLATPAK_ID" );
2229+ if (flatpakId != null && documentsDir != null && downloadDir != null
2230+ && !absolutePath .startsWith (documentsDir ) && !absolutePath .startsWith (downloadDir )) {
2231+ JOptionPane .showMessageDialog (null ,
2232+ "The application is running in Flatpak's sandbox.\n " +
2233+ "It is not possible to save data permanently in an arbitrary folder.\n " +
2234+ "Please save your data in your Documents or Downloads folder\n " +
2235+ "in order to avoid data loss after closing the program."
2236+ );
2237+ }
2238+ }
2239+
22172240 /**
22182241 * Saves the GDD proof as a GraphViz file.
22192242 *
@@ -2252,6 +2275,7 @@ private void saveGDDProofAsGraphViz(Object src) {
22522275 } catch (Exception ee ) {
22532276 ee .printStackTrace ();
22542277 }
2278+ showWarningUnsafeFolder (ff );
22552279 }
22562280
22572281 /**
@@ -2424,6 +2448,7 @@ public boolean saveAFile(boolean n) {
24242448 }
24252449 if (file != null )
24262450 try {
2451+ showWarningUnsafeFolder (file );
24272452 String path = file .getPath ();
24282453 if (!path .endsWith (".gex" )) {
24292454 path += ".gex" ;
@@ -2583,6 +2608,8 @@ public void saveProofAsGIF() {
25832608 chooser .setCurrentDirectory (new File (dr ));
25842609
25852610 File ff = chooser .getSelectedFile ();
2611+ showWarningUnsafeFolder (ff );
2612+
25862613 String p = ff .getPath ();
25872614 if (!p .endsWith ("gif" ) && !p .endsWith ("GIF" )) {
25882615 p = p + ".gif" ;
@@ -2657,14 +2684,16 @@ public void saveAsGIF() {
26572684
26582685
26592686 File ff = chooser .getSelectedFile ();
2687+ showWarningUnsafeFolder (ff );
2688+
26602689 String p = ff .getPath ();
26612690 if (!p .endsWith ("gif" ) && !p .endsWith ("GIF" )) {
26622691 p = p + ".gif" ;
26632692 ff = new File (p );
26642693 }
26652694
26662695
2667- am .reClaclulate ();
2696+ am .reCalculate ();
26682697 int n = am .getRounds ();
26692698 if (n == 0 ) return ;
26702699
@@ -2759,6 +2788,8 @@ public void saveAsImage() {
27592788 }
27602789
27612790 File ff = chooser .getSelectedFile ();
2791+ showWarningUnsafeFolder (ff );
2792+
27622793 FileFilter f = chooser .getFileFilter ();
27632794 String endfix = f .getDescription ();
27642795 if (endfix == null )
0 commit comments