mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-20 06:36:40 +02:00
deal with unavailable dbus server (Issue: #365)
If the dbus server cannot be started or is not available, calling a notification would result in an exception. During initialization check that we can get the server information, and disable notifications if this is not possible. Note: we change dnotify.d from the originally distributed version to include a check for availability function.
This commit is contained in:
parent
8b8cf9c777
commit
1f955c82be
11
src/log.d
11
src/log.d
|
@ -41,6 +41,17 @@ void init(string logDir)
|
||||||
|
|
||||||
void setNotifications(bool value)
|
void setNotifications(bool value)
|
||||||
{
|
{
|
||||||
|
version(Notifications) {
|
||||||
|
// if we try to enable notifications, check for server availability
|
||||||
|
// and disable in case dbus server is not reachable
|
||||||
|
if (value) {
|
||||||
|
auto serverAvailable = dnotify.check_availability();
|
||||||
|
if (!serverAvailable) {
|
||||||
|
log("Notification (dbus) server not available, disabling");
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
doNotifications = value;
|
doNotifications = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,20 @@ class NotificationError : Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_availability() {
|
||||||
|
// notify_init might return without dbus server actually started
|
||||||
|
// try to check for running dbus server
|
||||||
|
char **ret_name;
|
||||||
|
char **ret_vendor;
|
||||||
|
char **ret_version;
|
||||||
|
char **ret_spec_version;
|
||||||
|
bool ret;
|
||||||
|
try {
|
||||||
|
return notify_get_server_info(ret_name, ret_vendor, ret_version, ret_spec_version);
|
||||||
|
} catch (NotificationError e) {
|
||||||
|
throw new NotificationError("Cannot find dbus server!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init(in char[] name) {
|
void init(in char[] name) {
|
||||||
notify_init(name.toStringz());
|
notify_init(name.toStringz());
|
||||||
|
@ -306,4 +320,4 @@ version(TestMain) {
|
||||||
n.timeout = 3;
|
n.timeout = 3;
|
||||||
n.show();
|
n.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue