|
| 1 | +import React, { PropTypes } from 'react' |
| 2 | +import CSSModules from 'browser/lib/CSSModules' |
| 3 | +import styles from './StatusBar.styl' |
| 4 | +import ZoomManager from 'browser/main/lib/ZoomManager' |
| 5 | + |
| 6 | +const electron = require('electron') |
| 7 | +const ipc = electron.ipcRenderer |
| 8 | +const { remote } = electron |
| 9 | +const { Menu, MenuItem } = remote |
| 10 | + |
| 11 | +class StatusBar extends React.Component { |
| 12 | + constructor (props) { |
| 13 | + super(props) |
| 14 | + this.state = {updateAvailable: false} |
| 15 | + } |
| 16 | + |
| 17 | + componentDidMount () { |
| 18 | + ipc.on('update-available', function (message) { |
| 19 | + this.setState({updateAvailable: true}) |
| 20 | + }.bind(this)) |
| 21 | + } |
| 22 | + |
| 23 | + updateApp () { |
| 24 | + ipc.send('update-app', 'Deal with it.') |
| 25 | + } |
| 26 | + |
| 27 | + handleZoomButtonClick (e) { |
| 28 | + let menu = new Menu() |
| 29 | + menu.append(new MenuItem({ |
| 30 | + label: '130%', |
| 31 | + click: () => this.handleZoomMenuItemClick(1.3) |
| 32 | + })) |
| 33 | + menu.append(new MenuItem({ |
| 34 | + label: '120%', |
| 35 | + click: () => this.handleZoomMenuItemClick(1.2) |
| 36 | + })) |
| 37 | + menu.append(new MenuItem({ |
| 38 | + label: '110%', |
| 39 | + click: () => this.handleZoomMenuItemClick(1.1) |
| 40 | + })) |
| 41 | + menu.append(new MenuItem({ |
| 42 | + label: '100%', |
| 43 | + click: () => this.handleZoomMenuItemClick(1) |
| 44 | + })) |
| 45 | + menu.append(new MenuItem({ |
| 46 | + label: '90%', |
| 47 | + click: () => this.handleZoomMenuItemClick(0.9) |
| 48 | + })) |
| 49 | + menu.append(new MenuItem({ |
| 50 | + label: '80%', |
| 51 | + click: () => this.handleZoomMenuItemClick(0.8) |
| 52 | + })) |
| 53 | + menu.popup(remote.getCurrentWindow()) |
| 54 | + } |
| 55 | + |
| 56 | + handleZoomMenuItemClick (zoomFactor) { |
| 57 | + let { dispatch } = this.props |
| 58 | + ZoomManager.setZoom(zoomFactor) |
| 59 | + dispatch({ |
| 60 | + type: 'SET_ZOOM', |
| 61 | + zoom: zoomFactor |
| 62 | + }) |
| 63 | + } |
| 64 | + |
| 65 | + render () { |
| 66 | + let { config } = this.props |
| 67 | + return ( |
| 68 | + <div className='StatusBar' |
| 69 | + styleName='root' |
| 70 | + > |
| 71 | + {this.state.updateAvailable |
| 72 | + ? <button onClick={this.updateApp} styleName='update'> |
| 73 | + <i className='fa fa-cloud-download'/> Update is available! |
| 74 | + </button> |
| 75 | + : null |
| 76 | + } |
| 77 | + <button styleName='zoom' |
| 78 | + onClick={(e) => this.handleZoomButtonClick(e)} |
| 79 | + > |
| 80 | + <i className='fa fa-search-plus'/> |
| 81 | + {Math.floor(config.zoom * 100)}% |
| 82 | + </button> |
| 83 | + </div> |
| 84 | + ) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +StatusBar.propTypes = { |
| 89 | + config: PropTypes.shape({ |
| 90 | + zoom: PropTypes.number |
| 91 | + }) |
| 92 | +} |
| 93 | + |
| 94 | +export default CSSModules(StatusBar, styles) |
0 commit comments