gioui-plugins / gio-plugins

Gio-Plugins offers new plugins to extend and enhance your Gio app. Inspired by flutter/plugins repository,
Other
55 stars 6 forks source link

universal links setup with deeplinks #54

Open gedw99 opened 1 year ago

gedw99 commented 1 year ago

Deeplinks are great. We could also make it work with Universal Links.

What are universal links?

Universal links are web links which point to some content on the web and in your app. Universal links are different from deeplink as they are pure web links where as deeplinks will always start with yourAppScheme:// and open the app.

Shared web credentials, universal links, Handoff, and App Clips all use associated domains via the Universal links concept.

https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content

And extra info here:

https://developer.apple.com/documentation/xcode/supporting-associated-domains


This is a very good walk through of how to set it setup and working.

https://nishbhasin.medium.com/apple-universal-link-setup-in-ios-131a508b45d1

Summary of steps and GIO aspects....

  1. Apple Permissions.

URL: https://developer.apple.com/account/resources/identifiers/list


  1. Web Server
# Tool for making Certs be trusted locally.
# https://github.com/FiloSottile/mkcert
go install filippo.io/mkcert@latest

# Web Server
# https://github.com/caddyserver/caddy
go install github.com/caddyserver/caddy/v2/cmd/caddy@v2.6.4

Now you need a CaddyFIle. You can run a Static or Reverse proxy. both work.

{
    # globals
    debug
    log {
        output file .data/caddy/main.log {
            roll_size 1gb
            roll_keep 1
            roll_keep_for 720h
        }
    }
}

# https://www.[INSERT-YOUR-DOMAIN-URL]/
deeplink.localhost:443 {
    root * {system.wd}/demo/deeplink-demo/deeplink.web
    encode gzip
    try_files {path} /index.html
    file_server
}

# https://test.[INSERT-YOUR-DOMAIN-URL]/
test.localhost:443 {
    reverse_proxy 127.0.0.1:8080
}

Now we run it:


# Chang to where you will run the web server 

# Gen the certs and pem to disk:
mkcert -install
mkcert [INSERT-YOUR-DOMAIN-URL]

# run the caddy web server. It will look for the Caddyfile and Certs.
caddy run
{
    "applinks": {
        "details": [
             {
               "appIDs": [ "[INSERT-YOUR-DOMAIN-URL].app", "[INSERT-YOUR-DOMAIN-URL].app2" ],
               "components": [
                 {
                    "#": "no_universal_links",
                    "exclude": true,
                    "comment": "Matches any URL with a fragment that equals no_universal_links and instructs the system not to open it as a universal link."
                 },
                 {
                    "/": "/buy/*",
                    "comment": "Matches any URL with a path that starts with /buy/."
                 },
                 {
                    "/": "/help/website/*",
                    "exclude": true,
                    "comment": "Matches any URL with a path that starts with /help/website/ and instructs the system not to open it as a universal link."
                 },
                 {
                    "/": "/help/*",
                    "?": { "articleNumber": "????" },
                    "comment": "Matches any URL with a path that starts with /help/ and that has a query item with name 'articleNumber' and a value of exactly four characters."
                 }
               ]
             }
         ]
     },
     "webcredentials": {
        "apps": [ "[INSERT-YOUR-DOMAIN-URL].app" ]
     },

      "appclips": {
          "apps": ["[INSERT-YOUR-DOMAIN-URL].MyApp.Clip"]
      }
  }
  1. Plist inside app:
<key>com.apple.developer.associated-domains</key>
<array>
    <string>applinks:[INSERT-YOUR-DOMAIN-URL]</string>
</array>
inkeliz commented 1 year ago

I want to add support for Universal Link, but I didn't include that in the same patch, to keep it simple.

Fun fact, Windows also supports it: https://learn.microsoft.com/en-us/windows/uwp/launch-resume/web-to-app-linking. But, gio is Win32, and not UWP. Far I know, Golang can't compile to UWP (https://github.com/golang/go/issues/21805), but I'm not sure if that issue still valid. However, sometimes it's possible to call UWP functions from Win32, that is the case in "Share-Dialog", for instance. I found that exists one functions that adds an URL at runtime (https://learn.microsoft.com/en-us/uwp/api/windows.system.appurihandlerregistration.setappaddedhostsasync?view=winrt-22621), and here we have the IDL (https://github.com/ojdkbuild/tools_toolchain_sdk10_17763/blob/a647d1194cd10afdaa52f8056db239b7598fe1dd/Include/10.0.17763.0/winrt/windows.system.idl#L1203-L1212). Since it's a COM API, I'm not sure if it will be approved in Gio, that is very messy. But, I'm a little bit curious to see if that works. :P