From f57aecb1c1ec1c8b4c2c98d1f650b448daa44573 Mon Sep 17 00:00:00 2001 From: Rodrigo Juarez Date: Sun, 8 Oct 2017 23:42:34 -0300 Subject: [PATCH 1/4] Enhancement - Added iTunes plugin - Still using the same styles from Spotify - For the moment this only marks if iTunes is running or not --- package.json | 1 + src/lib/plugins/index.js | 19 ++++----- src/lib/plugins/itunes.js | 84 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 src/lib/plugins/itunes.js 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..1b70f00 --- /dev/null +++ b/src/lib/plugins/itunes.js @@ -0,0 +1,84 @@ +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 { + 'spotify-icon': { + fill: '#1ED760' + } + }; + } + + 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) => { + console.log('is running iTunes'); + this.setState({ state: isRunning ? 'Running' : 'Not running' }); + if (err) { + console.log(`Caught exception at setStatus(e): ${err}`); + } + // spotify.getState((err, st) => { + // if (err) { + // console.log(`Caught exception at spotify.getState(e): ${err}`); + // } + // spotify.getTrack((err, track) => { + // if (err) { + // console.log(`Caught exception at spotify.getTrack(e): ${err}`); + // } + // this.setState({ state: `${st.state === 'playing' ? '▶' : '❚❚'} ${track.artist} - ${track.name}` }); + // }); + // }); + }); + } + + componentDidMount() { + this.setStatus(); + this.interval = setInterval(() => this.setStatus(), 1000); + } + + styles() { + return { wrapper: { display: 'flex', alignItems: 'center', color: '#1ED760' } }; + } + + template(css) { + return ( +
+ {this.state.state} +
+ ); + } +} From 454180b049daa04fb20526a5b6665424d0236e1c Mon Sep 17 00:00:00 2001 From: Rodrigo Juarez Date: Mon, 9 Oct 2017 00:01:59 -0300 Subject: [PATCH 2/4] Enhancement - Added the track that it's currently playing to the status --- src/lib/plugins/itunes.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib/plugins/itunes.js b/src/lib/plugins/itunes.js index 1b70f00..c6f160a 100644 --- a/src/lib/plugins/itunes.js +++ b/src/lib/plugins/itunes.js @@ -46,22 +46,20 @@ export default class Itunes extends Component { setStatus() { itunes.isRunning((err, isRunning) => { - console.log('is running iTunes'); - this.setState({ state: isRunning ? 'Running' : 'Not running' }); + if (!isRunning) { + this.setState({ state: 'Not running' }); + return; + } if (err) { console.log(`Caught exception at setStatus(e): ${err}`); } - // spotify.getState((err, st) => { - // if (err) { - // console.log(`Caught exception at spotify.getState(e): ${err}`); - // } - // spotify.getTrack((err, track) => { - // if (err) { - // console.log(`Caught exception at spotify.getTrack(e): ${err}`); - // } - // this.setState({ state: `${st.state === 'playing' ? '▶' : '❚❚'} ${track.artist} - ${track.name}` }); - // }); - // }); + + itunes.track((err, track) => { + if (err) { + console.log(`Caught exception at itunes.getTrack(e): ${err}`); + } + this.setState({ state: `▶ ${track[1]} - ${track[5]}` }); + }); }); } From 065c3e1b739cdfb1b23ba3abcc4ab6b2758e9d5d Mon Sep 17 00:00:00 2001 From: Rodrigo Juarez Date: Mon, 9 Oct 2017 00:28:42 -0300 Subject: [PATCH 3/4] Enhancement - Retrieving current state of track - Yet this script isn't implemented inside itunes-node-applescript, i'll do a PR to get it updated and tell the owner to update the npm package --- src/lib/plugins/itunes.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/plugins/itunes.js b/src/lib/plugins/itunes.js index c6f160a..ccaf6a5 100644 --- a/src/lib/plugins/itunes.js +++ b/src/lib/plugins/itunes.js @@ -54,11 +54,17 @@ export default class Itunes extends Component { console.log(`Caught exception at setStatus(e): ${err}`); } - itunes.track((err, track) => { + itunes.getState((err, state) => { if (err) { - console.log(`Caught exception at itunes.getTrack(e): ${err}`); + console.log(`Caught exception at itunes.getState(e): ${err}`); } - this.setState({ state: `▶ ${track[1]} - ${track[5]}` }); + + itunes.track((err, track) => { + if (err) { + console.log(`Caught exception at itunes.getTrack(e): ${err}`); + } + this.setState({ state: `${state === 'playing' ? '▶' : '❚❚'} ${track[1]} - ${track[5]}` }); + }); }); }); } From 4282a8c82ca8138068f490e8f882ecb111c8ae84 Mon Sep 17 00:00:00 2001 From: Rodrigo Juarez Date: Tue, 10 Oct 2017 19:13:23 -0300 Subject: [PATCH 4/4] Enhancement - Changed icon and text colors for itunes plugin --- src/lib/plugins/itunes.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/plugins/itunes.js b/src/lib/plugins/itunes.js index ccaf6a5..7e4512c 100644 --- a/src/lib/plugins/itunes.js +++ b/src/lib/plugins/itunes.js @@ -6,8 +6,8 @@ import itunes from 'itunes-node-applescript'; class PluginIcon extends Component { styles() { return { - 'spotify-icon': { - fill: '#1ED760' + 'itunes-icon': { + fill: '#F5F4F5' } }; } @@ -17,11 +17,11 @@ class PluginIcon extends Component { - + @@ -75,7 +75,7 @@ export default class Itunes extends Component { } styles() { - return { wrapper: { display: 'flex', alignItems: 'center', color: '#1ED760' } }; + return { wrapper: { display: 'flex', alignItems: 'center', color: '#F5F4F5' } }; } template(css) {