jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
126 stars 13 forks source link

Destroy GTK events #25

Closed webmastak closed 5 years ago

webmastak commented 5 years ago

Hello. Please tell me how to destroy GTK events. I have an application that shows notifications, but there is one problem.

When a notification is viewed, i.e. an GTK event and no longer fall into this cycle for the next notifi:

        while !Gtk.events_pending
          Gtk.main_iteration
          break if notification.on_closed { next true }
        end 

I am poorly versed in GTK and tried different options, and the best thing I think is to restart the application from myself with this code:

        if Gtk.events_pending
          File.write LOCK, e.pubDate 
          parent = Process.pid
          fork = Process.fork do
            Process.exec("#{PROGRAM_NAME}")
          end 
          Process.kill(Signal::KILL, parent)                      
        end

But the thought do this without restarting the application does not give me rest. :)

jhass commented 5 years ago

Why don't you let Gtk run the main loop (Gtk.main_loop) and use a glib timeout (Glib.timeout(seconds) { callback }) to poll your feed? As long as you return true from the callback it'll keep being called at the given interval. See https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add and https://github.com/jhass/crystal-gobject/blob/master/src/g_lib/g_lib.cr

webmastak commented 5 years ago

Done :) Everything works as it should. You can view?