Remove weather

This commit is contained in:
Florian Hoss 2024-03-12 16:05:20 +01:00
parent 76741a9295
commit e253825635
2 changed files with 14 additions and 39 deletions

View file

@ -40,7 +40,6 @@ func main() {
sse := sse.New()
sse.AutoReplay = false
sse.CreateStream("weather")
s := services.NewSystemService(sse)
b := services.NewBookmarkService()

View file

@ -9,8 +9,8 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI
<section class="grid gap-14">
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none">
@components.System("icon-[bi--cpu]",static.CPU.Name,"",static.CPU.Threads,"systemCpuPercentage","",live.CPU)
@components.System("icon-[bi--memory]",live.Ram.Value,fmt.Sprintf(" | %s", static.Ram.Total),static.Ram.Swap,"systemRamPercentage","systemRamValue",live.Ram.Percentage)
@components.System("icon-[bi--nvme]",live.Disk.Value,fmt.Sprintf(" | %s", static.Disk.Total),static.Disk.Partitions,"systemDiskPercentage","systemDiskValue",live.Disk.Percentage)
@components.System("icon-[bi--memory]",live.Ram.Value,fmt.Sprintf(" | %s", static.Ram.Total),static.Ram.Swap,"systemRamPercentage","systemRamValue",live.Ram.Percentage)
@components.Uptime(static.Host.Architecture,"systemUptimePercentage",live.Uptime)
</div>
<div class="grid gap-4">
@ -42,29 +42,14 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI
</section>
<script>
let systemSSESource = null;
let weatherSSESource = null;
addEventListener('beforeunload', () => {
systemSSESource && systemSSESource.close();
weatherSSESource && weatherSSESource.close();
systemSSESource && systemSSESource.close();
});
systemSSESource = new EventSource('/sse?stream=system');
systemSSESource.onmessage = (e) => {
const parsed = JSON.parse(e.data);
replaceSystem(parsed);
const parsed = JSON.parse(e.data);
replaceSystem(parsed);
};
weatherSSESource = new EventSource('/sse?stream=weather');
weatherSSESource.onmessage = (e) => {
const parsed = JSON.parse(e.data);
replaceWeather(parsed);
};
// weather elements
const weatherIcon = document.getElementById('weatherIcon');
const weatherTemp = document.getElementById('weatherTemp');
const weatherDescription = document.getElementById('weatherDescription');
const weatherHumidity = document.getElementById('weatherHumidity');
const weatherSunrise = document.getElementById('weatherSunrise');
const weatherSunset = document.getElementById('weatherSunset');
// system elements
const systemCpuPercentage = document.getElementById('systemCpuPercentage');
@ -78,26 +63,17 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI
const uptimeMinutes = document.getElementById('uptimeMinutes');
const uptimeSeconds = document.getElementById('uptimeSeconds');
function replaceWeather(parsed) {
weatherIcon.setAttribute('xlink:href', '#' + parsed.icon);
weatherTemp.innerText = parsed.temp;
weatherDescription.innerText = parsed.description;
weatherHumidity.innerText = parsed.humidity + '%';
weatherSunrise.innerText = parsed.sunrise;
weatherSunset.innerText = parsed.sunset;
}
function replaceSystem(parsed) {
systemCpuPercentage.style = 'width:' + parsed.cpu + '%';
systemRamPercentage.style = 'width:' + parsed.ram.percentage + '%';
systemRamValue.innerText = parsed.ram.value;
systemDiskPercentage.style = 'width:' + parsed.disk.percentage + '%';
systemDiskValue.innerText = parsed.disk.value;
systemUptimePercentage.style = 'width:' + parsed.uptime.percentage + '%';
uptimeDays.style = '--value:' + parsed.uptime.days;
uptimeHours.style = '--value:' + parsed.uptime.hours;
uptimeMinutes.style = '--value:' + parsed.uptime.minutes;
uptimeSeconds.style = '--value:' + parsed.uptime.seconds;
systemCpuPercentage.style = 'width:' + parsed.cpu + '%';
systemRamPercentage.style = 'width:' + parsed.ram.percentage + '%';
systemRamValue.innerText = parsed.ram.value;
systemDiskPercentage.style = 'width:' + parsed.disk.percentage + '%';
systemDiskValue.innerText = parsed.disk.value;
systemUptimePercentage.style = 'width:' + parsed.uptime.percentage + '%';
uptimeDays.style = '--value:' + parsed.uptime.days;
uptimeHours.style = '--value:' + parsed.uptime.hours;
uptimeMinutes.style = '--value:' + parsed.uptime.minutes;
uptimeSeconds.style = '--value:' + parsed.uptime.seconds;
}
</script>
}