diff --git a/src/lib/plugins/index.js b/src/lib/plugins/index.js index 41c8b99..996ff90 100644 --- a/src/lib/plugins/index.js +++ b/src/lib/plugins/index.js @@ -1,5 +1,6 @@ import hostname from './hostname' import ip from './ip' +import localip from './localip' import memory from './memory' // Import Uptime from './uptime' import cpu from './cpu' @@ -9,4 +10,4 @@ import battery from './battery' // Import Docker from './docker' import spotify from './spotify' -export default [hostname, ip, memory, battery, cpu, network, spotify] +export default [hostname, ip, localip, memory, battery, cpu, network, spotify] diff --git a/src/lib/plugins/localip.js b/src/lib/plugins/localip.js new file mode 100644 index 0000000..d75781e --- /dev/null +++ b/src/lib/plugins/localip.js @@ -0,0 +1,91 @@ +import React from 'react' +import Component from 'hyper/component' +import SvgIcon from '../utils/svg-icon' +import os from 'os' + +function getLocalIp() { + const interfaces = os.networkInterfaces(); + let localip; + for (const i in interfaces) { + if(localip){ + return localip; + } + interfaces[i].some((el) => { + if(!el.internal && el.family === 'IPv4'){ + localip = el.address; + return true; + } + }); + } + return "?.?.?.?"; +}; + +class PluginIcon extends Component { + render() { + return ( + + + + + + + + + ) + } +} + +export default class LocalIp extends Component { + static displayName() { + return 'localip' + } + + constructor(props) { + super(props) + + this.state = { + localip: '?.?.?.?' + } + + this.setIp = this.setIp.bind(this) + } + + setIp() { + this.setState({localip: getLocalIp()}) + } + + componentDidMount() { + // Every 5 seconds + this.setIp() + this.interval = setInterval(() => this.setIp(), 60000 * 5) + } + + componentWillUnmount() { + clearInterval(this.interval) + } + + render() { + return ( +
+ {this.state.localip} + + +
+ ) + } +}