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

[v3] Support for File-Associations on macOS #4177

Merged

Conversation

wimaha
Copy link

@wimaha wimaha commented Mar 29, 2025

Description

Added support for file associations in macOS applications. This feature is supported by wails v2, so this PR is a port of the feature to wails v3. The groundwork has already been done, so this PR is very small. If necessary, it could also be classified as a bug fix, since the feature was already working for Windows and is documented in the docs.

Also added the ability to specify the mime type on macOS.

Fixes #4176

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

 Wails (v3.0.0-dev)  Wails Doctor 
                                                                                                                                                                          
# System 

┌──────────────────────────────────────────────────┐
| Name          | MacOS                            |
| Version       | 15.3.1                           |
| ID            | 24D70                            |
| Branding      | Sequoia                          |
| Platform      | darwin                           |
| Architecture  | arm64                            |
| Apple Silicon | true                             |
| CPU           | Apple M1 Pro                     |
| CPU 1         | Apple M1 Pro                     |
| CPU 2         | Apple M1 Pro                     |
| GPU           | 16 cores, Metal Support: Metal 3 |
| Memory        | 16 GB                            |
└──────────────────────────────────────────────────┘

# Build Environment 

┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-dev                               |
| Go Version   | go1.24.1                                 |
| Revision     | 8c3ee8f1bd9fd92df2f99773dec2a27871ebe611 |
| Modified     | false                                    |
| -buildmode   | exe                                      |
| -compiler    | gc                                       |
| CGO_CFLAGS   |                                          |
| CGO_CPPFLAGS |                                          |
| CGO_CXXFLAGS |                                          |
| CGO_ENABLED  | 1                                        |
| CGO_LDFLAGS  |                                          |
| GOARCH       | arm64                                    |
| GOARM64      | v8.0                                     |
| GOOS         | darwin                                   |
| vcs          | git                                      |
| vcs.modified | false                                    |
| vcs.revision | 8c3ee8f1bd9fd92df2f99773dec2a27871ebe611 |
| vcs.time     | 2025-03-29T20:06:53Z                     |
└─────────────────────────────────────────────────────────┘

# Dependencies 

┌────────────────────────────────────────────────────────────────────────┐
| Xcode cli tools | 2409                                                 |
| npm             | 10.9.2                                               |
| *NSIS           | Not Installed. Install with `brew install makensis`. |
|                                                                        |
└─────────────────────── * - Optional Dependency ────────────────────────┘

# Checking for issues 

 SUCCESS  No issues found

# Diagnosis 

 SUCCESS  Your system is ready for Wails development!

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features

    • Introduced file association support for macOS, now allowing MIME type specification for files.
  • Documentation

    • Enhanced guides and configuration instructions to help users set up file associations on macOS, including examples for MIME types and asset management.

Copy link
Contributor

coderabbitai bot commented Mar 29, 2025

Walkthrough

This pull request adds support for file associations on macOS. It updates the changelog and documentation with a new entry and guide instructions, adds a new mimeType property to both the configuration and the internal code structure, and modifies the macOS plist templates to include conditional blocks for handling file associations with MIME type details.

Changes

File(s) Change Summary
docs/src/content/docs/changelog.mdx, docs/src/content/docs/guides/file-associations.mdx Added a changelog entry for "File Association support for mac" and updated the guide to include a new mimeType property and additional macOS setup instructions.
v3/internal/commands/build-assets.go, v3/internal/commands/build_assets/config.yml Introduced a new MimeType field in the FileAssociation struct and added an optional mimeType configuration property.
v3/.../Info.dev.plist.tmpl, v3/.../Info.plist.tmpl Added a conditional block for file associations that creates a CFBundleDocumentTypes array with entries for document types, including optional MIME type support.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BuildProcess
    participant ConfigLoader
    participant PlistBuilder

    User->>BuildProcess: Initiate build
    BuildProcess->>ConfigLoader: Load file associations config
    ConfigLoader-->>BuildProcess: Return file associations (including mimeType)
    BuildProcess->>PlistBuilder: Generate Info.plist with file association block
    PlistBuilder-->>BuildProcess: Return updated plist with CFBundleDocumentTypes
    BuildProcess-->>User: Build output with macOS file associations support
Loading

Assessment against linked issues

