| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /**
- * @author oldj
- * @blog http://oldj.net
- */
- 'use strict'
- import React from 'react'
- import Panel from './panel/panel'
- import Content from './content/content'
- import SudoPrompt from './frame/sudo'
- import EditPrompt from './frame/edit'
- import PreferencesPrompt from './frame/preferences'
- import Agent from '../../renderer/Agent'
- import './app.less'
- class App extends React.Component {
- constructor (props) {
- super(props)
- this.state = {
- list: [],
- sys: {},
- current: {},
- lang: {}
- }
- Agent.act('getUserHosts', (e, data) => {
- this.setState({
- list: data.list,
- sys: data.sys
- })
- })
- Agent.act('getLang', (e, lang) => {
- this.setState({lang})
- })
- }
- setCurrent (hosts) {
- if (hosts.is_sys) {
- Agent.act('getSysHosts', (e, _hosts) => {
- this.setState({
- current: _hosts
- })
- })
- } else {
- this.setState({
- current: hosts
- })
- }
- }
- static isReadOnly (hosts) {
- return !hosts || hosts.is_sys || hosts.where === 'remote'
- }
- toSave () {
- clearTimeout(this._t)
- this._t = setTimeout(() => {
- Agent.emit('change')
- }, 1000)
- }
- setHostContent (v) {
- if (this.state.current.content === v) return // not changed
- this.state.current.content = v || ''
- this.toSave()
- }
- componentDidMount () {
- window.addEventListener('keydown', (e) => {
- if (e.keyCode === 27) {
- Agent.emit('esc')
- }
- }, false)
- }
- render () {
- let current = this.state.current
- return (
- <div id="app" className={'platform-' + Agent.platform}>
- <Panel
- list={this.state.list}
- sys={this.state.sys}
- current={current}
- setCurrent={this.setCurrent.bind(this)}
- lang={this.state.lang}
- />
- <Content
- current={current}
- readonly={App.isReadOnly(current)}
- setHostContent={this.setHostContent.bind(this)}
- lang={this.state.lang}
- />
- <div className="frames">
- <SudoPrompt/>
- <EditPrompt hosts={this.state.hosts}/>
- <PreferencesPrompt/>
- </div>
- </div>
- )
- }
- }
- export default App
|