При нажатии на кнопку отмены на диалоге открытия файла (код ниже) я получаю следующее сообщение об ошибке:Electron ошибка отменяя диалог открытия файла
A JavaScript error occurred in the main process
Uncaught Exception:
TypeError: Error processing argument -1.
at TypeError (native)
at [object Object].Object.defineProperty.set (/Applications/Electron.app/Contents/Resources/atom.asar/browser/api/lib/web-contents.js:92:24)
at main.js:37:20
at Function.wrappedCallback (/Applications/Electron.app/Contents/Resources/atom.asar/browser/api/lib/dialog.js:80:16)
Ошибка представлена как модальное всплывающее окно:
Я до сих пор тестировал только на Mac.
Мой код выглядит следующим образом:
Основной код процесса, который обрабатывает создание диалога выглядит следующим образом:
import electron, { ipcMain } from 'electron'
const app = electron.app
const BrowserWindow = electron.BrowserWindow
electron.crashReporter.start()
let mainWindow = null
app.on('window-all-closed',() => {
if (process.platform != 'darwin') app.quit()
})
app.on('ready',() => {
mainWindow = new BrowserWindow({
width: 800,
height: 600
})
mainWindow.loadURL(`file://${__dirname}/index.html`)
mainWindow.webContents.openDevTools()
mainWindow.on('closed',() => {
mainWindow = null
})
ipcMain.on('file:open', (e, arg) => {
electron.dialog.showOpenDialog(mainWindow, {
properties: ['openFile'],
filters: [{
name: 'Outlines',
extensions: ['pxo']
}]
}, (filePathList) => {
debugger
e.returnValue = filePathList
})
})
})
Мой отладчик заявление никогда не будет достигнуто. Кроме того, код отлично работает, когда некоторые файлы фактически выбраны, и работает только при отмене отмены.
Код (ES6 + JSX), что вызывает МПК вызов следующим образом:
class Welcome extends React.Component {
render() {
const styles = this.getStyles()
return (
<div style={styles.outerContainer}>
<a style={styles.btnSetLink} onClick={this.initFileSelection.bind(this)}>
Open File
</a>
</div>
)
}
initFileSelection() {
const filePathList = ipcRenderer.sendSync('file:open')
}
...
Код обрабатывается через Вавилонской 6. Мой .babelrc
выглядит следующим образом:
{
"presets": ["react", "es2015"]
}
Версия электронный: v0.35.1
.
Версии зависимостей Бабеля:
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── babel-plugin-transform-es2015-object-sup[email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
Любая помощь в решении ошибки будут высоко оценены.
Здравствуйте, пожалуйста, добавьте некоторые детали код является таким образом ответ имеет некоторое объяснение, и его легче понять. – Chaithanya
Этот код поймает любую ошибку и в обратном вызове вы сможете справиться с этим –
Спасибо за информацию. Пожалуйста, добавьте информацию из комментария в ответ, чтобы она была полной. Посмотрите http://stackoverflow.com/help/how-to-answer советы о том, как писать хорошие ответы. – Chaithanya