Skip to content

Commit

Permalink
Updated documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkol authored and Stelzi79 committed Oct 27, 2020
1 parent e73506c commit 8298341
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 2 deletions.
77 changes: 76 additions & 1 deletion Documents/commands.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@

# Commands

work in progress
There are two ways to communicate between Renderer and Browser.
- Action route
- Command route

An action route, is the normal way to do IPC. There is a request and a response. For more info on normal "action route" please see [Registering Custom Scheme Handlers](https://github.com/chromelyapps/Chromely/blob/master/Documents/registering_scheme_handlers.md). The second option is to use commands. Commands are fire-and-forget. There is a request but no response returned to the originating method.

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

### Register URl Scheme
A command scheme can be registered in config file or configuration object.

- Using config file

````javascript
"urlSchemes": [
{
"name": "default-command-http",
"baseUrl": "",
"scheme": "http",
"host": "command.com",
"urlSchemeType": "command",
"baseUrlStrict": false
}
]
````
- Using C# code

````csharp
public class DefaultConfiguration : IChromelyConfiguration
{
public DefaultConfiguration()
{
UrlSchemes.AddRange(new List<UrlScheme>()
{
new UrlScheme("default-command-http", "http", "command.com", string.Empty UrlSchemeType.Command, false),
});

}
}
````

### Add Command Methods To Controller

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

- Constructor type
````csharp
public DemoController()
{
RegisterCommand("/democontroller/showdevtools", ShowDevTools);
}

public void ShowDevTools(IDictionary<string, string> queryParameters)
{
}

````

- Attribute decorated type
````csharp

[Command(Route = "/democontroller/showdevtools")]
public void ShowDevTools(IDictionary<string, string> queryParameters)
{
}
````

### Create a JavaScript request in the Renderer html

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

A sample:

````html
<a href="http://command.com/democontroller/showdevtools">Show DevTools</a>
````
87 changes: 86 additions & 1 deletion Documents/loading_html.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,89 @@

# Loading Html

work in progress
Chromely html loading (start url) can be done in [3 different](https://github.com/chromelyapps/Chromely/blob/5086087dfc03d27cbd84699359cd4891024cfcd1/src/Chromely.Core/Helpers/ConfigKeys.cs#L3) ways.

- A real website URL
- Local Resource Loading
- File Protocol

## A Real Website URL

This will launch actual website URL. This may not necessarily be commonly used as Chromely is focused on loading local HTML5 files for Single Page Applications (SPAs). This URL should also be of scheme and domain combination that is not registered as external URL scheme.

If the URL is pre-regisered as an external url scheme type, the URL will be opened by the OS default browser. Please see more info at [Registering Url Schemes](https://github.com/chromelyapps/Chromely/blob/master/Documents/registering_url_schemes.md).

To load start url and its assets, you can do it either in config file or configuration object:

````javascript
"startUrl": {
"url": "https://google.com",
"loadType": "absolute"
}
````

````csharp
public class DefaultConfiguration : IChromelyConfiguration
{
public DefaultConfiguration()
{
StartUrl = "https://google.com";
}
}
````

## Local Resource Loading

This is the preferred way of loading local HTML5 files.

Loading html and associated files via LocalResource needs a custom resource scheme handler. For more info on scheme handling, please see [Registering Resource Handlers](https://github.com/chromelyapps/Chromely/blob/master/Documents/registering_resource_handlers.md).

To load start url and its assets, you can do it either in config file or configuration object:

````javascript
"startUrl": {
"url": "local://app/chromely.html",
"loadType": "localResource"
}
````

````csharp
public class DefaultConfiguration : IChromelyConfiguration
{
public DefaultConfiguration()
{
StartUrl = "local://app/chromely.html";
}
}

````

## File Protocol

Local HTML5 files can also be loaded using file protocol (**file:///**). Using file protocol (**file:///**) is discouraged for security reasons. One issue might be Cross-Origin domain. Although not the preferred way, it is useful if HTML/Ajax XHR requests are required.

To load start url and its assets, you can do it either in config file or configuration object:

````javascript
"startUrl": {
"url": "app/chromely.html",
"loadType": "fileprotocol"
}
````

````csharp
public class DefaultConfiguration : IChromelyConfiguration
{
public DefaultConfiguration()
{
var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
var startUrl = $"file:///{appDirectory}app/chromely.html";
StartUrl = startUrl;
}
}

````

Notes:
- Folder "app" is a physical folder in the executable folder. Usually this is the primary folder for all html and associated files. Sample - [app folder](https://github.com/chromelyapps/demo-projects/tree/master/regular-chromely/CrossPlatDemo/app). Usually all files in this folder are copied to executable (bin) folder.
- For Angular/React/Vue this is usually the "dist" folder. So the start url usually is [local://dist/index.html](https://github.com/chromelyapps/demo-projects/blob/98732be68154623dd9d7977cf6cbe29e2eed82a0/angular-react-vue/ChromelyAngular/chromelyconfig.json#L4). The "dist" folder is where Webpack, Parcel and other bundlers publish the bundled (end product) for browsers consumption.

0 comments on commit 8298341

Please sign in to comment.