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

Desktop: Add support for file associations #773

Closed
cjbrooks12 opened this issue Jun 11, 2021 · 2 comments · Fixed by #4957 or #5054
Closed

Desktop: Add support for file associations #773

cjbrooks12 opened this issue Jun 11, 2021 · 2 comments · Fixed by #4957 or #5054
Assignees

Comments

@cjbrooks12
Copy link
Contributor

cjbrooks12 commented Jun 11, 2021

Feature Request

The current desktop packaging tasks do not include options for setting up file associations, a particularly valuable feature for desktop apps.

Possible Workaround

The AbstractJPackageTask allows us to add custom args with the freeArgs property, which get passed-through directly to jpackage. So to add our file associations, we should be able to follow the documentation linked above and manually add the args we need.

// build.gradle.kts
plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose")
}
compose.desktop {
    application {
		...
    }
}

tasks.withType<AbstractJPackageTask>().all {
    // add custom args to jpackage to set up file associations
    freeArgs.add("--file-associations")
    freeArgs.add(project.projectDir.resolve("ext.properties"))
}

macOS Problems

The above workaround does not seem to work on macOS (I have not tried it on other OSs). macOS handles file associations differently than Windows or Linux, and has a particularly verbose "registration" process that involves adding a bunch of additional information to the package's Info.plist file. Normally, jpackage would add all this info to the Info.plist file itself in accordance with the --file-associations property, but the Compose for Desktop Gradle plugin is writing that file itself. This means that even if we add those flags manually using the freeArgs property, the application will still not be registered to open custom file types, because the Compose Gradle plugin is not adding the necessary properties to the plist it writes.

In addition, the CfD plugin adds freeArgs before it configures itself, and it specifies --resource-dir for its own use when writing the Info.plist, so we cannot provide our own resource dir to write the plist by hand ourselves either.

Solution

Rather than writing the Info.plist file within the CfD Gradle plugin, it should let jpackage do it.

Potential Issues

There may already be info CfD is manually adding to Info.plist that jpackage is not adding (which may have been the reason for manually writing it in the first place). Removing the step to manually write the plist may cause issues with some of the existing Gradle plugin properties, and deeper research into customizing jpackage usage or other workarounds may need to be added to fully support them.

zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 6, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 12, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 20, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 21, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 21, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jun 22, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jul 1, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jul 1, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jul 1, 2024
[Desktop: Add support for file associations](JetBrains#773)
zhelenskiy added a commit to zhelenskiy/compose-multiplatform that referenced this issue Jul 1, 2024
terrakok pushed a commit that referenced this issue Jul 2, 2024
Add file associations support to Compose Desktop

<!-- Optional -->
Fixes #773

## Testing

Tested on the [sample
project](https://github.com/zhelenskiy/file-associations-demo).
Behaviours per OSs:
- MacOS Sonoma: associations work for distributables.
- Windows 11: associations work after the installation of the MSI.
- Kubuntu: associations do not work, but everything else works fine.
However, IDEA also does not have associations there, so I assume this is
fine.

I didn't write any unit tests because I don’t know which of them you are
expecting me to write. So, I'm looking forward to your feedback and
suggestions.

<!-- Optional -->
This should be tested by QA

## Release Notes
<!--
Optional, if omitted - won't be included in the changelog

Sections:
- Highlights
- Known issues
- Breaking changes
- Features
- Fixes

Subsections:
- Multiple Platforms
- iOS
- Desktop
- Web
- Resources
- Gradle Plugin
-->
### Highlight - Desktop
- Introduction of the new DSL function in `nativeDistributions` block:
  ```kotlin
fun fileAssociation(mimeType: String, extension: String, description:
String): Unit
  ```
igordmn pushed a commit that referenced this issue Jul 2, 2024
Docs for file associations support
(#4957) which
fixes #773.

---------

Co-authored-by: Aleksey Zamulla <aleksey.zamulla@jetbrains.com>
@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@zhelenskiy
Copy link
Member

zhelenskiy commented Aug 26, 2024

@okushnikov The integration didn't import mentions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants