Skip to content

Commit

Permalink
Additional idleCheckShort try-catch
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed Nov 23, 2022
1 parent ecde961 commit b1e4551
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2894,36 +2894,40 @@ async function startIdleCheckShort() {
}

function idleCheckShort() {
const idleTime = powerMonitor.getSystemIdleTime()
try {
const idleTime = powerMonitor.getSystemIdleTime()

if (!userIdleDimmed && settings.detectIdleTime * 1 > 0 && idleTime >= settings.detectIdleTime) {
console.log(`\x1b[36mUser idle. Dimming displays.\x1b[0m`)
userIdleDimmed = true
try {
Object.values(monitors)?.forEach((monitor) => {
updateBrightness(monitor.id, 0, true, monitor.brightnessType)
})
} catch(e) {
console.log(`Error dimming displays`, e)
if (!userIdleDimmed && settings.detectIdleTime * 1 > 0 && idleTime >= settings.detectIdleTime) {
console.log(`\x1b[36mUser idle. Dimming displays.\x1b[0m`)
userIdleDimmed = true
try {
Object.values(monitors)?.forEach((monitor) => {
updateBrightness(monitor.id, 0, true, monitor.brightnessType)
})
} catch(e) {
console.log(`Error dimming displays`, e)
}
}
}

if(isUserIdle && idleTime < lastIdleTime) {
// Wake up
console.log(`\x1b[36mUser no longer idle after ${lastIdleTime} seconds.\x1b[0m`)
clearInterval(notIdleMonitor)
notIdleMonitor = false
if(!settings.disableAutoApply) setKnownBrightness(false);
// Wait a little longer, re-apply known brightness in case monitors take a moment, and finish up
setTimeout(() => {

if(isUserIdle && idleTime < lastIdleTime) {
// Wake up
console.log(`\x1b[36mUser no longer idle after ${lastIdleTime} seconds.\x1b[0m`)
clearInterval(notIdleMonitor)
notIdleMonitor = false
if(!settings.disableAutoApply) setKnownBrightness(false);
isUserIdle = false
userIdleDimmed = false
handleBackgroundUpdate() // Apply ToD adjustments, if needed
}, 3000)

// Wait a little longer, re-apply known brightness in case monitors take a moment, and finish up
setTimeout(() => {
if(!settings.disableAutoApply) setKnownBrightness(false);
isUserIdle = false
userIdleDimmed = false
handleBackgroundUpdate() // Apply ToD adjustments, if needed
}, 3000)

}
lastIdleTime = idleTime
} catch(e) {
console.log('Error in idleCheckShort', e)
}
lastIdleTime = idleTime
}


Expand Down

0 comments on commit b1e4551

Please sign in to comment.