JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.27k stars 1.18k forks source link

Desktop: Add support for file associations #773

Closed cjbrooks12 closed 4 months ago

cjbrooks12 commented 3 years ago

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.

okushnikov commented 2 months ago

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

zhelenskiy commented 2 months ago

@okushnikov The integration didn't import mentions.