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

Implement custom protocol association support #3000

Merged
merged 78 commits into from
Nov 2, 2023

Conversation

APshenkin
Copy link
Contributor

@APshenkin APshenkin commented Oct 23, 2023

Description

Implements custom protocol association support for macOS/Windows. This will allow connect web apps with desktop apps builded with Wails

Users can specify list of custom protocols in wails.json config with following params

"scheme": :"Custom Protocol scheme. e.g. myapp"
"description": "Windows-only. The description."
"role": "macOS-only. The app’s role with respect to the type. Corresponds to CFBundleTypeRole."

Few comments regarding implementation
MacOS: Darwin handle opening file by raising handleGetURLEvent event. Callback is added for app configuration to handle this correctly.
Windows: On Windows protocols association is done via NSIS installer. So apps should be distributed with it to have this feature.
When custom protocol URL is opened, Windows launches new instance of the app and pass url as argument. So apps developers should parse args and handle situation properly.
Linux: To setup association changes on client system should be done. As wails doesn't support bundling for linux now, nothing was added in this PR for it, but in test repo that is provided below you can see how this can be done using nfmp. Also this is added in guides.

You can see how it works here.

  • Windows
  • MacOs
  • Linux – NOTE THIS IS NOT PART OF PR AS WAILS DOESN'T SUPPORT BUNDLING FOR LINUX. But it can be done manually using bundling (docs added for this)

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • 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?

Test repo is available here https://github.com/APshenkin/wails-open-file/tree/feature/deeplinks
PR should be fetched and replace in go.mod should be adjusted

  • Windows
  • macOS
  • Linux

Test Configuration

# Wails
Version  | v2.6.0
Revision | a419721dcdf16da7a4afd92b9ba63b2050229a26
Modified | true

# System
┌─────────────────────────┐
| OS           | MacOS    |
| Version      | 13.5.2   |
| ID           | 22G91    |
| Go Version   | go1.20.2 |
| Platform     | darwin   |
| Architecture | arm64    |
└─────────────────────────┘


# System
┌────────────────────────────────────┐
| OS           | Windows 10 Pro      |
| Version      | 2009 (Build: 22621) |
| ID           | 22H2                |
| Go Version   | go1.21.1            |
| Platform     | windows             |
| Architecture | arm64               |
└────────────────────────────────────┘                         

# System
┌────────────────────────────────────┐
| OS           | Ubuntu              |
| Version      | 22.04               |
| ID           | ubuntu              |
| Go Version   | go1.21.1            |
| Platform     | linux               |
| Architecture | arm64               |
└────────────────────────────────────┘

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

@APshenkin APshenkin marked this pull request as ready for review October 23, 2023 11:42
@APshenkin
Copy link
Contributor Author

APshenkin commented Oct 23, 2023

@leaanthony @stffabi please take a look on this too 😊

This feature will be really handy in case when devs have web app and want to open desktop app builded with Wails in some cases

@APshenkin
Copy link
Contributor Author

@leaanthony sorry for ping you, just want to check if you saw this PR :)

@leaanthony
Copy link
Member

Sorry, I've not been feeling too good so haven't been in the right headspace for this. Others can take a look in the meantime

@APshenkin
Copy link
Contributor Author

@leaanthony @stffabi
Just kind reminder about this 🙂

@leaanthony
Copy link
Member

I'm good with this PR. Thanks so much for spending the time doing it and your patience. I'll just give @stffabi a couple of days to look at it and we'll get it in. Thanks again 🙏

@annismckenzie
Copy link

Would this be available in a 2.x release when it's merged? 😅

Copy link
Collaborator

@stffabi stffabi left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Thanks so much for this awesome PR @APshenkin and taking the time to do this 🙏 .

@stffabi
Copy link
Collaborator

stffabi commented Nov 2, 2023

Would this be available in a 2.x release when it's merged? 😅

Yes, this PR is targeting v2.

@leaanthony leaanthony merged commit ae688aa into wailsapp:master Nov 2, 2023
10 of 12 checks passed
@leaanthony
Copy link
Member

Thanks again @APshenkin! You're filling my v3 backlog by stealth 😅

@APshenkin
Copy link
Contributor Author

APshenkin commented Nov 2, 2023

@leaanthony I'm really excited about Wails (and its V3 as well) and planing to do some app with it 🙂
Just cause v3 is still in active development – wanted to speed up things that are critical for me.

Maybe will introduce some more PRs if will need some features in Wails more 😊

@bilalk1
Copy link

bilalk1 commented Dec 1, 2023

Hello! @APshenkin
I have cloned your PR and go.mod adjusted
My go.mod file

module changeme

go 1.21

toolchain go1.21.4

require github.com/wailsapp/wails/v2 v2.6.0

require (
	github.com/bep/debounce v1.2.1 // indirect
	github.com/go-ole/go-ole v1.2.6 // indirect
	github.com/godbus/dbus/v5 v5.1.0 // indirect
	github.com/google/uuid v1.3.0 // indirect
	github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
	github.com/labstack/echo/v4 v4.10.2 // indirect
	github.com/labstack/gommon v0.4.0 // indirect
	github.com/leaanthony/go-ansi-parser v1.6.0 // indirect
	github.com/leaanthony/gosod v1.0.3 // indirect
	github.com/leaanthony/slicer v1.6.0 // indirect
	github.com/leaanthony/u v1.1.0 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.19 // indirect
	github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/rivo/uniseg v0.4.4 // indirect
	github.com/samber/lo v1.38.1 // indirect
	github.com/tkrajina/go-reflector v0.5.6 // indirect
	github.com/valyala/bytebufferpool v1.0.0 // indirect
	github.com/valyala/fasttemplate v1.2.2 // indirect
	github.com/wailsapp/go-webview2 v1.0.10 // indirect
	github.com/wailsapp/mimetype v1.4.1 // indirect
	golang.org/x/crypto v0.14.0 // indirect
	golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
	golang.org/x/net v0.17.0 // indirect
	golang.org/x/sys v0.13.0 // indirect
	golang.org/x/text v0.13.0 // indirect
)

replace github.com/wailsapp/wails/v2 v2.6.0 => /Users/mac/Desktop/wails-open-file/wails/v2

I have replaced the local wails.

Getting this error while building the project


# Building target: darwin/amd64

  • Generating bindings: Done.
  • Installing frontend dependencies: Done.
  • Compiling frontend: Done.
  • Compiling application: Done.
  • Packaging application:   ERROR   Unable to resolve data in darwin/Info.plist: template: :26:18: executing "" at <.Info.FileAssociations>: can't evaluate field FileAssociations in type project.Info

  ERROR   Unable to resolve data in darwin/Info.plist: template: :26:18: executing "" at <.Info.FileAssociations>: can't evaluate field FileAssociations in type project.Info
Screenshot 2023-12-01 at 3 28 34 PM

@byteams
Copy link

byteams commented Mar 28, 2024

Hi folks, I'm unable to get this to work on a mac. Tried open("customapp://localhost:port/path") like in the vid but it complains that there is no registered scheme handler for customapp://. Is there any plan to update the documentations on how to achieve this?

@leaanthony
Copy link
Member

@byteams - thanks for reporting this. Perhaps it's best to open a new issue rather than an old PR. Might also be worth mentioning @APshenkin to see if he's still around.

@byteams
Copy link

byteams commented Mar 29, 2024

@leaanthony gotcha ok. Let me create a new issue this weekend. Thanks btw for this awesome project.

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.

6 participants