AhmedSaadi0 / my-hyprland-config

a Linux "rice" configuration using Hyprland and AGS. It includes multiple themes and supports Google Material 3 themes.
212 stars 21 forks source link

SysTrayItem Click Problem #2

Open kursatufukcoskun opened 6 months ago

kursatufukcoskun commented 6 months ago

Hello Ahmed!

First of all, thank you very much for this excellent work.

I have a problem. An exception occurs when I click on some tray items. For example when I click to the bluetooth icon, it works and opens bluetooth manager application. But when I click on Spotify, NM Applet or Steam, an error occurs. The error is like this:

(com.github.Aylur.ags:377891): Gjs-CRITICAL **: 22:12:50.115: JS ERROR: TypeError: item.activate(...) is undefined SysTrayItem/onPrimaryClick/<@file:///home/kursatufukcoskun/.config/ags/modules/widgets/systray.js:26:14 setTimeout/source<@resource:///org/gnome/gjs/modules/esm/_timers.js:72:9 _init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34

(com.github.Aylur.ags:377891): Gjs-WARNING **: 22:12:50.954: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise: @resource:///org/gnome/gjs/modules/core/overrides/Gio.js:192:20 activate@resource:///com/github/Aylur/ags/service/systemtray.js:40:21 SysTrayItem/onPrimaryClick/<@file:///home/kursatufukcoskun/.config/ags/modules/widgets/systray.js:26:14 setTimeout/source<@resource:///org/gnome/gjs/modules/esm/_timers.js:72:9 _init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34

Operating System: Arch Linux AGS Version: 1.8.0

What do you think could be the problem? Thanks for your support.

AhmedSaadi0 commented 6 months ago

I'm short on time right now, but I've managed to implement a temporary workaround for the issue.

What I did was incorporate a try-catch block. Now, when a click occurs, if the icon has an associated action, it will execute seamlessly. If not, it will do nothing without the error.

Also I added rx_path, tx_path to handle network speed meter in the settings file

hardware: {
        network: {
            rx_path: '/sys/class/net/wlp0s20f3/statistics/tx_bytes',
            tx_path: '/sys/class/net/wlp0s20f3/statistics/tx_bytes',
        },
    },
kursatufukcoskun commented 5 months ago

Thank you for your answer.

But it didn't work for me. 2024-03-16-130643_hyprshot

AhmedSaadi0 commented 5 months ago

Actually right now I did not find any solutions. Even after looking into other people's config, I found that they do not use item.activate(event); instead they make both mouse buttons open the menu of the systray icon item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),

you can change that in the file modules/widgets/systray.js

    onPrimaryClick: (btn, event) => {
      try {
        item.activate(event).catch();
      } catch (TypeError) {}
    },
    onSecondaryClick: (btn) =>
      item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),

Into

    onPrimaryClick: (btn, event) => {
     item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),
    },
    onSecondaryClick: (btn) =>
      item.menu.popup_at_widget(btn, Gravity.SOUTH, Gravity.NORTH, null),

For me I'll stick with the original settings as they error only appears in the log and does not crash anything, I just ignore the action if nothing happens and use the second mouse click.