Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add iTunes plugin #123

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 10 additions & 9 deletions src/lib/plugins/index.js
Original file line number Diff line number Diff line change
@@ -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];
88 changes: 88 additions & 0 deletions src/lib/plugins/itunes.js
Original file line number Diff line number Diff line change
@@ -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 (
<SvgIcon>
<g fill="none" fillRule="evenodd">
<g fill="none" fillRule="evenodd">
<g className={css('itunes-icon')} transform="translate(1.000000, 1.000000)">
<g>
<path
d="m7.49996,1.06347c-3.55479,0 -6.43665,2.88178 -6.43665,6.43657c0,3.55494 2.88186,6.43649 6.43665,6.43649c3.55517,0 6.43672,-2.88155 6.43672,-6.43649c0,-3.55456 -2.88155,-6.43626 -6.4368,-6.43626l0.00008,-0.00031zm2.9518,9.28338c-0.11529,0.18908 -0.36279,0.24903 -0.55187,0.13297c-1.51126,-0.92311 -3.41374,-1.13218 -5.65427,-0.62028c-0.21591,0.04919 -0.43112,-0.08609 -0.48031,-0.30207c-0.04942,-0.21598 0.08532,-0.4312 0.30176,-0.48039c2.45189,-0.5604 4.55507,-0.31898 6.25172,0.71789c0.18908,0.11606 0.24903,0.36279 0.13297,0.55187zm0.78783,-1.75284c-0.14527,0.23635 -0.45425,0.31091 -0.69022,0.16564c-1.73016,-1.06369 -4.36752,-1.37168 -6.41397,-0.75048c-0.2654,0.08017 -0.54572,-0.06941 -0.62627,-0.33435c-0.07994,-0.2654 0.06971,-0.54518 0.33466,-0.62589c2.3376,-0.70928 5.24367,-0.36571 7.23055,0.85524c0.23597,0.14527 0.31052,0.45425 0.16525,0.68991l0,-0.00008zm0.06764,-1.82501c-2.0745,-1.23217 -5.49716,-1.34547 -7.47782,-0.74433c-0.31805,0.09646 -0.6544,-0.08309 -0.75079,-0.40114c-0.09638,-0.31821 0.08301,-0.65433 0.4013,-0.75102c2.27365,-0.69022 6.05334,-0.55686 8.44174,0.86101c0.28669,0.16979 0.38047,0.53926 0.2106,0.82496c-0.1691,0.28608 -0.53957,0.38039 -0.82473,0.21052l-0.00031,0z"
fill="#F5F4F5"
/>
</g>
</g>
</g>
</g>
</SvgIcon>
);
}
}

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 (
<div className={css('wrapper')}>
<PluginIcon /> {this.state.state}
</div>
);
}
}