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.AutoReplay = false
|
||||
sse.CreateStream("weather")
|
||||
|
||||
s := services.NewSystemService(sse)
|
||||
b := services.NewBookmarkService()
|
||||
|
|
|
@ -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 = new EventSource('/sse?stream=system');
|
||||
systemSSESource.onmessage = (e) => {
|
||||
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,15 +63,6 @@ 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 + '%';
|
||||
|
|
Loading…
Reference in a new issue