Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
catch NullReferenceException
add delay to the displaysettingschanged event to give the system time to finish making those adjustments
  • Loading branch information
Michael Higgins committed Feb 2, 2021
1 parent 652af12 commit a2be258
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions CenterTaskbar/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ private void Start()
Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, Desktop, TreeScope.Subtree, _uiaEventHandler);
}

private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
private async void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
await Task.Delay(3000);
Restart(sender, e);
}

Expand Down Expand Up @@ -401,7 +402,19 @@ private bool PositionLoop(AutomationElement trayWnd)
}

// Right bounds check
var rightBounds = SideBoundary(false, horizontal, taskList, scale, trayBounds);
int rightBounds;
int leftBounds;
try
{
rightBounds = SideBoundary(false, horizontal, taskList, scale, trayBounds);
leftBounds = SideBoundary(true, horizontal, taskList, scale, trayBounds);
}
catch (NullReferenceException)
{
Reset(trayWnd);
return true;
}

if (targetPos + size > rightBounds)
{
// Shift off center when the bar is too big
Expand All @@ -411,7 +424,6 @@ private bool PositionLoop(AutomationElement trayWnd)
}

// Left bounds check
var leftBounds = SideBoundary(true, horizontal, taskList, scale, trayBounds);
if (targetPos <= leftBounds)
{
// Prevent X position ending up beyond the normal left aligned position
Expand Down

0 comments on commit a2be258

Please sign in to comment.