-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.demoContainer { | ||
width: 50%; | ||
margin: 0 auto; | ||
} | ||
|
||
.margin { | ||
margin-top: 15px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import { Button, Alert } from 'antd'; | ||
import styles from './index.css'; | ||
import { ipcRenderer } from 'electron'; | ||
|
||
|
||
class IPC extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
msg: '' | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
ipcRenderer.on('main-msg', (event, msg) => { | ||
this.setState({ msg }) | ||
}) | ||
} | ||
|
||
handleSendSync = () => { | ||
ipcRenderer.send('sync-render', '我是来自渲染进程的异步消息'); | ||
} | ||
|
||
handleSendAsync = () => { | ||
const msg = ipcRenderer.sendSync('async-render', '我是来自渲染进程的同步消息'); | ||
this.setState({ msg }) | ||
} | ||
|
||
handleStart = () => { | ||
ipcRenderer.send('start-msg'); | ||
} | ||
|
||
handleEnd = () => { | ||
ipcRenderer.send('end-msg'); | ||
} | ||
|
||
|
||
render() { | ||
const { msg } = this.state; | ||
return ( | ||
<div className={styles.demoContainer}> | ||
<Alert className={styles.margin} message="点击向主进程发送【异步】消息" type="info" /> | ||
<Button className={styles.margin} onClick={this.handleSendSync}>发送</Button> | ||
<Alert className={styles.margin} message="点击向主进程发送【同步】消息" type="error" /> | ||
<Button className={styles.margin} onClick={this.handleSendAsync}>发送</Button> | ||
<Alert className={styles.margin} message="点击告诉主进程,开始向渲染进程发消息吧!" type="error" /> | ||
<Button className={styles.margin} onClick={this.handleStart}>开始发送</Button> | ||
<Button className={styles.margin} onClick={this.handleEnd}>结束发送</Button> | ||
<Alert className={styles.margin} message={"主进程的回应:" + msg} type="warning" /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default IPC; |