Check DBUS Access before using Notification Manager
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
ab3398aa3b
commit
b0a9531bdb
|
@ -64,7 +64,7 @@ class FlwtchState extends State<Flwtch> {
|
||||||
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
|
||||||
cwtch = CwtchGomobile(cwtchNotifier);
|
cwtch = CwtchGomobile(cwtchNotifier);
|
||||||
} else if (Platform.isLinux) {
|
} 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);
|
cwtch = CwtchFfi(cwtchNotifier);
|
||||||
} else {
|
} else {
|
||||||
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
|
||||||
|
|
|
@ -16,10 +16,28 @@ class NullNotificationsManager implements NotificationsManager {
|
||||||
// the standard dbus-powered linux desktop notifications.
|
// the standard dbus-powered linux desktop notifications.
|
||||||
class LinuxNotificationsManager implements NotificationsManager {
|
class LinuxNotificationsManager implements NotificationsManager {
|
||||||
int previous_id = 0;
|
int previous_id = 0;
|
||||||
final NotificationsClient client = NotificationsClient();
|
late NotificationsClient client;
|
||||||
LinuxNotificationsManager() {}
|
LinuxNotificationsManager(NotificationsClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
Future<void> notify(String message) async {
|
Future<void> notify(String message) async {
|
||||||
var icon_path = Uri.file(path.join(path.current, "cwtch.png"));
|
var iconPath = 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);
|
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();
|
||||||
|
}
|
Loading…
Reference in New Issue