Ubuntu – Is it possible to update the app indicator from code

application-developmentgtkindicatorrubyunity

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?

Best Answer

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.

Related Question