Check DBUS Access before using Notification Manager
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-06-28 14:32:26 -07:00
parent ab3398aa3b
commit b0a9531bdb
2 changed files with 23 additions and 5 deletions

View File

@ -64,7 +64,7 @@ class FlwtchState extends State<Flwtch> {
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
cwtch = CwtchGomobile(cwtchNotifier);
} else if (Platform.isLinux) {
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, LinuxNotificationsManager(), globalAppState);
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(), globalAppState);
cwtch = CwtchFfi(cwtchNotifier);
} else {
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);

View File

@ -16,10 +16,28 @@ class NullNotificationsManager implements NotificationsManager {
// the standard dbus-powered linux desktop notifications.
class LinuxNotificationsManager implements NotificationsManager {
int previous_id = 0;
final NotificationsClient client = NotificationsClient();
LinuxNotificationsManager() {}
late NotificationsClient client;
LinuxNotificationsManager(NotificationsClient client) {
this.client = client;
}
Future<void> notify(String message) async {
var icon_path = Uri.file(path.join(path.current, "cwtch.png"));
client.notify(message, appName: "cwtch", appIcon: icon_path.toString(), replacesId: this.previous_id).then((Notification value) => previous_id = value.id);
var iconPath = Uri.file(path.join(path.current, "cwtch.png"));
client.notify(message, appName: "cwtch",
appIcon: iconPath.toString(),
replacesId: this.previous_id).then((Notification value) =>
previous_id = value.id);
}
}
NotificationsManager newDesktopNotificationsManager() {
try {
// Test that we can actually access DBUS. Otherwise return a null
// notifications manager...
NotificationsClient client = NotificationsClient();
client.getCapabilities();
return LinuxNotificationsManager(client);
} catch (e) {
print("Attempted to access DBUS for notifications but failed. Switching off notifications.");
}
return NullNotificationsManager();
}