Skip to content

Commit

Permalink
bug fixes on monitor restorations
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonary committed Dec 16, 2024
1 parent cdac0e5 commit 9ae3cea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
30 changes: 12 additions & 18 deletions Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,30 @@ function OnStreamStart() {
function OnStreamEnd($kwargs) {
Write-Debug "Starting OnStreamEnd function"


try {
# Check if the primary monitor is not active
Write-Debug "Checking if the primary monitor is active"
if (-not (IsPrimaryMonitorActive)) {
Write-Debug "Primary monitor is not active, attempting to set primary screen"
# Attempt to set the primary screen if it is not already set.
SetPrimaryScreen
}
Write-Debug "Now attempting to restore the primary monitor"
SetPrimaryScreen

# Check again if the primary monitor is not active after the first attempt to set it.
Write-Debug "Re-checking if the primary monitor is active"
if (-not (IsPrimaryMonitorActive)) {
if ((IsPrimaryMonitorActive)) {
# Primary monitor is active, return true.
Write-Host "Primary monitor(s) have been successfully restored!"
Write-Debug "Primary monitor is active, returning true"
return $true

}
else {
Write-Debug "Primary monitor failed to be restored, this is most likely because the display is currently not available."
if (($script:attempts++ -eq 1) -or ($script:attempts % 120 -eq 0)) {
# Output a message to the host indicating difficulty in restoring the display.
# This message is shown once initially, and then once every 10 minutes.
Write-Host "Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds... (this message will be suppressed to only show up once every 10 minutes)"
Write-Host "Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds... (this message will be suppressed to only show up once every 10-15 minutes)"
}

# Return false indicating the primary monitor is still not active.
# If we reached here, that indicates the first two attempts had failed.
Write-Debug "Returning false as primary monitor is still not active after two attempts"
return $false
}
else {
# Primary monitor is active, return true.
Write-Host "Primary monitor(s) have been successfully restored!"
Write-Debug "Primary monitor is active, returning true"
return $true
}
}
catch {
Write-Debug "Caught an exception, expected in cases like when the user has a TV as a primary display"
Expand Down
7 changes: 3 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ This tool automatically switches your main display to a dummy plug (or any virtu
## Change Log
**v2.0.2**
- More bug fixes that prevented primary monitor from restoring after a stream was ended.
**v2.0.1**
- Fixed a bug that prevented the primary monitor from restoring after ending a stream.
Expand All @@ -130,8 +133,4 @@ This tool automatically switches your main display to a dummy plug (or any virtu
- Added debug logging.
- Fixed monitor flicker issue related to known workarounds.
**v1.1.7 & v1.1.6**
- Various fixes for file handling, profile restoration, and logging.
- Integrated updates from the SunshineScript Installer template.
---

0 comments on commit 9ae3cea

Please sign in to comment.