Integrating Protocol Requests (Deeplinks) cover image

Launcher SDK

Integrating Protocol Requests (Deeplinks)

Integrating Protocol Requests (Deeplinks) in PatchKit Launcher SDK

Protocol requests, often referred to as deeplinks, enable external applications or websites to trigger specific actions in your application via custom URL schemes. They act as a bridge between systems, making it easier to integrate functionalities across platforms.

How Do They Work?

  1. Protocol Registration: The application registers itself as a handler for a specific protocol (e.g., my-app://).
  2. Request Handling: The application processes protocol requests, such as my-app://do-action.
  3. Triggering Requests: External sources, such as websites or other apps, invoke these requests. For example, a “Download” button on a game’s webpage might link to my-app://download-game?id=123.

Example of a Protocol Request in Chrome Browser:
Protocol Request Example

Configuring Protocol Support in PatchKit Launcher SDK

Adding protocol support to your launcher in the PatchKit SDK is straightforward. All you need is to configure the protocol field in your preset.

Example Configuration

// ...
protocol: {
  id: "patchkit-demo-launcher"
}
// ...

Testing Protocol Support

To confirm the setup:

  1. Start your launcher in development mode.
  2. Trigger a protocol request, such as patchkit-demo-launcher://test.
  3. Ensure the launcher opens and focuses as expected.

Customization Options:

Note: Updating the protocol field requires publishing a new version of your runtime to deploy changes.


Handling Protocol Requests in React Themes

The @upsoft/patchkit-launcher-runtime-api-react-theme-extras package simplifies handling protocol requests in React.

Using the useProtocolPendingRequestListener Hook

The useProtocolPendingRequestListener hook listens for incoming protocol requests and allows you to define how they’re handled.

Here’s an example implementation:

import { startAppBranchProcess } from "@upsoft/patchkit-launcher-runtime-api-react-theme-client";
import { useProtocolPendingRequestListener } from "@upsoft/patchkit-launcher-runtime-api-react-theme-extras";
import { useCallback } from "react";

export function App() {
  useProtocolPendingRequestListener(
    useCallback(async ({ protocolPendingRequestController }) => {
      const url = protocolPendingRequestController.url;

      if (url.includes("://start-app-branch-process")) {
        await protocolPendingRequestController.dismiss();
        
        const urlObject = new URL(url);
        const appId = urlObject.searchParams.get("appId");
        const appBranchId = urlObject.searchParams.get("appBranchId");

        if (appId && appBranchId) {
          await startAppBranchProcess({ appId, appBranchId });
        }
      }
    }, [])
  );

  // Component rendering logic...
}

Best Practices:

  • Place the hook in a top-level component like <App> or context providers to ensure it remains active.

Handling Protocol Requests in Non-React Themes

For non-React themes, the @upsoft/patchkit-launcher-runtime-api-theme-client package provides two core functions:

Refer to the API documentation for detailed usage examples.


Summary

Protocol requests (deeplinks) offer a powerful way to integrate your PatchKit launcher with other systems. They allow you to create seamless workflows between websites, applications, and the launcher. Whether you’re working in React or a custom theme, PatchKit provides the tools you need to handle protocol requests effectively.

Key Takeaways:

Get started by enabling protocol support and experimenting with deeplinks today!