Skip to content

Commit

Permalink
Implement media status check for idle detection
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed Oct 6, 2024
1 parent 58e08ce commit c577d9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/SettingsWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ export default class SettingsWindow extends PureComponent {
<SettingsOption title="Enable HDR support" input={this.renderToggle("enableHDR")} />
<SettingsOption title="Show console window (requires restart)" input={this.renderToggle("showConsole")} />
<SettingsOption title="Use Taskbar Registry" input={this.renderToggle("useTaskbarRegistry")} />
<SettingsOption title="Prevent idle detection while media is playing" input={this.renderToggle("detectIdleMedia")} />
<SettingsOption title="Disable Mouse Events (requires restart)" input={this.renderToggle("disableMouseEvents")} />

</div>
Expand Down
16 changes: 14 additions & 2 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ const defaultSettings = {
detectIdleTimeEnabled: false,
detectIdleTimeSeconds: 0,
detectIdleTimeMinutes: 5,
detectIdleCheckFullscreen: true,
detectIdleCheckFullscreen: false,
detectIdleMedia: false,
idleRestoreSeconds: 0,
wakeRestoreSeconds: 0,
hardwareRestoreSeconds: 0,
Expand Down Expand Up @@ -3891,11 +3892,22 @@ function isFocusedWindowFullscreen() {
}
}

function isMediaPlaying() {
try {
if(!settings.detectIdleMedia) return false;
const mediaPlaying = MediaStatus.getPlaybackStatus()
return (mediaPlaying === "playing" ? true : false)
} catch(e) {
console.log(e)
return false
}
}

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

if (!userIdleDimmed && settings.detectIdleTimeEnabled && !settings.disableAutoApply && idleTime >= getIdleSettingValue() && !isFocusedWindowFullscreen()) {
if (!userIdleDimmed && settings.detectIdleTimeEnabled && !settings.disableAutoApply && idleTime >= getIdleSettingValue() && !isFocusedWindowFullscreen() && !isMediaPlaying()) {
console.log(`\x1b[36mUser idle. Dimming displays.\x1b[0m`)
userIdleDimmed = true
idleMonitorBlock?.release?.()
Expand Down

0 comments on commit c577d9e

Please sign in to comment.