Skip to content

Commit

Permalink
Fix close
Browse files Browse the repository at this point in the history
  • Loading branch information
blavka committed Jan 15, 2020
1 parent 0150dea commit a9081b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ function createWindow() {
buttons: ["Cancel", "Close without Saving"],
title: "Warning",
message: "Node-RED contains unsaved changes"
}, (response)=>{
if (response == 1) {
}).then((result)=>{
console.log('showMessageBox', 'response', result);
if (result.response == 1) {
mainWindow.send("iframe:node-red:visible", false);
timer = setTimeout(()=>{mainWindow.close()}, 100);
}
});
}).catch(err => {
console.error('showMessageBox', err);
})

}, 1000);
})
Expand Down
20 changes: 17 additions & 3 deletions src/render/components/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,40 @@ class RouteIframeComponent extends Component {
constructor(props) {
super(props);

this.state = {visible: true};
this.state = {
visible: true,
random: 0
};
}

componentDidMount() {
if (this.props.id) {
ipcRenderer.on("iframe:" + this.props.id + ":visible", (sender, visible)=>{ console.log("iframe:" + this.props.id + ":visible", visible); this.setState({visible}); });
ipcRenderer.on("iframe:" + this.props.id + ":visible", (sender, visible)=>{
console.log("iframe:" + this.props.id + ":visible", visible);
this.setState({visible});
});
ipcRenderer.on("iframe:" + this.props.id + ":reload", (sender)=>{
console.log("iframe:" + this.props.id + ":reload");
this.setState({random: this.state.random + 1});
});
}
}

componentWillUnmount() {
if (this.props.id) {
ipcRenderer.removeAllListeners("iframe:" + this.props.id + ":visible");
ipcRenderer.removeAllListeners("iframe:" + this.props.id + ":reload");
}
}

render() {
const { location, path, src } = this.props

return (this.state.visible ?
<iframe src={src} style={{display: location.pathname == path ? "block" : "none"}} className="route" id={this.props.id} ></iframe>
<iframe src={this.props.src}
key={this.state.random}
style={{display: location.pathname == path ? "block" : "none"}}
className="route" id={this.props.id} ></iframe>
: null
)
}
Expand Down

0 comments on commit a9081b8

Please sign in to comment.