import React from 'react/addons'; import remote from 'remote'; import RetinaImage from 'react-retina-image'; import ipc from 'ipc'; var autoUpdater = remote.require('auto-updater'); import util from '../utils/Util'; import metrics from '../utils/MetricsUtil'; var Menu = remote.require('menu'); var MenuItem = remote.require('menu-item'); import accountStore from '../stores/AccountStore'; import accountActions from '../actions/AccountActions'; import Router from 'react-router'; import classNames from 'classnames'; var Header = React.createClass({ mixins: [Router.Navigation], getInitialState: function () { return { fullscreen: false, updateAvailable: false, username: accountStore.getState().username, verified: accountStore.getState().verified }; }, componentDidMount: function () { document.addEventListener('keyup', this.handleDocumentKeyUp, false); accountStore.listen(this.update); ipc.on('application:update-available', () => { this.setState({ updateAvailable: true }); }); autoUpdater.checkForUpdates(); }, componentWillUnmount: function () { document.removeEventListener('keyup', this.handleDocumentKeyUp, false); accountStore.unlisten(this.update); }, update: function () { let accountState = accountStore.getState(); this.setState({ username: accountState.username, verified: accountState.verified }); }, handleDocumentKeyUp: function (e) { if (e.keyCode === 27 && remote.getCurrentWindow().isFullScreen()) { remote.getCurrentWindow().setFullScreen(false); this.forceUpdate(); } }, handleClose: function () { if (util.isWindows()) { remote.getCurrentWindow().close(); } else { remote.getCurrentWindow().hide(); } }, handleMinimize: function () { remote.getCurrentWindow().minimize(); }, handleFullscreen: function () { if (util.isWindows()) { if (remote.getCurrentWindow().isMaximized()) { remote.getCurrentWindow().unmaximize(); } else { remote.getCurrentWindow().maximize(); } this.setState({ fullscreen: remote.getCurrentWindow().isMaximized() }); } else { remote.getCurrentWindow().setFullScreen(!remote.getCurrentWindow().isFullScreen()); this.setState({ fullscreen: remote.getCurrentWindow().isFullScreen() }); } }, handleFullscreenHover: function () { this.update(); }, handleAutoUpdateClick: function () { metrics.track('Restarted to Update'); ipc.send('application:quit-install'); }, handleUserClick: function (e) { let menu = new Menu(); if (!this.state.verified) { menu.append(new MenuItem({ label: 'I\'ve Verified My Email Address', click: this.handleVerifyClick})); } menu.append(new MenuItem({ label: 'Sign Out', click: this.handleLogoutClick})); menu.popup(remote.getCurrentWindow(), e.currentTarget.offsetLeft, e.currentTarget.offsetTop + e.currentTarget.clientHeight + 10); }, handleLoginClick: function () { this.transitionTo('login'); metrics.track('Opened Log In Screen'); }, handleLogoutClick: function () { metrics.track('Logged Out'); accountActions.logout(); }, handleVerifyClick: function () { metrics.track('Verified Account', { from: 'header' }); accountActions.verify(); }, renderLogo: function () { return (