Objective Addressed Explanation
[v3] File-Associations on macOS not working (#4176)

Possibly related issues

Possibly related PRs

Suggested labels

TODO

Suggested reviewers

  • leaanthony

Poem

I'm a bunny with coding flair,
Hopping through macOS files with care.
MIME types and icons now unite,
In plist templates shining bright.
Celebrate the code with a joyful hop and a byte!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@wimaha wimaha marked this pull request as ready for review March 29, 2025 20:42
@wimaha wimaha changed the title Support for File-Associations on macOS [v3] Support for File-Associations on macOS Mar 29, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
docs/src/content/docs/guides/file-associations.mdx (1)

109-110: Helpful macOS-specific instruction

Good addition of macOS-specific instructions for document icons. Consider adding a note about where to create or obtain the documenticon.icns file for new users.

v3/internal/commands/updatable_build_assets/darwin/Info.plist.tmpl (1)

26-48: Well-implemented file association support for macOS

The new conditional block correctly implements file associations for macOS applications following Apple's standards for Info.plist configuration. The structure properly handles:

  • Conditional inclusion based on presence of file associations
  • Multiple file type registration through template iteration
  • Optional MIME type specification

Consider adding support for LSHandlerRank to give applications more control over their priority when handling specific file types. This is useful when multiple applications can handle the same file type. Example implementation:

                {{- if .MimeType}}
                <key>CFBundleTypeMimeType</key>
                    <string>{{.MimeType}}</string>
                {{- end}}
+               {{- if .HandlerRank}}
+               <key>LSHandlerRank</key>
+                   <string>{{.HandlerRank}}</string>
+               {{- end}}
v3/internal/commands/updatable_build_assets/darwin/Info.dev.plist.tmpl (1)

26-48: Well-implemented file association support for macOS development environment

The new conditional block correctly implements file associations for macOS applications in the development environment. The implementation maintains consistency with the production plist template while correctly preserving the development-specific network security settings.

For consistency with the production template, consider adding support for LSHandlerRank to give applications more control over their priority when handling specific file types:

                {{- if .MimeType}}
                <key>CFBundleTypeMimeType</key>
                    <string>{{.MimeType}}</string>
                {{- end}}
+               {{- if .HandlerRank}}
+               <key>LSHandlerRank</key>
+                   <string>{{.HandlerRank}}</string>
+               {{- end}}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a2dc28 and 5f8a858.

📒 Files selected for processing (6)
  • docs/src/content/docs/changelog.mdx (1 hunks)
  • docs/src/content/docs/guides/file-associations.mdx (2 hunks)
  • v3/internal/commands/build-assets.go (2 hunks)
  • v3/internal/commands/build_assets/config.yml (1 hunks)
  • v3/internal/commands/updatable_build_assets/darwin/Info.dev.plist.tmpl (1 hunks)
  • v3/internal/commands/updatable_build_assets/darwin/Info.plist.tmpl (1 hunks)
🔇 Additional comments (7)
v3/internal/commands/build_assets/config.yml (1)

59-59: Good addition of the optional MIME type field

This addition properly documents the new mimeType optional field for file associations, providing a clear example with image/jpeg. The comment clarifying it's optional is helpful for users.

docs/src/content/docs/changelog.mdx (1)

79-79: Well-formatted changelog entry

The changelog entry for macOS file association support is correctly formatted with the macOS icon prefix and includes proper attribution to the contributor with a link to the PR.

docs/src/content/docs/guides/file-associations.mdx (1)

65-65: Good documentation for the new MIME type property

Clear and concise documentation of the new mimeType property in the configuration properties table, with a practical example and platform specification.

v3/internal/commands/build-assets.go (2)

13-15: Clean import organization

The reordering of imports improves code readability by grouping standard library imports separately from third-party imports.


125-125: Core implementation of MIME type support

The addition of the MimeType field to the FileAssociation struct is well-implemented with the proper YAML tag. This change enables storing and processing MIME type information from the configuration files.

v3/internal/commands/updatable_build_assets/darwin/Info.plist.tmpl (1)

5-25: Improved indentation enhances readability

The indentation changes make the XML structure more readable while preserving the original functionality.

v3/internal/commands/updatable_build_assets/darwin/Info.dev.plist.tmpl (1)

5-25: Improved indentation enhances readability

The indentation changes make the XML structure more readable while preserving the original functionality.

@leaanthony leaanthony merged commit bd74170 into wailsapp:v3-alpha Apr 9, 2025
3 of 4 checks passed
@leaanthony
Copy link
Member

Thanks so much! 🙏

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.

2 participants