From 8ee13d0079473ae39b9e8173aa3c3da1bd3c2e4b Mon Sep 17 00:00:00 2001 From: naotone Date: Mon, 6 Aug 2018 20:58:20 -0400 Subject: [PATCH 1/2] Add local ip plugin --- src/lib/plugins/localip.js | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/lib/plugins/localip.js 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} + + +
+ ) + } +} From a6bfc3e5d5ca43404f13bdf8e947cacf13b92032 Mon Sep 17 00:00:00 2001 From: naotone Date: Mon, 6 Aug 2018 20:58:38 -0400 Subject: [PATCH 2/2] Add localip to plugins/index.js --- src/lib/plugins/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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]