Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use async save dialog for anchor download attribute #16612

Merged
merged 1 commit into from Jan 31, 2019

Commits on Jan 30, 2019

  1. fix: Use async save dialog for anchor download attribute

    On macOS, the synchronous save dialog does not work properly and breaks
    in weird ways when the dialog is expanded/collapsed (see #14606). This
    works around the problem for the dialog shown for `<a download=...>` by
    switching to the asynchronous API.
    
    To test this:
    
    main.js:
    ```
    const { app, BrowserWindow, session } = require('electron')
    const path = require('path')
    
    function createWindow() {
      win = new BrowserWindow({
        width: 600,
        height: 600,
        webPreferences: {
          nodeIntegration: false,
        },
      })
    
      session.defaultSession.on('will-download', (event, item) => {
        // Test with and without this commented out.
        //item.setSavePath(path.join(app.getPath('desktop'), 'test-download.txt'))
      })
    
      win.loadURL(`file://${__dirname}/test.html`)
    }
    
    app.on('ready', createWindow)
    ```
    
    test.html:
    ```
    <html>
    <head>
      <meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; img-src 'self' data:">
    </head>
    <body>
    <a href="data:application/xml;charset=utf-8,foo" download="download.txt">Save</a>
    </body>
    ```
    poiru committed Jan 30, 2019
    Configuration menu
    Copy the full SHA
    261ebd5 View commit details
    Browse the repository at this point in the history