Closed rhbvkleef closed 3 years ago
Hi @rhbvkleef! I was hoping someone would request this feature sooner or later.
Let's recap how to achieve this on different platforms:
Info.plist
file.I was hoping someone would request this feature sooner or later.
Cool! Well, here ya go ;-)
I'm not really sure how to do it. Do you know if it depends on the used Linux distro?
Luckily, it doesn't. You can simply place the mime-type into the desktop file: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.5.html#mime-types
Let's recap how to achieve this on different platforms:
- Windows: it can be done adding some entries to Windows Registry.
As a starting point here the snippet i added to the iss.vtl
:
[Registry]
; create file associations
\#define MyAppName "${info.name}"
\#define MyFileExtension "FILENAMESUFFIXHERE"
\#define MyFileDescription "Human readable file type description here (what Windows Explorer will show)"
Root: HKCU; Subkey: "Software\Classes\.{#MyFileExtension}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName}File"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Classes\Mime\Database\Content Type\application/xml"; ValueType: string; ValueName: "Extension"; ValueData: ".{#MyFileExtension}"; Flags: uninsdeletevalue
Root: HKCU; Subkey: "Software\Classes\{#MyAppName}File"; ValueType: string; ValueName: ""; ValueData: "{#MyFileDescription}"; Flags: uninsdeletekey
Root: HKCU; Subkey: "Software\Classes\{#MyAppName}File\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppName}"" ""%1"""
Let's recap how to achieve this on different platforms:
- Windows: it can be done adding some entries to Windows Registry.
As a starting point here the snippet i added to the
iss.vtl
:[Registry] ; create file associations \#define MyAppName "${info.name}" \#define MyFileExtension "FILENAMESUFFIXHERE" \#define MyFileDescription "Human readable file type description here (what Windows Explorer will show)" Root: HKCU; Subkey: "Software\Classes\.{#MyFileExtension}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppName}File"; Flags: uninsdeletevalue Root: HKCU; Subkey: "Software\Classes\Mime\Database\Content Type\application/xml"; ValueType: string; ValueName: "Extension"; ValueData: ".{#MyFileExtension}"; Flags: uninsdeletevalue Root: HKCU; Subkey: "Software\Classes\{#MyAppName}File"; ValueType: string; ValueName: ""; ValueData: "{#MyFileDescription}"; Flags: uninsdeletekey Root: HKCU; Subkey: "Software\Classes\{#MyAppName}File\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppName}"" ""%1"""
Thanks!!
Hi @rhbvkleef! You can follow the work in progress in issue-103 branch.
I've been trying to associate extensions/mime-types to apps on Linux, but I'm not able to do it.
Luckily, it doesn't. You can simply place the mime-type into the desktop file: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.5.html#mime-types
It doesn't work just trying what is explained here. What if I want to associate a custom file format? e.g. ".hello" files.
Heeelp!!! 😓
Yes, you have to register a custom mime-type first.
For a user these are here: $HOME/.local/share/mime/
for users and here /usr/share/mime
for system
Example for opus-files:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="audio/x-opus+ogg">
<comment>Opus-Audio</comment>
<icon name="audio-x-flac+ogg"/>
<glob-deleteall/>
<glob pattern="*.opus"/>
</mime-type>
</mime-info>
You see there a file pattern (can be more than one). Then you can use this mime type in a .desktop-file. When installing a .deb, changes to the system-wise mime folder should be picked up automatically
More here: https://wiki.debian.org/MimeTypesSupport
Hi @commi! Yeah! Thanks.
But when I specify fileAssociations
in JavaPackager:
<fileAssociations>
<fileAssociation>
<description>HelloWorld File</description>
<extension>hello</extension>
<mimeType>application/hello</mimeType>
</fileAssociation>
</fileAssociations>
I'm creating a file like this in /usr/share/mime/packages
:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/hello">
<comment>HelloWorld File</comment>
<glob pattern="*.hello"/>
</mime-type>
</mime-info>
The following file in /usr/share/applications
:
[Desktop Entry]
Name=HelloWorld
GenericName=HelloWorld
Comment=My HelloWorld sample app
Exec=/opt/HelloWorld/HelloWorld %U
Icon=/opt/HelloWorld/HelloWorld.png
Terminal=false
Type=Application
StartupNotify=true
MimeType=application/hello;
When installing a .deb, changes to the system-wise mime folder should be picked up automatically
and yes, you are right, these system changes are triggered after installing a .deb.
but it doesn't work.
For that worked.
I created exactly those files and ran
sudo update-mime-database /usr/share/mime
manually
The file was recognized.
And after placing the desktop file, dolphin (KDE) tried to run /opt/HelloWorld/HelloWorld
when clicking the file.
Which file manager do you use?
For that worked. I created exactly those files and ran
sudo update-mime-database /usr/share/mime
manually
Oh! Great!!! I thought that this command was triggered after installing a DEB file ... so, do I have to include an after-install script including this command?
The file was recognized.
And after placing the desktop file, dolphin (KDE) tried to run
/opt/HelloWorld/HelloWorld
when clicking the file.Which file manager do you use?
I'm testing on a LinuxMint 20.1 (Mate), with nemo
file manager.
Afaik dpkg
really should trigger that itself, if it sees that a package modifies /usr/share/mime/packages
. You should not call that yourself. update-mime-database
(package shared-mime-info
) may not even be installed on all systems.
Maybe i can test den DEB you created here? can you upload it somewhere?
I've just installed my DEB file:
$ sudo dpkg -i HelloWorldMaven_1.0.0.deb
Seleccionando el paquete helloworldmaven previamente no seleccionado.
(Leyendo la base de datos ... 278851 ficheros o directorios instalados actualmente.)
Preparando para desempaquetar .../HelloWorldMaven_1.0.0.deb ...
Desempaquetando helloworldmaven (1.0.0) ...
Configurando helloworldmaven (1.0.0) ...
Procesando disparadores para gnome-menus (3.36.0-1ubuntu1) ...
Procesando disparadores para desktop-file-utils (0.24+linuxmint1) ...
Procesando disparadores para mime-support (3.64ubuntu1) ...
Procesando disparadores para shared-mime-info (1.15-1) ...
You can see here that shared-mime-info
triggers has been executed.
Then, I did some checks:
$ xdg-mime query default application/hello
HelloWorldMaven.desktop
$ xdg-mime query filetype prueba.hello
text/plain
and ... what!?! text/plain
?
Then, I executed sudo update-mime-database /usr/share/mime
... but with the same result! I'm missing something.
Here you have a link to my deb.
Thanks so much!!!
works great here:
(Doubleclick on the bla.hello)
(file details from Dolphin)
till@tbc:/tmp$ xdg-mime query filetype bla.hello
application/hello
Maybe some other mimetype claims *.hello on your system? Has you testfile any contents..maybe a BOM?
:exploding_head:
Maybe some other mimetype claims *.hello on your system?
It's a freshly installed virtual machine ... I'll have to do some research about this.
Has you testfile any contents..maybe a BOM?
No, because I'd like that the file associations was only by the file extension, not by the content.
Hi @rhbvkleef! Sorry! I've been a bit busy last month ... I hope to have more time now.
At the moment, file associations are implemented for GNU/Linux and Windows (only Setup installer, still need to implement for MSI installer), so you can already test it.
Thanks!
Hi @rhbvkleef! File association is already implemented for Mac OS X. You can try JavaPackager 1.6.0-SNAPSHOT issue-103, which has to be installed manually. If it works fine for you, I'll merge this branch to be released in 1.6.0.
Sorry for being so late. I hope you haven't lost faith in JavaPackager 😞
I write this information here for those who may be useful:
When we double click a file on Windows and GNU/Linux, the path of the file is passed to the executable as an argument.
But, on Mac OS X, it's a bit different. I put a link here with explanations about how to access a file open from the system in Mac OS X: https://openjfx-dev.openjdk.java.narkive.com/emgVmZMH/how-to-handle-file-open-requests-on-macos
Example on how to handle open files by double clicking on Mac OS X:
Branch issue-103 merged into master
Changes will be released in v1.6.0 asap.
JavaPackager v1.6.0 released to Maven Central
I'm submitting a…
Short description of the issue/suggestion:
We are able to specify file associations in jpackage (through the
--file-associations
switch). I would like to have the ability to do this too, using this plugin. I read through the source, and I cannot find how to do this. In fact, it appears that we are entirely unable to specify file associations.What is the expected behavior?
Have a
configuraiton
property namedfileAssociations
in which we are able to specify these associations.What is the current behavior?
There´s no way to specify these associations.
What is the motivation / use case for changing the behavior?
It is sometimes desired to register the java application to open certain files.
Please tell us about your environment: