plotly / orca

Command line application for generating static images of interactive plotly charts
MIT License
295 stars 39 forks source link

'ready' call back don't response. #343

Open WintonWL opened 4 years ago

WintonWL commented 4 years ago

When I used orca.run, the call back wasn't called. After checking the orca codes, I found the problem: electron app had been called 'ready' before orca.run, so orca.run call back is invalid.

Those modified codes in index.js createApp work for me:

function createApp (_opts) {
  initApp(app, ipcMain)

  const opts = coerceOpts(_opts)
  let win = null
  let index = null

  let readyCallback = () => {
    win = new BrowserWindow(opts._browserWindowOpts)

    if (opts.debug) {
      win.openDevTools()
    }

    win.on('closed', () => {
      win = null
      index.destroy()
    })

    createIndex(opts.component, opts, (_index) => {
      index = _index
      win.loadURL(`file://${index.path}`)
    })

    win.webContents.once('did-finish-load', () => {
      run(app, win, ipcMain, opts)
    })
  }

  if (app.isReady()) {
    readyCallback();
  } else {
    app.on('ready', readyCallback);
  }

  return app
}