forked from jaredpalmer/hyperhue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (51 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const Hue = require('node-hue-api')
const fs = require('fs')
const path = require('path')
exports.middleware = (store) => (next) => (action) => {
if ('CONFIG_LOAD' === action.type || 'CONFIG_RELOAD' === action.type) {
const homedir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
const configfile = path.join(homedir, '.hyperhue.json')
try {
const hueConfig = JSON.parse(fs.readFileSync(configfile, 'utf-8'))
const { host, username, light } = hueConfig
const api = new Hue.HueApi(host, username)
return api
.lightStatusWithRGB(1)
.then(status => {
const { rgb } = status.state
return store.dispatch({
type: 'UPDATE_HUE',
payload: `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`
})
})
.catch(e => {
console.log(e)
return next(action)
})
} catch (e) {
console.log('You need to run HyperHue init.js first. Copy and paste the following into your terminal. Press the link button on your brige BEFORE your run it.')
console.log('node ~/.hyperterm_plugins/node_modules/hyperhue/init.js')
next(action)
}
} else {
next(action)
}
}
exports.reduceUI = (state, action) => {
switch (action.type) {
case 'UPDATE_HUE':
console.log(action)
return state.set('borderColor', action.payload)
.set('cursorColor', action.payload)
.set('css', `
${state.css || ''}
.tabs_nav .tabs_list .tab_text {
color: ${action.payload}
}
.tabs_nav .tabs_title {
color: ${action.payload}
}
`)
}
return state
}