From d2078fd450a3a631c57dc13c61b35af0ce27d070 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Jul 2014 14:51:22 -0500 Subject: Pair notify_init() with a shutdown call to notify_uninit() when the last Snap Decision is closed. This is needed in the dbusmock tests because libnotify's bus proxy needs to be closed. For production, this doesn't make much change: only that notify_uninit() is called once when the local Snap object goes out of scope in main(). --- src/snap.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/snap.cpp b/src/snap.cpp index fe8e7f2..45eb14e 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -216,14 +216,6 @@ public: m_interactive(get_interactive()), m_sound_builder(sound_builder) { - // ensure notify_init() is called once - // before we start popping up dialogs - static std::once_flag once; - std::call_once(once, [](){ - if(!notify_init("indicator-datetime-service")) - g_critical("libnotify initialization failed"); - }); - show(); } @@ -421,6 +413,8 @@ std::string get_alarm_uri(const Appointment& appointment, return uri; } +int32_t n_existing_snaps = 0; + } // unnamed namespace /*** @@ -432,10 +426,14 @@ Snap::Snap(const std::shared_ptr& clock, m_clock(clock), m_settings(settings) { + if (!n_existing_snaps++ && !notify_init("indicator-datetime-service")) + g_critical("libnotify initialization failed"); } Snap::~Snap() { + if (!--n_existing_snaps) + notify_uninit(); } void Snap::operator()(const Appointment& appointment, -- cgit v1.2.3