Sentry/assets/coffee/storage.coffee
Gregory Ballantine a23827355a
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Added a temperature reading for the current selected disk
2022-08-24 00:23:36 -04:00

61 lines
1.8 KiB
CoffeeScript

si = require('systeminformation')
window.onload = () ->
# Set the option selector to trigger an info grab on element change
document.getElementById('diskSelector').addEventListener('change', () ->
updateDiskInfo(@value)
)
# Load GPUs into the selector
loadDisks()
# Run the updateGpuInfo function with the default value of 0
updateDiskInfo()
# Start running our function to update the drive's temperature
setDiskTemp()
loadDisks = () ->
si.diskLayout()
.then((data) ->
i = 0
while i < data.length
optionElem = document.createElement('option')
diskName = data[i].name + ' (' + data[i].device + ')'
optionElem.innerText = diskName
optionElem.setAttribute('value', i)
document.getElementById('diskSelector').appendChild(optionElem)
i++
).catch((error) ->
console.error(error)
)
updateDiskInfo = (diskId = 0) ->
si.diskLayout()
.then((data) ->
document.getElementById('diskInfo').innerText = data[diskId].name
document.getElementById('diskPath').innerText = data[diskId].device
document.getElementById('diskType').innerText = data[diskId].type
document.getElementById('diskSize').innerText = formatBytes(data[diskId].size)
document.getElementById('diskVendor').innerText = data[diskId].vendor
).catch((error) ->
console.error(error)
)
setDiskTemp = (diskId = -1) ->
selector = document.getElementById('diskSelector')
if selector.length < 1
return
if (diskId = -1)
diskId = selector.value
si.diskLayout()
.then((data) ->
if (data[diskId].temperature)
document.getElementById('diskTemp').innerText = data[diskId].temperature
).catch((error) ->
console.error(error)
)
setTimeout(setDiskTemp, 2000)