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

Configuration

Fiahblade edited this page Jan 24, 2020 · 39 revisions

By default Chromely comes with its own default configuration. Which can be completely altered or overridden depending on your needs and preferences. There are a few ways how you can configure Chromely.

The default values will be used.

Chromely checks the application folder for a chromelyconfig.config file. It's parsed using the ConfigurationHandler.

The Chromely config is equivalent to Desktop App.config or Web project Web.config/appsettings.config.

{
  "appName": "chromely_demo",
  "startUrl": {
    "url": "local://app/chromely.html",
    "loadType": "localResource"
  },
  "loadCefBinariesIfNotFound": true,
  "silentCefBinariesLoading": false,
  "windowLeft": 0,
  "windowTop": 0,
  "windowWidth": 1200,
  "windowHeight": 900,
  "windowNoResize": false,
  "windowNoMinMaxBoxes": false,
  "windowFrameless": false,
  "windowCenterScreen": true,
  "windowKioskMode": false,
  "windowState": "normal",
  "windowTitle": "chromely",
  "windowIconFile": "chromely.ico",
  "debuggingMode": true,
  "windowCustomCreation": {
    "windowStyles": 0,
    "windowExStyles": 0,
    "useCustomtyle": false
  },
  "urlSchemes": [
    {
      "name": "default-resource",
      "baseUrl": "",
      "scheme": "local",
      "host": "",
      "urlSchemeType": "resource",
      "baseUrlStrict": false
    },
    ...
}

A complete example of the chromelyconfig.json file.

This is by far the easiest way to configure Chromely.

using Chromely.Core;
using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class Program
    {
        static void Main(string[] args)
        {
            // create a configuration with OS-specific defaults
            var config = DefaultConfiguration.CreateForRuntimePlatform();

            // your configuration
            config.StartUrl = "https://chromely.net/";
            config.WindowOptions.Title = "My Awesome Chromely App!";
            //..

            // application builder
            AppBuilder
            .Create()
            .UseApp<DemoChromelyApp>()
            .UseConfiguration<IChromelyConfiguration>(config)
            .Build()
            .Run(args);
        }
    }
}

If you want complete control or want to work from a blank slate, with your own default settings. Implementing a custom Configuration class is your best option.

Create a new class that inherits from IChromelyConfiguration.

using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class MyConfiguration : IChromelyConfiguration
    {
    }
}

After implementing the interface, the class will look something like this.

using Chromely.Core;
using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class MyConfiguration : IChromelyConfiguration
    {
        public string AppName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
        public ChromelyPlatform Platform { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
        //..
    }
}

You can now add your own values to each property.

Understand that Chromely can't work without any defined settings, you will need to provide them. It might be useful to look at the default values that Chromely uses. Chromely.Core/Configuration/DefaultConfiguration.cs

using Chromely.Core;
using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class MyConfiguration : IChromelyConfiguration
    {
        public string AppName { get; set; };
        public ChromelyPlatform Platform { get; set; }
        //..

        public MyConfiguration()
        {
            AppName = "My Awesome Chromely App";
            Platform = ChromelyRuntime.Platform;
            //..
        }
}

Of course there are different ways to implement this interface, it all depends on your programming style and preference.

using Chromely.Core;
using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class MyConfiguration : IChromelyConfiguration
    {
        public string AppName { get; set; } = "My Awesome Chromely App";
        public ChromelyPlatform Platform { get; set; } = ChromelyRuntime.Platform;
        //..
    }
}

Now reference that class in the application builder with the UseConfiguration option.

using Chromely.Core;
using Chromely.Core.Configuration;

namespace My_Chromely_App
{
    class Program
    {
        static void Main(string[] args)
        {
            // application builder
            AppBuilder
            .Create()
            .UseApp<DemoChromelyApp>()
            .UseConfiguration<MyConfiguration>()
            .Build()
            .Run(args);
        }
    }
}

That's it.