hydraulic-software / conveyor

Gradle plugin, user guide and discussion forums for Conveyor
https://conveyor.hydraulic.dev
Apache License 2.0
123 stars 9 forks source link

File associations and URL handlers #5

Closed mikehearn closed 1 year ago

mikehearn commented 2 years ago

Vote for this if you need packaged apps to support registering file associations and URL handlers.

mikehearn commented 1 year ago

URL handlers can be done in Conveyor 4 using some custom config. Future releases will simplify the configuration required, but that isn't strictly necessary. See here for how:

https://conveyor.hydraulic.dev/4.0/configs/os-integration/#url-handlers

ennerf commented 1 year ago

I tried the custom config parameters to get file associations (double click) working

Windows

The MSIX extension also works for file associations

app.windows.manifests.msix.extensions-xml = """
  <uap:Extension Category="windows.fileTypeAssociation">
      <uap3:FileTypeAssociation Name="textfile" Parameters="%1">
        <uap:SupportedFileTypes>
          <uap:FileType>.txt</uap:FileType>
        </uap:SupportedFileTypes>
      </uap3:FileTypeAssociation>
  </uap:Extension>
  """

macOS

The macOS documentation is unfortunately terrible, but I got it to work with the settings below. Some links that ended up being helpful:

Minimal for double click support

app.mac.info-plist.CFBundleDocumentTypes = [
    {
      // Minimal settings to allow opening
      CFBundleTypeRole = Viewer
      CFBundleTypeExtensions = [txt]
    }
  ]

Using a custom type with icon

app.mac.info-plist.CFBundleDocumentTypes = [
    {
      CFBundleTypeRole = Viewer
      CFBundleTypeExtensions = [extension]

      // Custom type definition
      CFBundleTypeName = "My Type Name"
      CFBundleTypeIconFile = app.icns
      LSHandlerRank = Owner
      LSTypeIsPackage = false
    }
  ]

Linux

I'm not sure about Linux, but after selecting the application it worked. To map it directly after install it probably needs a custom mime type and a registration in the postinstall script.

app.linux.desktop-file."Desktop Entry" {
    Exec = ${app.linux.install-path}/bin/${app.fsname} %f
    MimeType = application/octet-stream // or x-${app.fsname} for custom ones
  }

Exec codes

ennerf commented 1 year ago

The actual file handling on macOS is not straight forward though. Windows and Linux supply the file name as the first argument, but macOS needs to integrate with a native library.

I found several issues for it (e.g. How to handle file open requests on MacOS), but there still does not seem to be a fully supported/working way for JavaFX. Swing got the setOpenFileHandler added to java.awt.Desktop in Java 9, but there may be some caveats (JDK-8239590) when using it from JavaFX.

mikehearn commented 1 year ago

Yes, that looks right. We're adding native support for file associations at the moment. It won't be in the next feature release, probably the one after that. It boils down to what you're saying plus some code to handle Linux.

mikehearn commented 1 year ago

Re: JavaFX. Yes, it needs some more work on the native side to do the equivalent for AWT.

mikehearn commented 1 year ago

File associations have been released!

ennerf commented 1 year ago

Nice 👍 Is there a way to bundle icons too?

mikehearn commented 1 year ago

At the moment per-file type icons aren't supported. Is it so common to create dedicated icons for files these days? A surprising number of our users are using the auto-generated icons already.

ennerf commented 1 year ago

I didn't see icons mentioned in the docs, so I wasn't sure what it does without doing a sample project. Registering the application icon makes sense and would work well enough for me 👍

mikehearn commented 1 year ago

Yep, the icon used is the application icon.

ennerf commented 1 year ago

Fyi, I just replaced my previous hacks and it works like a charm 👍

The only issue I ran into was that Ubuntu 20.04 does not show the icon for the mime-type, in case it should be doing that.