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

Commit

Permalink
Add option to disable sensors in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
matthinc committed Oct 17, 2017
1 parent 12931e5 commit aa9a578
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ files:
- config.js
- assets/icon.png
- assets/tray.png
- assets/tray@2x.png
- "node_modules/**/*"
asar: false
linux:
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createWindow () {
browserWindow = new BrowserWindow({
height: 600,
icon: 'assets/icon.ico',
kiosk: false,
kiosk: false, //TODO: Reimplement
title: 'Home Assistant',
titleBarStyle: 'hidden',
width: 800
Expand All @@ -23,7 +23,7 @@ function createWindow () {
if (settings.has('url')) {
load('index.html')
if (!settings.has('tray') || settings.get('tray')) {
TrayInit(settings.get('url'), settings.get('password'))
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
}
} else {
load('connect.html')
Expand All @@ -46,17 +46,19 @@ function createWindow () {
settings.set('password', password)
load('index.html')
if (!settings.has('tray') || settings.get('tray')) {
TrayInit(settings.get('url'), settings.get('password'))
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
}
}

browserWindow.saveSettings = (notifications, dimensions, tray, kiosk) => {
browserWindow.saveSettings = (notifications, dimensions, tray, kiosk, sit) => {
settings.set('notifications', notifications)
settings.set('save_dimensions', dimensions)
settings.set('tray', tray)
settings.set('kiosk', kiosk)
settings.set('sensors_in_tray', sit)
if (settings.has('url')) {
load('index.html')
TrayInit(settings.get('url'), settings.get('password'), settings.get('sensors_in_tray', false))
} else {
load('connect.html')
}
Expand Down
16 changes: 11 additions & 5 deletions src/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
height: 100%;
overflow: hidden
}

#titlebar {
-webkit-app-region: drag;
height: 25px;
display: block;
}

h2 {
color: #03A9F4;
font-family: 'Roboto';
Expand All @@ -42,7 +42,7 @@
border-radius: 5px;
cursor: hand;
}

button:hover {
background-color: #3ab8f2;
}
Expand All @@ -58,7 +58,7 @@
table {
margin: 0 auto;
}

</style>
</head>

Expand All @@ -79,6 +79,10 @@ <h2>Settings</h2>
<td><input id="s2" type="checkbox"></td>
<td><span class="prefs">Create tray menu</span></td>
</tr>
<tr>
<td><input id="s4" type="checkbox"></td>
<td><span class="prefs">Show sensors in tray</span></td>
</tr>
<tr>
<td><input id="s3" type="checkbox" disabled="true"></td>
<td><span class="prefs disabled">Kiosk mode</span></td>
Expand All @@ -98,6 +102,7 @@ <h5>Some changes may require a restart</h5>
document.getElementById("s0").checked = remote.getCurrentWindow().settings.get('notifications', false)
document.getElementById("s1").checked = remote.getCurrentWindow().settings.get('save_dimensions', false)
document.getElementById("s2").checked = remote.getCurrentWindow().settings.get('tray', true)
document.getElementById("s4").checked = remote.getCurrentWindow().settings.get('sensors_in_tray', false)
document.getElementById("s3").checked = remote.getCurrentWindow().settings.get('kiosk', false)

function save () {
Expand All @@ -106,6 +111,7 @@ <h5>Some changes may require a restart</h5>
document.getElementById("s1").checked,
document.getElementById("s2").checked,
document.getElementById("s3").checked,
document.getElementById("s4").checked
)
}

Expand All @@ -117,4 +123,4 @@ <h5>Some changes may require a restart</h5>
</script>
</body>

</html>
</html>
29 changes: 20 additions & 9 deletions tray.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Client = require('node-rest-client').Client
const { app, BrowserWindow, Menu, dialog, shell, Tray } = require('electron')
const path = require('path')

var client = new Client()
var activeTray = undefined

/**
* Calls a home assistant service
Expand Down Expand Up @@ -42,8 +44,14 @@ function filterDomain(states, domain, sensor = false) {
})
}

function createTray(hass, password) {
let tray = new Tray('assets/tray.png')
function createTray(hass, password, show_sensors) {

if (activeTray) {
activeTray.destroy()
}

let tray = new Tray(path.join(__dirname, 'assets/tray.png'))
activeTray = tray

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

Expand Down Expand Up @@ -73,13 +81,16 @@ function createTray(hass, password) {
}
})

let sensors = filterDomain(data, 'sensor', true).map(item => {
return { label: item.label, enabled: false }
})

let bins = filterDomain(data, 'binary_sensor', true).map(item => {
return { label: item.label, enabled: false }
})
let sensors = []
let bins = []
if (show_sensors) {
sensors = filterDomain(data, 'sensor', true).map(item => {
return { label: item.label, enabled: false }
})
bins = filterDomain(data, 'binary_sensor', true).map(item => {
return { label: item.label, enabled: false }
})
}

let items = [
...sensors,
Expand Down

0 comments on commit aa9a578

Please sign in to comment.