电子反应 - 样板调用电子api

时间:2016-12-14 13:27:37

标签: reactjs electron

我试图打开一个由Electron API提供的对话框,点击UI中的按钮(使用react

这是我的代码

// @flow
import React, { Component, PropTypes } from 'react';
import { ipcRenderer, ipcMain, dialog } from 'electron'

ipcMain.on('open-information-dialog', function (event) {
  const options = {
    type: 'info',
    title: 'Information',
    message: "This is an information dialog. Isn't it nice?",
    buttons: ['Yes', 'No']
  }
  dialog.showMessageBox(options, function (index) {
    event.sender.send('information-dialog-selection', index)
  })
})

export default class App extends Component {
  static propTypes = {
    children: PropTypes.element.isRequired
  };

  handleClick() {
    console.log("test");
    ipc.send('open-information-dialog');
  }

  render() {
    return (
      <div>
        <button onClick={this.handleClick}>test</button>
        {this.props.children}
      </div>
    );
  }
}

我错过了什么吗?

0 个答案:

没有答案