-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 873 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 873 Bytes
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
require('dotenv').config()
const {app, Tray} = require('electron');
const axios = require('axios');
const path = require('path')
const url = `${process.env.HUE_IP}/api/${process.env.HUE_USER}/lights/2/state`;
let trayIcon;
app.on('ready', function() {
if(process.platform === 'darwin') app.dock.hide();
const iconOn = 'images/on.png';
const iconPathOn = path.join(__dirname, iconOn);
trayIcon = new Tray(iconPathOn);
trayIcon.on('click', (event) => {
axios.put(url, {"on":true})
.then(res => {
console.log('Light ON: ',res.status);
}).catch(err => {
console.log('error', err);
})
});
trayIcon.on('double-click', (event) => {
axios.put(url, {"on":false})
.then(res => {
console.log('Light OFF: ',res.status);
}).catch(err => {
console.log('error', err);
})
});
});