chromelyapps / Chromely

Build Cross Platform HTML Desktop Apps on .NET using native GUI, HTML5, JavaScript, CSS, Owin, AspNetCore (MVC, RazorPages, Blazor)
MIT License
2.99k stars 279 forks source link

CefDownloadHandler not showing Dialog on Linux #343

Closed peerem closed 2 years ago

peerem commented 2 years ago

The CefDownloadHandler not showing the dialog on Linux. The event was fired, but no "Save to..." dialog was shown.

internal class PeerEmDownloadHandler : CefDownloadHandler
{
    protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
    {
        base.OnBeforeDownload(browser, downloadItem, suggestedName, callback);

        LogHelper.Debug("Test", "OnBeforeDownload", true);

        // Ask for path
        callback.Continue(string.Empty, true);
    }
}
mattkol commented 2 years ago

@peerem

I do not think this will work straight out of the box for Linux and MacOS. You may have to implement a gtk "Save As" dialog to make it work.

That is exposing the gtk_file_chooser_native_new via C# using DllImport.

Like this example:

https://github.com/chromelyapps/Chromely/blob/542cd54d2a5452dd67d45aef0054f6187f17f809/src_5.0/Chromely/Native/LinuxGtk3/LinuxNativeMethods.cs#L83

There is an example here using CefSharp - https://stackoverflow.com/questions/39148865/cefsharp-onbeforedownload-handler-opening-open-file-window-instead-of-save-windo

So basically you replace the SaveFileDialog with your implementation.


  public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
    {
        if (!callback.IsDisposed)
        {
            using (callback)
            {
                if (_allowDownload)
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();

                    if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != "")
                    {

                    }
                    else
                }
                else

                callback.Continue(downloadItem.SuggestedFileName, showDialog: false);
            }

An alternative will be to use an HTML SaveFileDialog using JavaScript.

Chromely does not provide any of these options out of the box.

Thanks.

peerem commented 2 years ago

We are thinking about possibly running the application in the external Chrome/Edge "App Mode". CEF only causes problems, such as dialogues or missing codecs. An option to run it externally wouldn't be bad.