ElectronJS在dialog.showOpenDialog(...)上崩溃

时间:2019-11-24 14:29:08

标签: node.js ubuntu electron

我试图提示“打开文件”对话框,并在electron docs中找到了dialog.showOpenDialog(...)

我现在将该行添加到了几个不同的项目中,结果该行一经崩溃便崩溃了。我会看到文件浏览器对话框窗口打开了一秒钟,然后崩溃了。控制台没有显示任何错误消息,它显示的最后一句话是Promise { <pending> }

我尝试过的事情:

  • official vscode debugging示例中添加dialog.showOpenDialog(...),以查看是否发现任何错误。一旦到达该行,它总是崩溃,没有错误消息。
  • 使用npm install electron --save-dev删除我的node_modules文件夹并重新安装electronic
  • 使用全局电子命令electron .
  • 运行应用
  • 使用npm uninstall -g electron和本地npm start卸载全局电子
  • 使用`npm outdate
  • 检查我的节点软件包是否已过时
  • 使用--disable-gpu参数
  • 运行应用

我正在使用Ubuntu 19.04,而不是VM,但是我也在Ubuntu 18.04的VM中对其进行了测试。

一个有趣的注意事项是,当我尝试使用带有type = file的html表单按钮来完成同一任务时,在打开文件浏览器对话框后,它也崩溃了电子应用程序。但是,当我在常规的网络浏览器中打开html页面时,它确实起作用了。

这是我的main.js

const { app, BrowserWindow } = require('electron')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
function createWindow() {
  // Create the browser window.
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  // and load the index.html of the app.
  win.loadFile('index.html')

  // Open the DevTools.
  win.webContents.openDevTools()

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null
  })

  const { dialog } = require('electron')
  console.log(dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] })) //*****THIS LINE HERE
}

app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow()
  }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

这是我的package.json

{
  "name": "electron-demo",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^7.1.2"
  }
}

0 个答案:

没有答案