diff --git a/package.json b/package.json index 7be2a06..6070b43 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dependencies": { "color": "^0.11.3", "git-state": "^4.0.0", + "itunes-node-applescript":"^0.3.5", "json-loader": "^0.5.4", "left-pad": "^1.1.3", "moment": "^2.18.1", diff --git a/src/lib/plugins/index.js b/src/lib/plugins/index.js index 1d7bcea..ca3a4b8 100644 --- a/src/lib/plugins/index.js +++ b/src/lib/plugins/index.js @@ -1,13 +1,14 @@ -import Hostname from './hostname' -import Ip from './ip' -import Memory from './memory' +import Battery from './battery'; // Import Uptime from './uptime' -import Cpu from './cpu' -import Network from './network' -import Battery from './battery' +import Cpu from './cpu'; +import Hostname from './hostname'; +import Ip from './ip'; +import Itunes from './itunes'; +import Memory from './memory'; +import Network from './network'; +import PartyParrot from './party-parrot'; // Import Time from './time' // Import Docker from './docker' -import Spotify from './spotify' -import PartyParrot from './party-parrot'; +import Spotify from './spotify'; -export default [Hostname, Ip, Memory, Battery, Cpu, Network, Spotify, PartyParrot] +export default [Hostname, Ip, Memory, Battery, Cpu, Network, Spotify, Itunes, PartyParrot]; diff --git a/src/lib/plugins/itunes.js b/src/lib/plugins/itunes.js new file mode 100644 index 0000000..7e4512c --- /dev/null +++ b/src/lib/plugins/itunes.js @@ -0,0 +1,88 @@ +import Component from 'hyper/component'; +import React from 'react'; +import SvgIcon from '../utils/svg-icon'; +import itunes from 'itunes-node-applescript'; + +class PluginIcon extends Component { + styles() { + return { + 'itunes-icon': { + fill: '#F5F4F5' + } + }; + } + + template(css) { + return ( + + + + + + + + + + + + ); + } +} + +export default class Itunes extends Component { + static displayName() { + return 'Itunes plugin'; + } + + constructor(props) { + super(props); + + this.state = { state: 'Not running' }; + this.setStatus = this.setStatus.bind(this); + } + + setStatus() { + itunes.isRunning((err, isRunning) => { + if (!isRunning) { + this.setState({ state: 'Not running' }); + return; + } + if (err) { + console.log(`Caught exception at setStatus(e): ${err}`); + } + + itunes.getState((err, state) => { + if (err) { + console.log(`Caught exception at itunes.getState(e): ${err}`); + } + + itunes.track((err, track) => { + if (err) { + console.log(`Caught exception at itunes.getTrack(e): ${err}`); + } + this.setState({ state: `${state === 'playing' ? '▶' : '❚❚'} ${track[1]} - ${track[5]}` }); + }); + }); + }); + } + + componentDidMount() { + this.setStatus(); + this.interval = setInterval(() => this.setStatus(), 1000); + } + + styles() { + return { wrapper: { display: 'flex', alignItems: 'center', color: '#F5F4F5' } }; + } + + template(css) { + return ( +
+ {this.state.state} +
+ ); + } +}