tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
912 stars 74 forks source link

How to use RegisterCustomSchemeHandler #209

Closed jogibear9988 closed 1 month ago

jogibear9988 commented 2 months ago

I tried to use the custom scheme also with the initial page:

        var window = new PhotinoWindow()
             .RegisterCustomSchemeHandler("app", (object sender, string scheme, string url, out string contentType) =>
             {
                 contentType = "text/javascript";
                 var filename = url.Replace("app://./", "wwwroot/html/app/dist/ACT/");
                 return new MemoryStream(File.ReadAllBytes(filename));
             })
            .SetTitle(windowTitle)
            .SetUseOsDefaultSize(true)
            //.SetSize(new Size(600, 400))
            .Center()
            .SetResizable(true)
            .SetDevToolsEnabled(true)
            .Load(new Uri("app://./index.html"));

        window.WaitForClose();

I know that my mime type is wrong at the moment, but the problem is, the CustomSchemehandler is not called, and it is not even tried to load the initial page.

In electron i did something similar:

        protocol.registerSchemesAsPrivileged([{ scheme: 'app', privileges: { secure: true, standard: true } }]);
        let createProtocol = (scheme, normalize = true) => {
            protocol.registerBufferProtocol(scheme,
                async (request, respond) => {
                .........

       app.on('ready',
          async () => {
              createProtocol("app");
              await createWindow();
          }
      );

      and in createWindow:
        win.loadURL('app://./index.html', { query: query });

there it worked

philippjbauer commented 1 month ago

You can't load an initial window using the custom scheme. You will have to use an HTTP resource on your disk like index.html in a wwwroot. That resource can then use the custom scheme to load dynamically generated data from the scheme handler.