Gio.Notification creates another instance when clicked


I’m trying to develop a Rust app which runs on background when closed (by using hide_on_close property on the ApplicationWindow) and send notifications to user with gio::Notificaiton.

Here is the example of creating the Application:

use adw::{Application};

fn main() {
    let application = Application::builder()


Then I send a notification anywhere inside the program:

    let notif = Notification::new(format!("{} minutes left!", total_minutes).as_str());

    app.send_notification(Some("time-warning"), &notif);

After I clicked the notification, it creates another instance of the application (calls on_activate again). This makes application create the UI windows all over again because all the UI initialized in on_activate function.

How can I handle notifications properly? Can I get an information in on_activate function if it’s activated by a notification or not?

(it is actually not spesific a question on Rust, it is about how GTK works generally)


The typical way to handle this is to check in your on_activate if the app was already activated. You can set a flag, or use to look to see if the windows are already created, or store a singleton for the windows, or anything you can come up with for the check.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.