diff --git a/core/src/net/sf/openrocket/arch/SystemInfo.java b/core/src/net/sf/openrocket/arch/SystemInfo.java index 316f313cc..27bf7d2bd 100644 --- a/core/src/net/sf/openrocket/arch/SystemInfo.java +++ b/core/src/net/sf/openrocket/arch/SystemInfo.java @@ -41,7 +41,24 @@ public class SystemInfo { } } - + /** + * Returns true if the OpenRocket is running a confined manner that may + * require alternative behaviors and experiences. + * + * Note: future versions may return further confinement information and + * this interface is subject to change. + * + * @return true if the system is running in a confined manner, false + * otherwise + */ + public static boolean isConfined() { + switch (getPlatform()) { + case UNIX: + return (System.getenv("SNAP_VERSION") != null); + default: + return false; + } + } /** diff --git a/swing/src/net/sf/openrocket/gui/dialogs/PrintDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/PrintDialog.java index d944d1d00..c1d2d2388 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/PrintDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/PrintDialog.java @@ -8,9 +8,12 @@ import java.awt.Desktop; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.BufferedInputStream; +import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Enumeration; import java.util.Iterator; @@ -31,6 +34,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.arch.SystemInfo; +import net.sf.openrocket.arch.SystemInfo.Platform; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.print.PrintController; import net.sf.openrocket.gui.print.PrintSettings; @@ -321,7 +326,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener { // TODO: HIGH: Remove UIManager, and pass settings to the actual printing methods TemplateProperties.setColors(settings); File f = generateReport(settings); - desktop.open(f); + openPreviewHelper(f); } catch (IOException e) { log.error("Could not open preview.", e); JOptionPane.showMessageDialog(this, new String[] { @@ -339,6 +344,20 @@ public class PrintDialog extends JDialog implements TreeSelectionListener { } } + private void openPreviewHelper(final File f) throws IOException { + if (SystemInfo.getPlatform() == Platform.UNIX && SystemInfo.isConfined()) { + /* When installed via a snap package on Linux, the default option + * to open PDF options using java.awt.Desktop.open() doesn't work + * due to using . Instead, use the xdg-open command + * which will work for URLs. + */ + String command = "xdg-open " + f.getAbsolutePath(); + Runtime.getRuntime().exec(command); + } else { + desktop.open(f); + } + } + /** * Handler for when the "Save as PDF" button is clicked. *