@@ -68,6 +68,14 @@ UPower::UPower(const std::string& id, const Json::Value& config)
68
68
box_.signal_query_tooltip ().connect (sigc::mem_fun (*this , &UPower::show_tooltip_callback));
69
69
}
70
70
71
+ upowerWatcher_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
72
+ " org.freedesktop.UPower" ,
73
+ G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
74
+ upowerAppear,
75
+ upowerDisappear,
76
+ this ,
77
+ NULL );
78
+
71
79
GError* error = NULL ;
72
80
client = up_client_new_full (NULL , &error);
73
81
if (client == NULL ) {
@@ -106,6 +114,7 @@ UPower::~UPower() {
106
114
g_dbus_connection_signal_unsubscribe (login1_connection, login1_id);
107
115
login1_id = 0 ;
108
116
}
117
+ g_bus_unwatch_name (upowerWatcher_id);
109
118
removeDevices ();
110
119
}
111
120
@@ -142,6 +151,17 @@ void UPower::prepareForSleep_cb(GDBusConnection* system_bus, const gchar* sender
142
151
}
143
152
}
144
153
}
154
+ void UPower::upowerAppear (GDBusConnection* conn, const gchar* name, const gchar* name_owner,
155
+ gpointer data) {
156
+ UPower* up = static_cast <UPower*>(data);
157
+ up->upowerRunning = true ;
158
+ up->dp .emit ();
159
+ }
160
+ void UPower::upowerDisappear (GDBusConnection* conn, const gchar* name, gpointer data) {
161
+ UPower* up = static_cast <UPower*>(data);
162
+ up->upowerRunning = false ;
163
+ up->dp .emit ();
164
+ }
145
165
146
166
void UPower::removeDevice (const gchar* objectPath) {
147
167
std::lock_guard<std::mutex> guard (m_Mutex);
@@ -261,6 +281,14 @@ std::string UPower::timeToString(gint64 time) {
261
281
auto UPower::update () -> void {
262
282
std::lock_guard<std::mutex> guard (m_Mutex);
263
283
284
+ // Hide everything if the UPower service is not running
285
+ if (!upowerRunning) {
286
+ event_box_.set_visible (false );
287
+ // Call parent update
288
+ AModule::update ();
289
+ return ;
290
+ }
291
+
264
292
UpDeviceKind kind;
265
293
UpDeviceState state;
266
294
double percentage;
0 commit comments