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

Add file associations for Windows applications #62

Merged
merged 9 commits into from
Feb 14, 2025

Conversation

davidfokkema
Copy link
Contributor

@davidfokkema davidfokkema commented Feb 11, 2025

This PR adds file associations to Windows apps. The support in briefcase.toml is already there and the feature is documented. It wasn't yet implemented for Windows, however.

Refs beeware/briefcase#1706 (corrects the problem for Windows).

I tested with https://github.com/davidfokkema/helloworld. This repository may be removed when the PR is merged. The relevant sections of pyproject.toml are:

[tool.briefcase.app.helloworld.document_type.project]
description = "Hello Project File"
extension = "hpf"
icon = "resources/document"
url = "https://example.com"

[tool.briefcase.app.helloworld.document_type.data]
description = "Hello Data File"
extension = "hda"
icon = "resources/document-data"
url = "https://example.com"

with the resources folder containing the icons inside the module. So, relative to the repository root, the icons are located in src/helloworld/resources. This makes them easy to reach from the .wxs file via the ROOTDIR and then src\app\helloworld\resources. This differs from the repository layout where they are at src/helloworld/resources, so without the app in between. For Windows, I think this is now solved cleanly. However, on macOS, I believe the icon paths were relative to the repository root. I may want to propose to change that when I'm working on that PR.

What is left to do: if we want to change the icon path, we should document that.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@davidfokkema
Copy link
Contributor Author

Still working on it, will check off all the boxes.

@davidfokkema
Copy link
Contributor Author

To test the functionality of this PR, add this to your project settings in your pyproject.toml:

[tool.briefcase.app.your_app_name]
template = "https://github.com/davidfokkema/briefcase-windows-app-template"
template_branch = "file-associations"

@fedelibre
Copy link

@davidfokkema I did a quick test here and it's failing, apparently because of the directory separator character's discrepancy:

Compiling... done
Linking application installer...
Linking... started
D:\a\frescobaldi\frescobaldi\build\frescobaldi\windows\app\frescobaldi.wxs(79) : error LGHT0103 : The system cannot find the file 'src\app\frescobaldi\frescobaldi/icons/org.frescobaldi.Frescobaldi.ico'.
D:\a\frescobaldi\frescobaldi\build\frescobaldi\windows\app\frescobaldi.wxs(86) : error LGHT0103 : The system cannot find the file 'src\app\frescobaldi\frescobaldi/icons/org.frescobaldi.Frescobaldi.ico'.
Linking... errored

Unable to link app frescobaldi.
Saving log... started

Log saved to D:\a\frescobaldi\frescobaldi\logs\briefcase.2025_02_11-22_48_28.package.log

Saving log... done

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; a couple of comments inline about improvements to MIME and icon handling, plus one escaping issue.

@davidfokkema
Copy link
Contributor Author

@davidfokkema I did a quick test here and it's failing, apparently because of the directory separator character's discrepancy:

The directory separator was not the issue. Currently, the icon needs to be specified relative to the sources module, in your case 'frescobaldi'. This diff of pyproject.toml fixes the icon issue:

 [tool.briefcase.app.frescobaldi.document_type.ly]
 description = "LilyPond file"
 extension = "ly"
-icon = "frescobaldi/icons/org.frescobaldi.Frescobaldi"
+icon = "icons/org.frescobaldi.Frescobaldi"
 url = "https://lilypond.org/"

 [tool.briefcase.app.frescobaldi.document_type.ily]
 description = "LilyPond included file"
 extension = "ily"
-icon = "frescobaldi/icons/org.frescobaldi.Frescobaldi"
+icon = "icons/org.frescobaldi.Frescobaldi2"
 url = "https://lilypond.org/"

However, it complained that a GUID is reused. On a hunch, since my test repo uses two different icons for the two document types, I copied the icon and named it org.frescobaldi.Frescobaldi2 (see the diff above) and on my machine, it created a nice .msi. I will look into the GUID issue, maybe there is an easy fix but I guess it just won't work with the same icon since two "components" in the installer are re-using the same file. I think the icons really need to be different, which is not that unusual if you define different document types, but I understand why you reused the icon.

@davidfokkema
Copy link
Contributor Author

Mind that specifying the location of the icon this way will probably change after I implemented @freakboy3742's suggestions.

@davidfokkema
Copy link
Contributor Author

@fedelibre with the current changes to the template, copying the same icon into the build directory, there is no longer any need to change your briefcase.toml. So the run that failed, should succeed now unchanged.

@fedelibre
Copy link

Thanks, I've rerun the job and the build completed successfully. I'll test the .msi file on Windows when I have time.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - and works great in my testing as well. 2 comments inline, one of which comes with a fix that I'd like someone other than me to validate works - but if it does, I think this is good to go!

@davidfokkema
Copy link
Contributor Author

The mime_type fix works for me! Without that declaration I get application/x-appname-doctype and with the declaration I get the mime type that is specified in the pyproject.toml section. Thanks!

@davidfokkema
Copy link
Contributor Author

When this is merged, how would I best go about including it in the visualstudio template? As a single commit including the same changes by copying over the new files? Or somehow pulling in the different commits?

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - thanks for these fixes!

Regarding the VisualStudio analog - a single commit making this set of change on that repo would be great.

One final minor housekeeping note - I've tweaked the PR description slightly, because the text "Fixes #xxx on windows" contains the magic words "Fixes #X", which Github will use to close the referenced ticket - the human readable qualifier won't be taken into consideration. In this case the issue won't be completely fixed, so we need to use "Refs #xxx" instead.

@freakboy3742 freakboy3742 merged commit 7cf714c into beeware:main Feb 14, 2025
16 checks passed
@davidfokkema
Copy link
Contributor Author

One final minor housekeeping note - I've tweaked the PR description slightly, because the text "Fixes #xxx on windows" contains the magic words "Fixes #X", which Github will use to close the referenced ticket - the human readable qualifier won't be taken into consideration. In this case the issue won't be completely fixed, so we need to use "Refs #xxx" instead.

Darn, didn't think of that. Thanks for the housekeeping. And for accepting my PR, of course!

davidfokkema added a commit to davidfokkema/briefcase-windows-VisualStudio-template that referenced this pull request Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants