moson-mo / mntray

A Manjaro Linux announcements notification app
MIT License
11 stars 0 forks source link

The tray icon does not show up after logging in - Manjaro Gnome #4

Closed lakotamm closed 3 years ago

lakotamm commented 3 years ago

I have 2 laptops running Manjaro Gnome Testing and both of them suffer from a disappearing tray icon on the 1st start.

mntray: 1.1.3-1 OS: Manjaro Gnome Branch: Testing Update Date: 7.12.2020 Kernel: 5.9.12-1-MANJARO Display Manager: X11 Used display driver: Intel modesetting

1st Laptop (Lenovo T490, i7-8565U, MX250, Switchin GPU to Intel only using Bbswitch): Mntray properly turns on only on the 1st login. If I log out and log in again, the tray icon will not be functional and if I try to launch mntray again, I will be met with a message mntray already running, exiting.

2nd Laptop (Acer V3-575g, i5-6200U, Switching GPU to Intel only using Nouveau) After logging in (no matter when), the tray icon will not be functional and if I try to launch mntray again, I will be met with a message mntray already running, exiting.

Debugging steps which I tried:

config file: { "Version": "1.1.3", "ServerURL": "http://manjaro.moson.eu:10111/news", "MaxArticles": 15, "AvailableCategories": [ "Testing Updates", "Stable Updates", "Stable Staging Updates", "Unstable Updates", "Twitter", "News", "Releases", "ARM News", "ARM Releases", "ARM Stable Updates", "ARM Testing Updates", "ARM Unstable Updates" ], "Categories": [ "Testing Updates" ], "AddCategoriesBranch": [], "RefreshInterval": 600, "HideNoNews": false, "Autostart": true, "ErrorNotifications": true, "DelayAfterStart": 60, "SetCategoriesFromBranch": false }

I am up for doing more debugging to get this fixed.

moson-mo commented 3 years ago

Hi,

Although I can't reproduce it on my end, I have some idea what it could be. Maybe the lock file is not properly removed when logging out.

Could you try the following:

  1. Log out
  2. Log in again (icon gone)
  3. rm /tmp/mntray.lock
  4. run mntray

Does that start the application?

lakotamm commented 3 years ago

I did a few tests on both laptops. The process you wrote of course works. However, I end up with 2 running mntrays (and only 1 tray icon), meaning that 1 mntray simply keeps running in the background without any use.

I tested the hypothesis that there is an issue with the lock file. I have not seen any evidence proving that so far. I went several times into tty2, while being logged out, right from the login page (gdm-prime), and did not see the lock file in the temp folder. I saw the mntray.lock file only when it was actually running (also when the icon was not appearing). Also, it was always created at login time.

Interesting observation Lenovo T490:

Acer V3 575G:

moson-mo commented 3 years ago

Hmm ok.

What if you add a delay in the autostart file?

X-GNOME-Autostart-Delay=5

lakotamm commented 3 years ago

X-GNOME-Autostart-Delay=5 This has no impact. However, this fixes the issue: Exec=bash -c "sleep 5 && /usr/bin/mntray" Waw. I have no clue why one works and the other one does not.

moson-mo commented 3 years ago

Ok, sounds like it's some race condition where the systray icon is initialized before the systray is available.

I'll have a look over the weekend. There is some method in qt to check if systray is constructed or not i think.

lakotamm commented 3 years ago

Cool! Let me know when there is something more to test! :-)

moson-mo commented 3 years ago

Could you try it with the "systray" branch? I've added some code there to wait until systray is available.

lakotamm commented 3 years ago

I do not have good news. I tested the code (ensuring 10 times that I have the right version) and it did not fix the issue. I even tried to test whether hardcoding a 5s delay instead of your patch would solve the issue, and it did not. time.Sleep(5000 * time.Millisecond)

EDIT: However, if I put the delay at the beginning of the function NewTrayIcon, the issue disappears. Let me try to find where the thing actually breaks down.

lakotamm commented 3 years ago

In the file tray.go in the function NewTrayIcon:


// set icons
ico = gui.QIcon_FromTheme2("mntray-regular", gui.NewQIcon5(":assets/images/mntray-regular.png"))
icoNew = gui.QIcon_FromTheme2("mntray-news", gui.NewQIcon5(":assets/images/mntray-news.png"))
icoChecked = gui.QIcon_FromTheme2("emblem-checked", gui.QIcon_FromTheme2("emblem-default", gui.QIcon_FromTheme("dialog-yes")))
icoExit = gui.QIcon_FromTheme("application-exit")
icoUnchecked = gui.QIcon_FromTheme2("vcs-removed", gui.QIcon_FromTheme("emblem-draft"))

//this is the point where the program needs to wait (a single line lower and it breaks)
time.Sleep(5000 * time.Millisecond)

// create icon
t.Icon = NewSystemTrayIcon(t.App)
t.Icon.SetIcon(ico)
t.Conf, err = NewConfig()
if err != nil {
    return err
}

To me, it seems like calling the function NewSystemTrayIcon too early, when the panel is not generated yet, breaks the program. But again, my knowledge of Linux app programming is nothing.

I tried different delays: 100ms - too short, 500ms, sometimes worked, 1s worked, 2s worked for sure (tested on Acer V3-575g with i5-6200u).

moson-mo commented 3 years ago

Thank you for your testing effort. It's strange that I can not reproduce the issue in my VM.

Could you try the following code for the icon creation?

// create icon
for !ui.QSystemTrayIcon_IsSystemTrayAvailable() {
    time.Sleep(100 * time.Millisecond)
}
t.Icon = NewSystemTrayIcon(t.App)
t.Icon.SetIcon(ico)
t.Conf, err = NewConfig()
if err != nil {
    return err
}

That should loop and wait 100ms every iteration until the systray is available. Afterwards it continues with the creation.

lakotamm commented 3 years ago

I think that calling ui.QSystemTrayIcon_IsSystemTrayAvailable() causes the issue as well.

I tried your code and it did not work. So I played with several options:

Regarding the VM - I thought that could be a good idea to find out why it breaks on my PC and not on yours. So I set up a VM in Virtualbox:

Latest Manjaro Gnome - https://dotsrc.dl.osdn.net/osdn/storage/g/m/ma/manjaro/gnome/20.2/manjaro-gnome-20.2-201203-linux59.iso RAM - 8GB (DDR3) Drive - 28GB (Sata SSD) GPU - VMSVGA, 3D acceleration enabled Swap with Hibernation enabled (so around 9.4GB) CPU - 4 CPU threads on a Dual-core 2.7GHz CPU. Login/password is required on start up.

The only thing I did on the VM was to install mntray using pamac install mntray, I launched it (to create the config files) and restarted. After the restart, I was welcomed with a not-working tray icon, and launching mntray resulted in mntray already running, exiting message.

I think that the key point is to run the VM with only a very limited CPU power. I can see that while Gnome is launching, it is loading the CPU to 100%. Could you try to run it with a comparable - or lower CPU performance?

EDIT: after restarting the VM several times, mntray started to - inconsistently work. This is confusing and it means that my theory about the variable CPU performance is likely wrong. I will put some more time into attempting to getting consistent results.

moson-mo commented 3 years ago

The latest gnome ISO does not even work for me in a VM, after entering the user details, it just does not do anything and after a restart I can't log in.

Anyways. I was actually hoping QSystemTrayIcon_IsSystemTrayAvailable() would return false if the systray is not yet initialized (which seems not be the case though). Then it would have looped and waited until it returned true and then continued constructing the tray icon...

I could of course just hard-code a 2 second sleep as you did in your tests, but that feels just like an ugly workaround :wink:

even this would cause the issue: if ui.QSystemTrayIcon_IsSystemTrayAvailable() { time.Sleep(2000 time.Millisecond) } else { time.Sleep(2000 time.Millisecond) }

That's weird though. In any case it would wait 2 seconds (which was fixing your issue before) :thinking:

Maybe one last try before turning onto the dirty road:

// create icon
t.Icon = NewSystemTrayIcon2(ico, t.App)
t.Conf, err = NewConfig()
if err != nil {
    return err
}

Here it uses another construction method for creating the tray icon, I doubt it makes a difference, but maybe worth a try...

lakotamm commented 3 years ago

// create icon t.Icon = NewSystemTrayIcon2(ico, t.App) t.Conf, err = NewConfig() if err != nil { return err }

No improvement. I still have to add a 2 second delay before calling NewSystemTrayIcon2

I do not think that a 2 second delay is a good solution. There might still be scenarios where it breaks, an unfortunately, there can be other issues related to this. For example - I experienced that my Gnome Extensions were sometimes all getting disabled.

I created a Virtual box machine which you can simply import if you want to do some testing. https://drive.google.com/file/d/15x0Klgf-FH5Iz_HeWnKkqaZV_K3e8awZ/view?usp=sharing

Login Password: TestManjaro

moson-mo commented 3 years ago

I can reproduce the issue on your VM (still no clue why it always works in my own VM).

edit switching from VBoxSVGA to VMSVGA on my VM, I can also reproduce it now

I tried with another application "ksnip" using QSystemTrayIcon. Same problem with that one...

Found this from the Arch forum: https://bbs.archlinux.org/viewtopic.php?id=259255

With this extension, the icons show up: https://extensions.gnome.org/extension/1503/tray-icons/

(for some reason the mntray icon looks weird though)

edit Also when you enable "Unite" in the extensions, it will show the missing tray icon(s)

lakotamm commented 3 years ago

I can reproduce the issue on your VM (still no clue why it always works in my own VM).

edit switching from VBoxSVGA to VMSVGA on my VM, I can also reproduce it now

This is also my experience. I guess it could be similar with different GPUs and drivers.

Using the extension "tray-icons" or "unity" extension fixes the issue, but the effect is inconsistent in between different configurations. I am getting different icon backgrounds and different zoom levels of icons + there are some side effects.

I do not really understand why certain apps have really great tray icon behavior in Gnome (e.g. Zulip) and why some have issues (e.g. Mattermost, or mntray). However, I guess this is to a certain extent an issue with Gnome itself, and there is not too much we can do about it.