-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
33 lines (27 loc) · 1.06 KB
/
renderer.js
File metadata and controls
33 lines (27 loc) · 1.06 KB
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
async function init() {
const config = await window.api.getConfig();
document.getElementById('haUrl').value = config.haUrl;
document.getElementById('token').value = config.token;
const sensors = await window.api.getAllSensors();
const list = document.getElementById('sensor-list');
sensors.forEach(sensor => {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = sensor.id;
checkbox.checked = config.sensors.includes(sensor.id);
const label = document.createElement('label');
label.textContent = sensor.name;
label.prepend(checkbox);
list.appendChild(label);
list.appendChild(document.createElement('br'));
});
}
function save() {
const haUrl = document.getElementById('haUrl').value;
const token = document.getElementById('token').value;
const checkboxes = document.querySelectorAll('#sensor-list input:checked');
const selectedSensors = Array.from(checkboxes).map(cb => cb.value);
window.api.saveConfig({ haUrl, token, sensors: selectedSensors });
window.close();
}
init();