-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flutter_local_notifications] Linux support #1208
Conversation
@MaikuB |
Is it possible to schedule notifications on Linux? I'm not familiar with Linux but my research shows that it's possible but wasn't done in #888. The reason I bring this up is I don't know if you'd need to go with the C++ approach to do so. I'm also not familiar with what the performance impact will be like but if it's minimal enough that Canonical themselves are happy to use DBus and it suits the purposes then that's fine. Note that I'm not familiar with the Linux APIs and it's been a long time since I looked at C++ so DBus would be my preference from maintenance perspective. On that note, if you're looking at C++, what could also work is for the Linux implementation is hosted and published separately and it becomes an endorsed implementation. |
In any case, I don't want to implement scheduling at the current stage, because none of the options is optimal. The option (2) takes place, but it doesn't guarantee that the notification will ever be shown, since it requires a live process.
I originally planned to use Based on my thoughts, I see two ways to implement the plugin. Which one is more preferable?
|
My own preference would be dbus so as to not have to deal with C++, particularly when there isn't a good option when it comes to being able to schedule notifications that will fire when expected even if the app has been killed. Not sure if there are other pros and cons to be aware that you could enlighten me on though. For what's it worth, I can see some of the Flutter Community Plus Plugins are using dbus as well |
Yes, it's common practice in Linux development to run a daemon - a background process that starts with the system (or starts later by user). But this is clearly not the responsibility of the Flutter plugin, this decision is up to the app developer. Okay, so I'll go into implementing the Dart version with |
@MaikuB Currently I see three ways out of the situation:
I think I'm leaning towards option (1) or (2). |
Thanks for the info. Sounds familiar from a previous PR I saw where it was persisting IDs used, which would've been option 3. I'd be leaning towards 2 or 3 but more towards 3. Going with option 1 could cause problems down the line if a similar change would need to happen down the line for other platforms. Whilst option 2 is closer to how the platform behaves, the developer experience become awkward to use in an app targeting multiple platforms. If you do a custom show method then I would guess that calling the existing |
@MaikuB |
@MaikuB The Desktop Notifications Specification is used as an implementation. I have separated the Linux plugin package from the main plugin package. This is necessary to correctly implement the Dart version of the plugin without using native code. For example, dbus package is used to communicate with the Desktop Notifications Specification and a few more auxiliary packages that allow to access native methods/environment. Implemented features:
Non-implemented features:
Testing the Desktop Notifications Specification in real-world conditions is difficult, because different Linux distributions and DE may or may not implement some of the specification things. For example, on GNOME, you can't set a timeout, custom sound, or screen location. Therefore, I wrote extensive tests that validate the request setmantics and format required by the Desktop Notifications Specification. For real world testing of notifications, I would recommend using different DEs such as GNOME (e.g Ubuntu or Fedora), KDE (e.g Kubuntu), XFCE (e.g Xubuntu), MATE (e.g Ubuntu MATE), etc. I also ask you to pay attention to these two methods: |
Thanks for the PR. Will take me sometime to go through it. I had an Ubuntu VM setup last time but had issues in testing out the example app with changes done from another PR. Was told there's some steps to follow but wasn't clear to me what I need to do. Is that the case here too? If so, would you be able to provide guidance on steps I'd need to follow as I'm not a Linux user |
In this case, no further action is required. You can immediately launch the debug version and test the notifications. |
Also, in the PR header, I described in detail all the nuances and how to test it in the best way. |
I've taken a look and this is awesome. So far it looks good and I've had some minor comment but I'm holding off on "finalising a review" as I've just across this canonical/desktop_notifications.dart#2. As such, I reached out to one of team members at Canonical to see if they would be up for maintaining a Linux implementation, have it endorsed and your PR would become the basis for this (e.g. you submit a PR to their repository). Curious to know what your thoughts are as well as I think that would be in the best interest of the community to have Canonical's own backing. Not sure when I'll hear back though. |
@MaikuB In fact,
If these problems are eliminated, it's quite possible to use If you want to combine the codebases of both plugins, then in fact my PR does this, because I use the Desktop Notification Specification as well as |
@proninyaroslav thanks, I'm aware of that. This is more on if they'd be keen on hosting and maintaining the |
@MaikuB |
Yep that's what I want to find out :) |
Thanks for reaching out @MaikuB! I'm the Canonical developer who has been working on dbus / desktop_notifications etc. Our motivation is to enable Flutter developers on Linux, and for that reason I've been working from the bottom up of the stack to make it easier for everyone to access to the services on Linux. It's great to see you've found the dbus library useful here. We're not currently working on any integration for flutter_local_notifications, but we would like it to exist so it's great to see your work here @proninyaroslav. There's a lot to build/maintain, so we always like seeing others do the work. desktop_notifications is intended to be a dependency for any Dart package that needs to access the XDG notifications spec. It's not intended to include any higher level code than that - that's left for projects like this. Regarding your specific issues:
Do please file issues if you have any trouble using desktop_notifications or features that we should add. However, should you not find desktop_notifications useful in your case, that's fine too! As long as people get working notifications, we're happy. |
Thanks so much for replying on this @robert-ancell. I realise it's a lot to maintain. As I saw an issue open on the |
This comment has been minimized.
This comment has been minimized.
@prateekmedia |
This comment has been minimized.
This comment has been minimized.
@prateekmedia That point was with regards to what was written by @robert-ancell earlier |
Oops, I think I misunderstood the discussion. |
@prateekmedia |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't find any major issues. Left some comments/questions :)
flutter_local_notifications_linux/lib/src/model/categories.dart
Outdated
Show resolved
Hide resolved
Thanks so much for this. Merged it in and will do an initial release of the Linux plugin and then publish the main plugin soon after |
android: androidPlatformChannelSpecifics, | ||
iOS: iOSPlatformChannelSpecifics, | ||
macOS: macOSPlatformChannelSpecifics); | ||
final LinuxNotificationDetails linuxPlatformChannelSpecifics = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proninyaroslav I left a comment on this elsewhere that I think may have been lost but wanted to flag that I found this sound wouldn't play when I tried on an Ubuntu VM. Do you have the same problem and are you able to help with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this is not standardized. You can get different behavior in different DEs. For example, on GNOME (which is used by Ubuntu) I was unable to achieve mp3 playback, it was causing the system to crash. I checked the /usr/share/sounds/freedesktop
directory and it turns out that the system uses the Ogg format for various system sounds. Therefore, you can use ThemeLinuxSound
to specify the name of the system sound (for example, ThemeLinuxSound('message')
), or using .oga
audio files. I think that in the example it's worth trying to replace the mp3 sound with Ogg format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reply. The ogg format sounds like a good idea 🙂
The Desktop Notifications Specification is used as an implementation.
I have separated the Linux plugin package from the main plugin package. This is necessary to correctly implement the Dart version of the plugin without using native code. For example, dbus package is used to communicate with the Desktop Notifications Specification and a few more auxiliary packages that allow to access native methods/environment.
Once this pull request is merged in the new version of the plugin, change the relative path to the package in pubspec.yaml: https://github.com/proninyaroslav/flutter_local_notifications/blob/ddc57043dcb6d68bd94d48b9fc601753ff4f899c/flutter_local_notifications/pubspec.yaml#L15
Implemented features:
initialize()
method andLinuxInitializationSettings
.show()
method andLinuxNotificationDetails
.cancel()
,cancelAll()
methods.getCapabilities()
method, which returns some of the capabilities implemented by the system notification service. Please see Desktop Notifications Specification#Backwards Compatibility.getSystemIdMap()
method, that returns aMap
with the specified notification id as the key and the id, assigned by the system, as the value. Because by specification, the system itself generates notification id, an[app id: system id]
map is used, which is cached within the user session.Non-implemented features:
As a possible option, we can consider interacting with systemd (similar to launchd on macOS) via D-Bus API of systemd (as done in the Desktop Notifications Specification). This will allow the scheduler to run as a system service. I haven't yet investigated how realistic it's to implement it in the plugin without changes from the application developer/user side.
getNotificationAppLaunchDetails()
. To respond to notification after the application is terminated, the application should be registered as DBus activatable (see DBusApplicationLaunching for more information), and register action before activating the application. This is difficult to do in a plugin because plugins instantiate during application activation, sogetNotificationAppLaunchDetails
can't be implemented without changing the main user application.Testing the Desktop Notifications Specification in real-world conditions is difficult, because different Linux distributions and DE may or may not implement some of the specification things. For example, on GNOME, you can't set a timeout, custom sound, or screen location. Therefore, I wrote extensive tests that validate the request setmantics and format required by the Desktop Notifications Specification. For real world testing of notifications, I would recommend using different DEs such as GNOME (e.g Ubuntu or Fedora), KDE (e.g Kubuntu), XFCE (e.g Xubuntu), MATE (e.g Ubuntu MATE), etc.
I also ask you to pay attention to these two methods:
https://github.com/proninyaroslav/flutter_local_notifications/blob/ddc57043dcb6d68bd94d48b9fc601753ff4f899c/flutter_local_notifications_linux/lib/src/typedefs.dart#L5
https://github.com/proninyaroslav/flutter_local_notifications/blob/ddc57043dcb6d68bd94d48b9fc601753ff4f899c/flutter_local_notifications_linux/lib/src/helpers.dart#L9
Because I split the Linux plugin version into a separate package, I had to copy these two methods for the plugin to work correctly. It might be worth leaving that as it is. Although you might consider moving the common methods into a separate package.