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

Howto: Custom Resource Scheme Handler #246

Closed
mattkol opened this issue Sep 25, 2020 · 0 comments
Closed

Howto: Custom Resource Scheme Handler #246

mattkol opened this issue Sep 25, 2020 · 0 comments

Comments

@mattkol
Copy link
Member

mattkol commented Sep 25, 2020

CustomResoureHandler.zip

    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var config = DefaultConfiguration.CreateForRuntimePlatform();

            // Scheme: myscheme, Host: custom [Pre-registered]
            config.StartUrl = "myscheme://custom/index.html";

            AppBuilder
            .Create()
            .UseConfig<DefaultConfiguration>(config)
            .UseApp<DemoApp>()
            .Build()
            .Run(args);
        }
    }

    public class DemoApp : ChromelyBasicApp
    {
        public override void ConfigureServices(ServiceCollection services)
        {
            base.ConfigureServices(services);
            services.AddSingleton(typeof(IChromelySchemeHandler), typeof(CustomResourceSchemeHandler));
        }
    }

    public class CustomResourceSchemeHandler : IChromelySchemeHandler
    {
        public CustomResourceSchemeHandler()
        {
            Name = "MyCustomResourceSchemeHamdler";
            // Scheme: myscheme
            // Host: custom - mapped to folder name containing resource files
            Scheme = new UrlScheme("mycustomresourcescheme", "myscheme", "custom", string.Empty, UrlSchemeType.Resource, false);
            HandlerFactory = new CustomResourceSchemeHandlerFactory();
            IsCorsEnabled = true;
            IsSecure = false;
        }

        public string Name { get; set; }
        public UrlScheme Scheme { get; set; }
        
        // Needed for CefSharp
        public object Handler { get; set; }
        public object HandlerFactory { get; set; }
        public bool IsCorsEnabled { get; set; }
        public bool IsSecure { get; set; }
    }

    public class CustomResourceSchemeHandlerFactory : DefaultResourceSchemeHandlerFactory
    {
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant