Remove weather
This commit is contained in:
parent
76741a9295
commit
e253825635
2 changed files with 14 additions and 39 deletions
1
main.go
1
main.go
|
@ -40,7 +40,6 @@ func main() {
|
||||||
|
|
||||||
sse := sse.New()
|
sse := sse.New()
|
||||||
sse.AutoReplay = false
|
sse.AutoReplay = false
|
||||||
sse.CreateStream("weather")
|
|
||||||
|
|
||||||
s := services.NewSystemService(sse)
|
s := services.NewSystemService(sse)
|
||||||
b := services.NewBookmarkService()
|
b := services.NewBookmarkService()
|
||||||
|
|
|
@ -9,8 +9,8 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI
|
||||||
<section class="grid gap-14">
|
<section class="grid gap-14">
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3 select-none">
|
<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--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--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)
|
@components.Uptime(static.Host.Architecture,"systemUptimePercentage",live.Uptime)
|
||||||
</div>
|
</div>
|
||||||
<div class="grid gap-4">
|
<div class="grid gap-4">
|
||||||
|
@ -42,29 +42,14 @@ templ Home(title string, bookmarks *services.Bookmarks, static *services.StaticI
|
||||||
</section>
|
</section>
|
||||||
<script>
|
<script>
|
||||||
let systemSSESource = null;
|
let systemSSESource = null;
|
||||||
let weatherSSESource = null;
|
|
||||||
addEventListener('beforeunload', () => {
|
addEventListener('beforeunload', () => {
|
||||||
systemSSESource && systemSSESource.close();
|
systemSSESource && systemSSESource.close();
|
||||||
weatherSSESource && weatherSSESource.close();
|
|
||||||
});
|
});
|
||||||
systemSSESource = new EventSource('/sse?stream=system');
|
systemSSESource = new EventSource('/sse?stream=system');
|
||||||
systemSSESource.onmessage = (e) => {
|
systemSSESource.onmessage = (e) => {
|
||||||
const parsed = JSON.parse(e.data);
|
const parsed = JSON.parse(e.data);
|
||||||
replaceSystem(parsed);
|
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
|
// system elements
|
||||||
const systemCpuPercentage = document.getElementById('systemCpuPercentage');
|
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 uptimeMinutes = document.getElementById('uptimeMinutes');
|
||||||
const uptimeSeconds = document.getElementById('uptimeSeconds');
|
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) {
|
function replaceSystem(parsed) {
|
||||||
systemCpuPercentage.style = 'width:' + parsed.cpu + '%';
|
systemCpuPercentage.style = 'width:' + parsed.cpu + '%';
|
||||||
systemRamPercentage.style = 'width:' + parsed.ram.percentage + '%';
|
systemRamPercentage.style = 'width:' + parsed.ram.percentage + '%';
|
||||||
systemRamValue.innerText = parsed.ram.value;
|
systemRamValue.innerText = parsed.ram.value;
|
||||||
systemDiskPercentage.style = 'width:' + parsed.disk.percentage + '%';
|
systemDiskPercentage.style = 'width:' + parsed.disk.percentage + '%';
|
||||||
systemDiskValue.innerText = parsed.disk.value;
|
systemDiskValue.innerText = parsed.disk.value;
|
||||||
systemUptimePercentage.style = 'width:' + parsed.uptime.percentage + '%';
|
systemUptimePercentage.style = 'width:' + parsed.uptime.percentage + '%';
|
||||||
uptimeDays.style = '--value:' + parsed.uptime.days;
|
uptimeDays.style = '--value:' + parsed.uptime.days;
|
||||||
uptimeHours.style = '--value:' + parsed.uptime.hours;
|
uptimeHours.style = '--value:' + parsed.uptime.hours;
|
||||||
uptimeMinutes.style = '--value:' + parsed.uptime.minutes;
|
uptimeMinutes.style = '--value:' + parsed.uptime.minutes;
|
||||||
uptimeSeconds.style = '--value:' + parsed.uptime.seconds;
|
uptimeSeconds.style = '--value:' + parsed.uptime.seconds;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue