Skip to content

Commit

Permalink
Fix opening pdf with okular in linux (#5253) (#5855)
Browse files Browse the repository at this point in the history
* Fix opening pdf with okular in linux (#5253)

* Fix opening pdf with okular in linux (#5253) stream ouput to Logger

* Fix checkstyle

Co-authored-by: Tobias Diez <[email protected]>
  • Loading branch information
t-morales and tobiasdiez committed Jan 26, 2020
1 parent eccfb57 commit 750279d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

### Fixed

- We fixed and issue where pdf files will not open under some KDE linux distributions when using okular. [#5253](https://github.com/JabRef/jabref/issues/5253)
- We fixed an issue where the Medline fetcher was only working when JabRef was running from source. [#5645](https://github.com/JabRef/jabref/issues/5645)
- We fixed some visual issues in the dark theme. [#5764](https://github.com/JabRef/jabref/pull/5764) [#5753](https://github.com/JabRef/jabref/issues/5753)
- We fixed an issue where non-default previews didn't handle unicode characters. [#5779](https://github.com/JabRef/jabref/issues/5779)
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.preferences.JabRefPreferences;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.jabref.preferences.JabRefPreferences.ADOBE_ACROBAT_COMMAND;
import static org.jabref.preferences.JabRefPreferences.USE_PDF_READER;

public class Linux implements NativeDesktop {
private static final Logger LOGGER = LoggerFactory.getLogger(Linux.class);

@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType);
Expand All @@ -30,7 +35,13 @@ public void openFile(String filePath, String fileType) throws IOException {
viewer = "xdg-open";
}
String[] cmdArray = { viewer, filePath };
Runtime.getRuntime().exec(cmdArray);
Process p = Runtime.getRuntime().exec(cmdArray);
// When the stream is full at some point, then blocks the execution of the program
// See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process.
BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
line = in.readLine();
LOGGER.debug("Received output: " + line);
}

@Override
Expand All @@ -46,7 +57,13 @@ public void openFileWithApplication(String filePath, String application) throws
String[] cmdArray = new String[openWith.length + 1];
System.arraycopy(openWith, 0, cmdArray, 0, openWith.length);
cmdArray[cmdArray.length - 1] = filePath;
Runtime.getRuntime().exec(cmdArray);
Process p = Runtime.getRuntime().exec(cmdArray);
// When the stream is full at some point, then blocks the execution of the program
// See https://stackoverflow.com/questions/10981969/why-is-going-through-geterrorstream-necessary-to-run-a-process.
BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
line = in.readLine();
LOGGER.debug("Received output: " + line);
}

@Override
Expand Down

0 comments on commit 750279d

Please sign in to comment.