Aylur / astal

Building blocks for creating custom desktop shells
https://aylur.github.io/astal/
GNU Lesser General Public License v2.1
266 stars 28 forks source link

Tray item properties are `null` in TypeScript #105

Open anders130 opened 5 days ago

anders130 commented 5 days ago

Describe the bug Using the AstalTray-Library, the trayItem-properties are null. I get the following error, when I try to use the gicon property:

(gjs:130264): astal-CRITICAL **: 13:55:35.731: could not set property "gIcon" on [object instance wrapper GType:Icon jsobj@0x3061585e7038 native@0x35afeae0]: Error: Argument value may not be null
setProp@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:282:25
Widget@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:448:16
Icon@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:650:5
jsx@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:768:12
SystemTray/<.children</<@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:843:37
SystemTray/<.children<@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:827:22
as/bind2.transformFn@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:71:34
as/bind2.transformFn@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:71:40
get@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:80:21
subscribe/id<@file:///nix/store/573jasg2in2yy9g85wqdvwpa09r6z19p-my-shell/bin/.my-shell-wrapped:93:23
_init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:263:34

To Reproduce I have my new AGS shell in this repository: https://github.com/anders130/my-shell With nix, you can just run it like this:

nix run github:anders130/my-shell

The code with the problem is in the file widget/Bar/SystemTray.tsx. It is just the SysTray function from the astal js example.

import { App, Gdk } from "astal/gtk3"
import { bind } from "astal"
import Tray from "gi://AstalTray"

export default function SystemTray() {
    const tray = Tray.get_default()

    return (
        <box>
            {bind(tray, "items").as((items) =>
                items.map((item) => {
                    if (item.iconThemePath) App.add_icons(item.iconThemePath)

                    const menu = item.create_menu()

                    return (
                        <button
                            tooltipMarkup={bind(item, "tooltipMarkup")}
                            onDestroy={() => menu?.destroy()}
                            onClickRelease={(self) => {
                                menu?.popup_at_widget(
                                    self,
                                    Gdk.Gravity.SOUTH,
                                    Gdk.Gravity.NORTH,
                                    null,
                                )
                            }}
                        >
                            <icon gIcon={bind(item, "gicon")} />
                        </button>
                    )
                }),
            )}
        </box>
    )
}

Expected behavior A Box with multiple Buttons containing the icon of the respective system-tray application.

Additional context OS: NixOS 24.11.20241105.4aa3656 (Vicuna) x86_64 Kernel: Linux 6.11.6

kotontrion commented 5 days ago

The gicon property can only be null, when something went wrong while loading the icon from the tray app.

Are there other errors as well? Does this error appear only with a specific tray app?

Edit: Just tried your config. works fine for me on Arch. with spotify, signal and vesktop as running tray apps. Probably a special case of a tray app is causing the issue.

anders130 commented 5 days ago

All apps, i have in the tray, work on the old ags version (currently signal-desktop, ZapZap and vesktop). I also get no other errors. When i add a print statement to retrieve some info about the item, I also only get null and zeros like this: print(item.id, item.category, item.iconName, item.gicon)->null 0 null null

Edit: Still doesn't work, when i stop any of the applications and try with just one or two of them.

kotontrion commented 5 days ago

Your systemtray code is correct. Except that if (item.iconThemePath) App.add_icons(item.iconThemePath) is unnecessary, but that won't cause issues.

I can't reproduce it on Arch Linux, I haven't set up nix, so I can't test it there. Maybe you could check the #68 PR, if that fixes it for you. But as item.id is null for your as well, it probably won't. If this issue still persists with that PR I'll look into it more deeply.

anders130 commented 5 days ago

I tried to run that PR like this: flake.nix:

    inputs = {
        nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

        astal = {
            url = "github:aylur/astal?ref=feat/tray-gtk4";

            inputs.nixpkgs.follows = "nixpkgs";
        };

        ags = {
            url = "github:aylur/ags";
            inputs.nixpkgs.follows = "nixpkgs";
            inputs.astal.follows = "astal";
        };
    };

But when i try to run it I get these Errors.

