tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
909 stars 74 forks source link

The application lacks a taskbar Icon #106

Open orels1 opened 2 years ago

orels1 commented 2 years ago

First of all, wanted to say that Photino is an absolute delight to work with thus far. We were able to get cross-platform application going in a matter of days with most of functionality we need handled.

One thing that I am unable to get working so far is taskbar icons, though. At least on Windows 11 (22H2) - the IconFile option does set it in the window titlebar, but the taskbar still shows a generic icon, like this:

image

If I am missing something, I apologize, but if it is just not something Photino.NET/Native supports, I would love to know as well!

I am setting the icon like this

        IconPath = Path.Combine(my,path,segments);
        MainWindow = new PhotinoWindow
            {
                Title = WindowTitle,
                UseOsDefaultSize = false,
                Size = new Size(1200,800),
                Centered = true,
                Resizable = true,
                IconFile = IconPath
            };

And am using the .ico file on Windows

Setting the ApplicationIcon in the .csproj also didn't do the trick, it is being set on the .exe, but the taskbar one is still missing. According to this github issue it is indeed grabbed from the window itself, so I assume Photino should be able to affect that.

ottodobretsberger commented 2 years ago

Thank you for letting us know. We will address this issue in one of our next releases.

orels1 commented 1 year ago

So I debugged a lot more and found out that it depends on the Title property.

If I pass Photino for .NET Demo App (as in the .Net sample) it doesn't show an icon If I add a space at the end - it does! Some other symbols work and I was unable to establish a pattern, It doesn't seem to be string length based in particular, I can pack a ton of numbers and it still works, but for other names it breaks very early on, so I'm not sure what is happening there, but I felt like this might be useful information

Here's the video evidence.

https://user-images.githubusercontent.com/3798928/207782630-9f37942a-fb52-4a54-bbfe-b6b3a86332f6.mp4

I'm not really a C++ person but a cursory look made me a bit suspicious of these in Photino.Windows.cpp

    _windowTitle = new wchar_t[256];

    if (initParams->TitleWide != NULL)
    {
        WinToast::instance()->setAppName(initParams->TitleWide);
        WinToast::instance()->setAppUserModelId(initParams->TitleWide);
        wcscpy(_windowTitle, initParams->TitleWide);
    }
    else
        _windowTitle[0] = 0;
void Photino::SetTitle(AutoString title)
{
    if (wcslen(title) > 255)
    {
        for (int i = 0; i < 256; i++)
            _windowTitle[i] = title[i];
        _windowTitle[255] = 0;
    }
    else
        wcscpy(_windowTitle, title);
    SetWindowText(_hWnd, title);
    WinToast::instance()->setAppName(title);
    WinToast::instance()->setAppUserModelId(title);
}
orels1 commented 1 year ago

Under further investigations I also found cases where it would show a default .NET icon like this image And in some rare rare cases it would show the correct icon

zeroskyx commented 1 year ago

I've also had mixed results with getting the icon to work in Windows 11; as @orels1 stated, sometimes it is the actual icon, and sometimes the generic .NET icon.

I believe it has something to do how Windows 11 (I never had the issue with Windows 10) groups taskbar icons; the issue appears to be here in Photino.Native. It sets the unique application id to the title of the window.

Hypothesis: this is not an issue the first time as the name/ id is simply matched to the executing application (which is dotnet.exe when you're running in a debugger). The problem arises when you publish the application (ie self-contained) and run it again. Apparently Windows 11 gets confused with the same application id and a new application location (ie not dotnet.exe but YourApplication.exe).

For me the latter results in the problem that I get the generic .NET Icon in the taskbar, and when i right-click on it, and right-click on the application name again and select Properties the application on the taskbar is actually C:\Program Files\dotnet\dotnet.exe and NOT the published application.

I was able to fix the issue by ensuring that the window titles (and thus, app ids) are unique between DEBUG and RELEASE:

string WindowTitle;
#if DEBUG
  WindowTitle = "My Application (Debug)";
#else
  WindowTitle = "My Application (Release)";
#endif

Hope this helps.

orels1 commented 1 year ago

@zeroskyx oh! That might explain why I was getting such inconsistent results while trying to debug. I will try this out and report back when I get a chance. Thank you for the pointers!

orels1 commented 1 year ago

@zeroskyx thx for the pointers! Clearing out all the old leftover shortcuts generated in my start menu and making a use of #if DEBUG have addressed the taskbar icon issues.

nsimpson-elv commented 1 year ago

It really seems to me that this issue should not have been closed. Is there any chance you can expose the setAppUserModelId() from Photino.Native through Photino.NET so that we can set this from C#?

As far as I can tell from extensive googling, Windows using the application user model ID to determine how to group taskbar icons. This means that the current default behavior here of dumping the title into the app ID causes two problems: 1) you get weird and unpredictable blank taskbar icon behavior sometimes, and 2) Windows cannot figure out how to group Photino windows in a process. In particular, if you use Photino in conjunction with an existing WinForms application, for example, you get two taskbar icons instead of one (one of which is possibly blank), and if you have multiple Photino windows in the same process, they each get their own taskbar icons instead of being grouped together properly.

Electron and other similar platforms allow the user to set the appUserModelId for this reason, and I think it would be helpful if Photino does the same.

ottodobretsberger commented 1 year ago

Thank you for pointing that out. I have re-opened the issue and set some labels to look into this again.

wthks commented 1 year ago

After doing some tests I noticed that when you use .SetMinimized(true) that on Windows 11 the icon is displayed in the taskbar.

I don't know why this happens, but it works. Can someone reproduce this.