Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The application lacks a taskbar Icon #106

Open
orels1 opened this issue Oct 7, 2022 · 10 comments
Open

The application lacks a taskbar Icon #106

orels1 opened this issue Oct 7, 2022 · 10 comments
Labels
bug Something isn't working Windows

Comments

@orels1
Copy link

orels1 commented Oct 7, 2022

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 ottodobretsberger added bug Something isn't working Windows labels Oct 13, 2022
@ottodobretsberger
Copy link
Contributor

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

@orels1
Copy link
Author

orels1 commented Dec 15, 2022

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.

Bz0R8PRvBf.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
Copy link
Author

orels1 commented Dec 15, 2022

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
Copy link

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
Copy link
Author

orels1 commented Dec 18, 2022

@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
Copy link
Author

orels1 commented Jan 19, 2023

@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
Copy link

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
Copy link
Contributor

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

@wthks
Copy link

wthks commented Jun 2, 2023

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.

@Segergren
Copy link

I'm encountering the same issue and believe it is because the name matches the namespace? I resolved it by adding a space to the name. Thank you @orels1 for letting me know that it depends on the title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

7 participants