error: builder for '/nix/store/pcsl5lrlriik579wix9jsamhyl335zxv-astal-tray-0.1.0.drv' failed with exit code 1;
       last 25 log lines:
       > WARNING: You should add the boolean check kwarg to the run_command call.
       >          It currently defaults to false,
       >          but it will default to true in future releases of meson.
       >          See also: https://github.com/mesonbuild/meson/issues/9300
       > Project name: astal-tray
       > Project version: 0.1.0
       > C compiler for the host machine: gcc (gcc 13.3.0 "gcc (GCC) 13.3.0")
       > C linker for the host machine: gcc ld.bfd 2.43.1
       > Vala compiler for the host machine: valac (valac 0.56.17)
       > Host machine cpu family: x86_64
       > Host machine cpu: x86_64
       > Configuring config.vala using configuration
       > Found pkg-config: YES (/nix/store/946chn5ja4yrvnnc5izwv792cc57xpy8-pkg-config-wrapper-0.29.2/bin/pkg-config) 0.29.2
       > Run-time dependency glib-2.0 found: YES 2.82.1
       > Run-time dependency gobject-2.0 found: YES 2.82.1
       > Run-time dependency gio-2.0 found: YES 2.82.1
       > Run-time dependency json-glib-1.0 found: YES 1.10.0
       > Run-time dependency gdk-pixbuf-2.0 found: YES 2.42.12
       > Did not find CMake 'cmake'
       > Found CMake: NO
       > Run-time dependency appmenu-glib-translator found: NO (tried pkgconfig)
       >
       > meson.build:42:2: ERROR: Dependency "appmenu-glib-translator" not found, tried pkgconfig
       >
       > A full log can be found at /build/tray/build/meson-logs/meson-log.txt
       For full logs, run 'nix log /nix/store/pcsl5lrlriik579wix9jsamhyl335zxv-astal-tray-0.1.0.drv'.
error: 1 dependencies of derivation '/nix/store/78pzc6qf96d8llc7xg19csf6c7p6v515-my-shell.drv' failed to build
warning: Git tree '/home/jesse/Projects/my-shell' is dirty
error: builder for '/nix/store/pcsl5lrlriik579wix9jsamhyl335zxv-astal-tray-0.1.0.drv' failed with exit code 1;
       last 25 log lines:
       > WARNING: You should add the boolean check kwarg to the run_command call.
       >          It currently defaults to false,
       >          but it will default to true in future releases of meson.
       >          See also: https://github.com/mesonbuild/meson/issues/9300
       > Project name: astal-tray
       > Project version: 0.1.0
       > C compiler for the host machine: gcc (gcc 13.3.0 "gcc (GCC) 13.3.0")
       > C linker for the host machine: gcc ld.bfd 2.43.1
       > Vala compiler for the host machine: valac (valac 0.56.17)
       > Host machine cpu family: x86_64
       > Host machine cpu: x86_64
       > Configuring config.vala using configuration
       > Found pkg-config: YES (/nix/store/946chn5ja4yrvnnc5izwv792cc57xpy8-pkg-config-wrapper-0.29.2/bin/pkg-config) 0.29.2
       > Run-time dependency glib-2.0 found: YES 2.82.1
       > Run-time dependency gobject-2.0 found: YES 2.82.1
       > Run-time dependency gio-2.0 found: YES 2.82.1
       > Run-time dependency json-glib-1.0 found: YES 1.10.0
       > Run-time dependency gdk-pixbuf-2.0 found: YES 2.42.12
       > Did not find CMake 'cmake'
       > Found CMake: NO
       > Run-time dependency appmenu-glib-translator found: NO (tried pkgconfig)
       >
       > meson.build:42:2: ERROR: Dependency "appmenu-glib-translator" not found, tried pkgconfig
       >
       > A full log can be found at /build/tray/build/meson-logs/meson-log.txt
       For full logs, run 'nix log /nix/store/pcsl5lrlriik579wix9jsamhyl335zxv-astal-tray-0.1.0.drv'.
error: 1 dependencies of derivation '/nix/store/r8avnwxa3m07k8sxy2cwbiq4km4zzx60-ags-2.0.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/aj5r6dz2gqclf7c1sy5lyvqnr0yv2w2m-nix-shell-env.drv' failed to build

I am not really familliar with meson and am unsure how to fix that bug.