mirror of
https://github.com/sascha-hemi/homeassistant-desktop.git
synced 2026-03-21 05:06:33 +01:00
- fixes #10 #17 - might fix #11 - feature #13 (thanks @tnagels) - added global keyboard shortcut - bonjour auto discovery - detached window on Windows can now be moved by resizing it Merry Christmas 🎄
130 lines
3.9 KiB
HTML
130 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Home Assistant</title>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width,user-scalable=no" />
|
|
<link href="assets/style.css" rel="stylesheet" />
|
|
<link href="assets/checkmark.css" rel="stylesheet" />
|
|
<script>
|
|
const { ipcRenderer } = require("electron");
|
|
const bonjour = require('bonjour')()
|
|
|
|
function showInstance(url) {
|
|
document.getElementById('availableInstancesContainer').style.display = "block"
|
|
const button = document.createElement("button")
|
|
button.onclick = () => addInstance(url)
|
|
button.classList.add("pure-material-button-contained")
|
|
button.textContent = url
|
|
document.getElementById('availableInstances').append(button)
|
|
}
|
|
|
|
ipcRenderer.send("get-instances");
|
|
ipcRenderer.on("get-instances", (event, result) => {
|
|
let instances = result
|
|
|
|
bonjour.find({ type: 'home-assistant' }, instance => {
|
|
if (instances.indexOf(instance.txt.internal_url) === -1) showInstance(instance.txt.internal_url)
|
|
if (instances.indexOf(instance.txt.external_url) === -1) showInstance(instance.txt.external_url)
|
|
})
|
|
})
|
|
|
|
function addInstance(url) {
|
|
ipcRenderer.send("ha-instance", url);
|
|
}
|
|
|
|
ipcRenderer.send("ha-instance");
|
|
|
|
let showCheckmark = false;
|
|
|
|
ipcRenderer.on("ha-instance", function (event, url) {
|
|
if (showCheckmark) {
|
|
document
|
|
.getElementById("check-wrapper")
|
|
.addEventListener(
|
|
"animationend",
|
|
() => (window.location.href = url)
|
|
);
|
|
} else window.location.href = url;
|
|
});
|
|
|
|
function isValidUrl(string) {
|
|
try {
|
|
new URL(string);
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function checkUrl() {
|
|
const url = document.getElementById("url").value;
|
|
|
|
if (!isValidUrl(url)) {
|
|
return;
|
|
}
|
|
|
|
fetch(url + "/auth/providers")
|
|
.then((response) => {
|
|
if (response.ok) {
|
|
document.getElementById("url").value = url;
|
|
document.getElementById("url").disabled = true;
|
|
document.getElementById("check-wrapper").style.display = "block";
|
|
document.getElementById("url-wrapper").style.display = "none";
|
|
showCheckmark = true;
|
|
ipcRenderer.send("ha-instance", url);
|
|
}
|
|
})
|
|
.catch((err) => {});
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<div class="content">
|
|
<div class="center header">
|
|
<img src="assets/favicon.png" height="52" /> Home Assistant
|
|
</div>
|
|
<div id="availableInstancesContainer" style="display:none;">
|
|
<div class="center">
|
|
<p>Available Instances: </p>
|
|
</div>
|
|
<div class="center">
|
|
<div id="availableInstances">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="center">
|
|
<p>Add Instance via URL</p>
|
|
</div>
|
|
<div class="center">
|
|
<div id="check-wrapper" class="success-checkmark">
|
|
<div class="check-icon">
|
|
<span class="icon-line line-tip"></span>
|
|
<span class="icon-line line-long"></span>
|
|
<div class="icon-circle"></div>
|
|
<div class="icon-fix"></div>
|
|
</div>
|
|
</div>
|
|
<div id="url-wrapper" class="group">
|
|
<input type="url" required="required" id="url" onkeyup="checkUrl()" />
|
|
<span class="highlight"></span>
|
|
<span class="bar"></span>
|
|
<label>Home Assistant URL</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="center">
|
|
<p>
|
|
<small class="grey"
|
|
>If the entered URL directs to a working Home Assistant instance,
|
|
you will be forwarded to the login page automatically.</small
|
|
>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|