6

I use ruby-libappindicator bindings to manage ubuntu application indicators.

I want to indicate if port 3000 is used by any application. Port checking isn't a problem but I also need to update the indicator (I want to show the green or red circle) when port becomes busy/free.

I can create a new indicator like this:

require "ruby-libappindicator"
indicator = AppIndicator::AppIndicator.new("test", "indicator-messages", AppIndicator::Category::APPLICATION_STATUS)
indicator.set_menu(Gtk::Menu.new)
indicator.set_status(AppIndicator::Status::ACTIVE)
Gtk.main

But after Gtk.main call the code "hangs" so I can't call any other method.

How I can update the appindicator icon after its creation?

1
  • It doesn't hang, Gtk.main enters the Gtk event loop, which blocks waiting for some event (system or user) to respond to.
    – mhall119
    Jan 9, 2014 at 23:23

3 Answers 3

1

Use g_timeout_add_seconds() from GLib to define a function that is called at regular intervals and in this function check the port and call indicator.set_status(...) is needed.

0

To save you writing your own indicator...

...you could install indicator-sysmonitor, then create a shell script to monitor the port and add your script to the indicator.

Rather than a red/green icon, you'd have to settle for a text label to indicate state.

1
  • I have added background script functionality to askubuntu.com/a/786708/67335 which would allow you check your port and display the result in the panel (still cannot change the icon though). Nov 6, 2021 at 0:46
0

You need to create a timer using GLib::Timeout.add_seconds, (or just add if you want to use milliseconds)

# ...

GLib::Timeout.add_seconds(2) do # every two seconds....
    app_indicator.set_icon '/path/to/icon.svg'
    true # returning false cancels the timer
end

Gtk.main

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .