Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Command Routes

Robin Gabriël edited this page Jan 24, 2020 · 1 revision

Commands are fire-and-forget JavaScript requests that are sent from the Renderer and processed by the Browser. As you might already have guessed, no response is returned to the Renderer.

A command must be registered and requires a URL scheme registarion and a related action method.

The configuration of an IPC workflow involves:

  1. Create a Controller class
  2. Register an Command method in the Controller class*
  3. Register the Controller class
  4. Register a scheme (http, custom, etc)*
  5. Create a JavaScript request in the Renderer html*

[*] We are only covering these parts of the workflow, to get the full picture please look at the Networking Introduction

Command methods can be added to Controller class in 2 ways.

  • Constructor type
public DemoController()
{
	RegisterCommand("/democontroller/exitprogram", ShowDevTools);
}

public void ExitProgram()
{
}
  • Attribute decorated type
 [Command(Route = "/democontroller/exitprogram")]
public void ExitProgram()
{
}

You can register a command scheme either in config file or via C# code.

  • Using config file
"urlSchemes": [
    {
      "name": "default-command-http",
      "baseUrl": "",
      "scheme": "http",
      "host": "command.com",
      "urlSchemeType": "command",
      "baseUrlStrict": false
    }
]
  • Using C# code
public class DefaultConfiguration : IChromelyConfiguration
{
    public DefaultConfiguration()
    {
        UrlSchemes.AddRange(new List<UrlScheme>()
        {
            new UrlScheme("default-command-http", "http", "command.com", string.Empty, UrlSchemeType.Command, false),
        });
        
    }
}

For more info on registering a custom scheme please see Custom Http Registration.

To trigger an actual request, an event must must be set up in the HTML file.

A sample:

<a href="http://command.com/democontroller/exitprogram">Close App</a>