wails icon indicating copy to clipboard operation
wails copied to clipboard

V3 Deep-link (Port of v2 feature)

Open atterpac opened this issue 5 months ago • 2 comments

This is a loose port of the v2 Custom Protocol Association feature initially introduced in #3000

There are some modification to how a user will use the API but the logic of gathering it is fairly similar

A unified Golang API for it is provided to the user regardless of OS as opposed to the v2 solution

app.OnApplicationEvent(events.Common.ApplicationLaunchedWithUrl, func(e *application.ApplicationEvent) {
   launchedURL := e.Context().URL() // Retrieve the URL from the event context
   log.Printf("Application launched with URL: %s", launchedURL)
})

I have tested on macOS but will need assistance to confirm/troubleshoot other OS, will include my hardware details below

Setting up custom protocol

Configuring the custom protocol is set inside the wails config file

{
 "name": "My App",
 "description": "An amazing Wails app!",
 "info": {
   "companyName": "My Company",
   "productName": "My Product",
   "protocols": [
     {
       "scheme": "myapp",
       "description": "My Application Custom Protocol"
     },
     {
       "scheme": "anotherprotocol",
       "description": "Another protocol for specific actions"
     }
   ]
 }
}

How it works

The config file will take care of most of the setup for you you will need to run task common:update:build-assets once updating your config file for the changes to take place

In all OS you will need a task package build in order for the custom protocol to work.

MacOS

Values are taken from the config file to populate the correct fields inside the plist

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>My Application Custom Protocol</string> <!-- From Protocol.Description in wails.json -->
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myapp</string> <!-- From Protocol.Scheme in wails.json -->
            </array>
        </dict>
    </array>

Windows

**Requires an NSIS install step and makensis ** Windows will add the URL as an argument to the launch args, wails checks this on start up any launch args match your deep link protocol if so the application event is emitted saving you from having to parse and determine yourself.

Linux

Requires an install step

Linux is setup to configure your deep-link via nfpm and a .desktop file, on install the post-install.sh script will update the device database and MIME types to allow for deep linking.

Linux works similar to windows as it passes the url as an argument to the launch. Wails handles is the same way to populate the application event

Hardware details

 Wails (v3.0.0-dev)  Wails Doctor

# System

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

# Build Environment

┌─────────────────────────────────────────────────────────┐
| Wails CLI    | v3.0.0-dev                               |
| Go Version   | go1.24.1                                 |
| Revision     | 3716acaae4dc0bb6407a7d0a772b32d8509be6d0 |
| Modified     | true                                     |
| -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 | true                                     |
| vcs.revision | 3716acaae4dc0bb6407a7d0a772b32d8509be6d0 |
| vcs.time     | 2025-05-14T20:35:41Z                     |
└─────────────────────────────────────────────────────────┘

Summary by CodeRabbit

  • New Features

    • Added comprehensive support for custom protocol schemes (deep linking) across macOS, Windows, and Linux, enabling applications to handle custom URLs.
    • Introduced a new example project demonstrating custom protocol handling, including frontend and backend integration.
    • Applications now emit events when launched via custom URLs, allowing frontend components to respond accordingly.
  • Documentation

    • Added detailed guides and README documentation explaining how to configure and use custom protocol schemes in Wails applications.
  • Chores

    • Added configuration files, build scripts, and templates to support packaging, installation, and protocol registration on all major platforms.

atterpac avatar May 18 '25 21:05 atterpac

Walkthrough

This change introduces comprehensive support for custom protocol schemes (deep linking) in Wails applications across macOS, Windows, and Linux. It includes new documentation, example projects, configuration files, build scripts, and runtime logic. The update adds event types, context handling, and platform-specific implementations to enable applications to register and respond to custom URL schemes, emitting events to the frontend when launched via a registered protocol.

Changes

Files/Paths Change Summary
docs/src/content/docs/guides/custom-protocol-association.mdx Added a detailed guide for implementing custom protocol schemes (deep linking) in Wails apps across all major platforms.
v3/examples/custom-protocol-example/* (README.md, .gitignore, Taskfile.yml, greetservice.go, main.go, etc.) Introduced a new example project demonstrating custom protocol usage, including Go backend, frontend assets, build scripts, configuration, and documentation.
v3/examples/custom-protocol-example/build/* (darwin, linux, windows, config.yml, etc.) Added cross-platform build and packaging scripts, configuration files, Info.plist templates, NSIS installer scripts, and Linux packaging support for the example.
v3/examples/custom-protocol-example/frontend/* (index.html, src/*, package.json, .gitignore, etc.) Added frontend implementation for the example, including event handling for URLs, UI, CSS, and generated JS bindings.
v3/internal/commands/build-assets.go Added ProtocolConfig struct and integrated protocol support into build/update config structs and asset update logic.
v3/internal/commands/build_assets/linux/nfpm/scripts/postinstall.sh Replaced empty script with logic to update desktop and MIME databases post-installation, with error handling.
v3/internal/commands/updatable_build_assets/darwin/Info.dev.plist.tmpl, Info.plist.tmpl Updated Info.plist templates to conditionally include custom URL scheme declarations based on provided protocols.
v3/internal/commands/updatable_build_assets/linux/desktop.tmpl Added a Linux desktop entry template supporting protocol MIME type handlers.
v3/internal/commands/updatable_build_assets/linux/nfpm/nfpm.yaml.tmpl Activated postinstall script in nfpm YAML template for Linux packaging.
v3/internal/runtime/desktop/@wailsio/runtime/src/event_types.ts Added new event type constant ApplicationLaunchedWithUrl to the Common event category.
v3/pkg/application/application_darwin.go, application_darwin_delegate.h, application_darwin_delegate.m Added macOS support for handling custom protocol Apple Events, including new handler class, initialization, and event emission.
v3/pkg/application/application_linux.go Extended Linux app to detect and handle custom protocol URLs from command-line arguments, emitting launch events.
v3/pkg/application/application_windows.go Enhanced Windows app to detect and handle custom protocol URLs from command-line arguments, emitting launch events.
v3/pkg/application/context_application_event.go Added/renamed constants and methods to support URL context in application events, including getter/setter for URL.
v3/pkg/events/events.txt, events.go Added new event identifier and struct field for ApplicationLaunchedWithUrl; incremented event IDs accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant OS as Operating System
    participant App as Wails Application
    participant Backend as Go Backend
    participant Frontend as JS Frontend

    OS->>App: Launch via custom URL (e.g., myapp://...)
    App->>Backend: Emit ApplicationLaunchedWithUrl event with URL context
    Backend->>Frontend: Emit frontend event (e.g., "ShowURL") with URL data
    Frontend->>Frontend: Display or process received URL

Poem

🐇
A protocol hops through the door,
With URLs it brings to explore.
Mac, Windows, and Linux in sync,
Now apps can respond in a blink!
Events and handlers, all in a row—
Deep linking magic, ready to go.
Let’s celebrate with a joyful wink!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 810dfbb11beff9fc7eee1df33451a3aa78b3e6ed and 101b09676d7eb2cd36fd96ee20ac88574b1e17f1.

📒 Files selected for processing (2)
  • v3/internal/runtime/desktop/@wailsio/runtime/src/event_types.ts (1 hunks)
  • v3/pkg/events/events.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • v3/pkg/events/events.txt
  • v3/internal/runtime/desktop/@wailsio/runtime/src/event_types.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)
  • GitHub Check: semgrep-cloud-platform/scan
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

coderabbitai[bot] avatar May 18 '25 21:05 coderabbitai[bot]

Thanks @atterpac 🎉

leaanthony avatar Jul 23 '25 21:07 leaanthony