Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Commit aa9a578

Browse files
committed
Add option to disable sensors in menu
1 parent 12931e5 commit aa9a578

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

electron-builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ files:
77
- config.js
88
- assets/icon.png
99
- assets/tray.png
10+
1011
- "node_modules/**/*"
1112
asar: false
1213
linux:

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function createWindow () {
1111
browserWindow = new BrowserWindow({
1212
height: 600,
1313
icon: 'assets/icon.ico',
14-
kiosk: false,
14+
kiosk: false, //TODO: Reimplement
1515
title: 'Home Assistant',
1616
titleBarStyle: 'hidden',
1717
width: 800
@@ -23,7 +23,7 @@ function createWindow () {
2323
if (settings.has('url')) {
2424
load('index.html')
2525
if (!settings.has('tray') || settings.get('tray')) {
26-
TrayInit(settings.get('url'), settings.get('password'))
26+
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
2727
}
2828
} else {
2929
load('connect.html')
@@ -46,17 +46,19 @@ function createWindow () {
4646
settings.set('password', password)
4747
load('index.html')
4848
if (!settings.has('tray') || settings.get('tray')) {
49-
TrayInit(settings.get('url'), settings.get('password'))
49+
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
5050
}
5151
}
5252

53-
browserWindow.saveSettings = (notifications, dimensions, tray, kiosk) => {
53+
browserWindow.saveSettings = (notifications, dimensions, tray, kiosk, sit) => {
5454
settings.set('notifications', notifications)
5555
settings.set('save_dimensions', dimensions)
5656
settings.set('tray', tray)
5757
settings.set('kiosk', kiosk)
58+
settings.set('sensors_in_tray', sit)
5859
if (settings.has('url')) {
5960
load('index.html')
61+
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
6062
} else {
6163
load('connect.html')
6264
}

src/settings.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
height: 100%;
1010
overflow: hidden
1111
}
12-
12+
1313
#titlebar {
1414
-webkit-app-region: drag;
1515
height: 25px;
1616
display: block;
1717
}
18-
18+
1919
h2 {
2020
color: #03A9F4;
2121
font-family: 'Roboto';
@@ -42,7 +42,7 @@
4242
border-radius: 5px;
4343
cursor: hand;
4444
}
45-
45+
4646
button:hover {
4747
background-color: #3ab8f2;
4848
}
@@ -58,7 +58,7 @@
5858
table {
5959
margin: 0 auto;
6060
}
61-
61+
6262
</style>
6363
</head>
6464

@@ -79,6 +79,10 @@ <h2>Settings</h2>
7979
<td><input id="s2" type="checkbox"></td>
8080
<td><span class="prefs">Create tray menu</span></td>
8181
</tr>
82+
<tr>
83+
<td><input id="s4" type="checkbox"></td>
84+
<td><span class="prefs">Show sensors in tray</span></td>
85+
</tr>
8286
<tr>
8387
<td><input id="s3" type="checkbox" disabled="true"></td>
8488
<td><span class="prefs disabled">Kiosk mode</span></td>
@@ -98,6 +102,7 @@ <h5>Some changes may require a restart</h5>
98102
document.getElementById("s0").checked = remote.getCurrentWindow().settings.get('notifications', false)
99103
document.getElementById("s1").checked = remote.getCurrentWindow().settings.get('save_dimensions', false)
100104
document.getElementById("s2").checked = remote.getCurrentWindow().settings.get('tray', true)
105+
document.getElementById("s4").checked = remote.getCurrentWindow().settings.get('sensors_in_tray', false)
101106
document.getElementById("s3").checked = remote.getCurrentWindow().settings.get('kiosk', false)
102107

103108
function save () {
@@ -106,6 +111,7 @@ <h5>Some changes may require a restart</h5>
106111
document.getElementById("s1").checked,
107112
document.getElementById("s2").checked,
108113
document.getElementById("s3").checked,
114+
document.getElementById("s4").checked
109115
)
110116
}
111117

@@ -117,4 +123,4 @@ <h5>Some changes may require a restart</h5>
117123
</script>
118124
</body>
119125

120-
</html>
126+
</html>

tray.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const Client = require('node-rest-client').Client
22
const { app, BrowserWindow, Menu, dialog, shell, Tray } = require('electron')
3+
const path = require('path')
34

45
var client = new Client()
6+
var activeTray = undefined
57

68
/**
79
* Calls a home assistant service
@@ -42,8 +44,14 @@ function filterDomain(states, domain, sensor = false) {
4244
})
4345
}
4446

45-
function createTray(hass, password) {
46-
let tray = new Tray('assets/tray.png')
47+
function createTray(hass, password, show_sensors) {
48+
49+
if (activeTray) {
50+
activeTray.destroy()
51+
}
52+
53+
let tray = new Tray(path.join(__dirname, 'assets/tray.png'))
54+
activeTray = tray
4755

4856
client.get(hass + `/api/states?api_password=${password}`, (data, res) => {
4957

@@ -73,13 +81,16 @@ function createTray(hass, password) {
7381
}
7482
})
7583

76-
let sensors = filterDomain(data, 'sensor', true).map(item => {
77-
return { label: item.label, enabled: false }
78-
})
79-
80-
let bins = filterDomain(data, 'binary_sensor', true).map(item => {
81-
return { label: item.label, enabled: false }
82-
})
84+
let sensors = []
85+
let bins = []
86+
if (show_sensors) {
87+
sensors = filterDomain(data, 'sensor', true).map(item => {
88+
return { label: item.label, enabled: false }
89+
})
90+
bins = filterDomain(data, 'binary_sensor', true).map(item => {
91+
return { label: item.label, enabled: false }
92+
})
93+
}
8394

8495
let items = [
8596
...sensors,

0 commit comments

Comments
 (0)