Hannah-Sten / TeXiFy-IDEA

LaTeX support for the IntelliJ platform by JetBrains.
https://hannah-sten.github.io/TeXiFy-IDEA
MIT License
875 stars 86 forks source link

PDF viewer MIME/DE/xdg-open defaults are ignored #3313

Open danielzgtg opened 8 months ago

danielzgtg commented 8 months ago

Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

IntelliJ IDEA 2023.2.2 (Ultimate Edition) Build #IU-232.9921.47, built on September 12, 2023

Operating System

Ubuntu 23.10

TeXiFy IDEA version

0.9.1

What I did (steps to reproduce)

  1. Install
  2. Run any new document

Minimal example to reproduce the problem

\documentclass{article}
\begin{document}

\end{document}

Expected behavior

It should open Okular without me having to reconfigure it in the Run Configuration because it should autodetect my settings. If you want to parse the desktop environment, there is the XDG_CURRENT_DESKTOP=KDE environment variable. More generally, I have Okular at the top of my file associations, which is respected by xdg-open and part (the removed association of Evince) of it is stored at $XDG_CONFIG_DIRECTORY/mimeapps.list. Please detect the config in either place so people on both DEs will be happy.

Actual behavior

Evince is set to the default. Unlike Firefox, where removing the MIME association for zips causes it to use the KDE version, not even that works for TeXiFy. The only way to fix this is to change the Run Configuration. Uninstalling Evince could also work but I do not want to.

(if applicable) The full stacktrace of the exception thrown

No exception was thrown.

PHPirates commented 8 months ago

Thanks for the suggestion, I think you are right in that the current default is Evince if it is installed. We could have an entry like 'system default' which is selected by default if it is a supported PDF viewer. However, I don't know of a good way to check if xdg-open will open a supported PDF viewer? I would prefer opening a known supported PDF viewer rather than a system default one which is not. I'm not sure about using XDG_CURRENT_DESKTOP, because which desktop you are running does not directly imply which pdf viewer you have as default, even if there are likely options, but if you have multiple PDF viewers installed you are already not really a 'defaults only' user I would say. I don't have XDG_CONFIG_DIRECTORY, is that common to set manually, or a KDE thing?

Also I just want to check if you aware of run configuration templates: https://hannah-sten.github.io/TeXiFy-IDEA/running-a-latex-file.html#template-run-configurations

danielzgtg commented 8 months ago

Thank you for teaching me about run configuration templates. I just found out that there are both per-project and global versions. XDG_CONFIG_DIRECTORY is not set for me either, but it is specified that applications shall default to ~/.config. But nevermind those environment variables.

I remembered the command to find what xdg-open would open:

$ xdg-mime query default application/pdf
okularApplication_pdf.desktop
$ # After changing the file association:
$ xdg-mime query default application/pdf
org.gnome.Evince.desktop

This is part of the xdg-utils deb and is a preinstalled dependency of most desktop environments. If finding the .desktop file and parsing the Exec= would add too much complexity, TeXiFy could just match a substring in the xdg-mime output.

PHPirates commented 7 months ago

Thanks a lot! That command works for me as well, that should be easy enough to implement, indeed simple string matching should be sufficient. If it gives output then we can take the system default as default pdf viewer in the run configuration template.

I just remembered why it is not a good idea to use xdg-open by default: for forward search we need custom things, e.g. for Evince you need to communicate via the dbus.