forked from cwtch.im/cwtch-ui
Check DBUS Access before using Notification Manager
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);
|
||||
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);
|
||||
|
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue