From b65e62cd8c5d27941c4b4df5063e5403a673bb8e Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 26 May 2022 22:07:18 -0400 Subject: [PATCH] Added a selector to switch what info is showing on the GPU page --- assets/coffee/gpu.coffee | 36 +++++++++++++++++++++++++++++++----- assets/twig/gpu.twig | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/assets/coffee/gpu.coffee b/assets/coffee/gpu.coffee index 00a710f..d021370 100644 --- a/assets/coffee/gpu.coffee +++ b/assets/coffee/gpu.coffee @@ -1,13 +1,39 @@ si = require('systeminformation') window.onload = () -> + # Set the option selector to trigger an info grab on element change + document.getElementById('gpuSelector').addEventListener('change', () -> + updateGpuInfo(@value) + ) + + # Load GPUs into the selector + loadGpus() + + # Run the updateGpuInfo function with the default value of 0 + updateGpuInfo() + +loadGpus = () -> si.graphics() .then((data) -> - document.getElementById('gpuInfo').innerText = data.controllers[0].model - document.getElementById('gpuVendor').innerText = data.controllers[0].vendor - document.getElementById('gpuVendorId').innerText = data.controllers[0].vendorId - document.getElementById('gpuVram').innerText = data.controllers[0].vram + 'MB' - document.getElementById('gpuBus').innerText = data.controllers[0].bus + i = 0 + while i < data.controllers.length + optionElem = document.createElement('option') + optionElem.innerText = data.controllers[i].model + optionElem.setAttribute 'value', i + document.getElementById('gpuSelector').appendChild optionElem + i++ + ).catch((error) -> + console.error(error) + ) + +updateGpuInfo = (gpuId = 0) -> + si.graphics() + .then((data) -> + document.getElementById('gpuInfo').innerText = data.controllers[gpuId].model + document.getElementById('gpuVendor').innerText = data.controllers[gpuId].vendor + document.getElementById('gpuVendorId').innerText = data.controllers[gpuId].vendorId + document.getElementById('gpuVram').innerText = data.controllers[gpuId].vram + 'MB' + document.getElementById('gpuBus').innerText = data.controllers[gpuId].bus console.log(data) ).catch((error) -> console.error(error) diff --git a/assets/twig/gpu.twig b/assets/twig/gpu.twig index 6f6da78..3b85b70 100644 --- a/assets/twig/gpu.twig +++ b/assets/twig/gpu.twig @@ -9,6 +9,7 @@

GPU Info

+