Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify file associations #103

Closed
2 of 5 tasks
rhbvkleef opened this issue Apr 3, 2021 · 22 comments
Closed
2 of 5 tasks

Specify file associations #103

rhbvkleef opened this issue Apr 3, 2021 · 22 comments
Labels
enhancement New feature or request

Comments

@rhbvkleef
Copy link

I'm submitting a…

  • bug report
  • feature request
  • other

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 named fileAssociations 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:

  • JavaPackager version: 1.5.1
  • OS version: Arch Linux on kernel 5.11
  • JDK version: OpenJDK 15.0.2 JDK
  • Build tool:
    • Maven
    • Gradle
@fvarrui fvarrui added the enhancement New feature or request label Apr 5, 2021
@fvarrui
Copy link
Owner

fvarrui commented Apr 5, 2021

Hi @rhbvkleef!
I was hoping someone would request this feature sooner or later.

Let's recap how to achieve this on different platforms:

  • Windows: it can be done adding some entries to Windows Registry.
  • Mac OS X: we have to specify UTIs (Uniform Type Identifiers) in Info.plist file.
  • Linux: I'm not really sure how to do it. Do you know if it depends on the used Linux distro?

@rhbvkleef
Copy link
Author

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

@commi
Copy link
Contributor

commi commented Apr 14, 2021

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"""

@fvarrui
Copy link
Owner

fvarrui commented Apr 15, 2021

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!!

@fvarrui
Copy link
Owner

fvarrui commented Apr 19, 2021

Hi @rhbvkleef!
You can follow the work in progress in issue-103 branch.

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

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!!! 😓

@commi
Copy link
Contributor

commi commented Apr 22, 2021

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

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

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.

@commi
Copy link
Contributor

commi commented Apr 22, 2021

For that worked.
I created exactly those files and ran
sudo update-mime-database /usr/share/mime
manually

grafik
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?

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

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?

grafik
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.

@commi
Copy link
Contributor

commi commented Apr 22, 2021

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?

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

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?

image

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!!!

@commi
Copy link
Contributor

commi commented Apr 22, 2021

works great here:

grafik

(Doubleclick on the bla.hello)

grafik
grafik

(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?

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

🤯

@fvarrui
Copy link
Owner

fvarrui commented Apr 22, 2021

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.

@fvarrui
Copy link
Owner

fvarrui commented May 3, 2021

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!

@fvarrui
Copy link
Owner

fvarrui commented Jul 4, 2021

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 😞

@fvarrui
Copy link
Owner

fvarrui commented Jul 7, 2021

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

@fvarrui
Copy link
Owner

fvarrui commented Jul 20, 2021

@fvarrui
Copy link
Owner

fvarrui commented Aug 21, 2021

Branch issue-103 merged into master

@fvarrui
Copy link
Owner

fvarrui commented Aug 21, 2021

Changes will be released in v1.6.0 asap.

@fvarrui
Copy link
Owner

fvarrui commented Sep 10, 2021

JavaPackager v1.6.0 released to Maven Central

@fvarrui fvarrui closed this as completed Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants