hass-agent / HASS.Agent

Unofficial development project for the HASS.Agent platform.
https://hass-agent.io
MIT License
300 stars 7 forks source link

Bug: Tray Icon WebView does not appear in the proper location when the Taskbar is not on the bottom of the screen #137

Open jbcodemonkey opened 1 month ago

jbcodemonkey commented 1 month ago

Describe the bug The logic to display the WebView when right-clicking the tray icon assumes the taskbar is on the bottom of the screen. If the taskbar is on the left or top, the WebView still draws as though the taskbar were on the bottom.

To Reproduce

  1. Set WebView on tray icon right-click
  2. Unlock Windows taskbar
  3. Move taskbar to left side of screen
  4. Lock the taskbar (to the tune of 'Rock the Casbah')
  5. Right-click the tray icon
  6. Observe the WebView in the lower-right of the screen

Expected behavior The WebView should open in an appropriate location based on the taskbar location.

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Responsible code: Appears to be lines 197-216 in HASS.Agent/Forms/WebView.cs I think the fix requires adding logic for taskbar location and different calculations based on that. I'm willing to give changes a shot if someone can offer some guidance.

    internal void MakeVisible()
    {
        if (IsClosingOrClosed()) return;

        try
        {
            // show ourselves
            Opacity = 100;

            // check if we need to move
            var x = Screen.PrimaryScreen.WorkingArea.Width - Width;
            var y = Screen.PrimaryScreen.WorkingArea.Height - Height;

            if (x != _webViewInfo.X || y != _webViewInfo.Y)
            {
                // yep
                _webViewInfo.X = x;
                _webViewInfo.Y = y;
                Location = new Point(_webViewInfo.X, _webViewInfo.Y);
            }
amadeo-alex commented 3 weeks ago

Looks like I've been able to fix it: BpCILb

All four positions work. I'll do a github build of the branch and put a link in here if you'd like to test - please note that it'll be based on 2.1.0-beta3.

Will be included with 2.1.0-beta4.

jbcodemonkey commented 3 weeks ago

Thanks for your efforts!! I’d be happy to test if you have a build link.

amadeo-alex commented 3 weeks ago

My pleasure :) https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.0-beta4-webview-taskbar

Standard disclaimer: Since it's a beta build and a test one in addition - please backup your config before installing. If you'd like to know what changes were made in 2.1.0 betas - https://github.com/hass-agent/HASS.Agent/releases

jbcodemonkey commented 3 weeks ago

Success!! Pops up right where it should.

You've solved this problem for three, maybe even four people. Thank you. :)