godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Add support for sending desktop notifications #1338

Open Calinou opened 4 years ago

Calinou commented 4 years ago

Describe the project you are working on:

The Godot editor :slightly_smiling_face:

Describe the problem or limitation you are having in your project:

It's currently impossible to send desktop notifications from a Godot project (or the editor) in a cross-platform manner. It's possible to run notify-send using OS.execute(), but that only works on Linux/BSD.

There are many use cases for sending desktop notifications in projects:

We could also benefit from integrating them in the Godot editor:

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

There could be a method in the OS singleton to send a desktop notification:

OS.send_notification(title: String, message: String, custom_icon: Image = null, duration: int = -1)

The custom icon is optional. If it's null (the default), the project icon will be used for the notification icon.

The duration is specified in seconds. If it's -1 (the default), the OS-provided default will be used. (Note that this value can vary across platforms and configurations to match the user's accessibility settings.)

If the duration is 0, the notification will never go away and will have to be discarded manually (this may not be supported on all platforms).

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

On Windows 10, the result would look something like this:

We could perhaps integrate the portablefiledialogs library to implement this feature. On top of sending desktop notifications, it also supports spawning message dialogs and native file choosers (which may be useful for non-game applications made with Godot). On the HTML5 platform, the Web Notifications API could be used to implement this feature.

I also have a WIP branch which currently only supports Windows, but doesn't add any third-party libraries.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

No (except on Linux using notify-send).

Is there a reason why this should be core and not an add-on in the asset library?:

It might be possible to provide this functionality using a GDNative add-on. However, we may want to use this feature in the editor as described above for convenience reasons.

Xrayez commented 4 years ago

I would find this feature quite useful for turn-based games! People can chat in the middle of turns, and it's likely that a person may do other stuff, but a player would still like to return to the game when something interesting happens. 🙂

I believe this could also be used for simple matchmaking purposes (useful for the web).

NHodgesVFX commented 4 years ago

This could also be included on android using LocalNotification, it just needs a couple of additional parameters. There is already a module that does this but if we're doing it on desktop we might as well do it on other platforms where possible. HTML5 might also be possible. Probaly ios too but I don't know.

Oen44 commented 4 years ago

Just when I'm in need of such thing. Looked through your https://github.com/Calinou/godot/tree/add-os-notifications branch and it looks like there is some work in progress, added comment to your commit with fix for removing try icon (tested, sending multiple notification works now).

Then there is another issue, icons. While I was able to make single .png icon to display, separating them into small (tray icon) and big (the one on notification box) will be more challenging. From MSDN

Notification area icons should be high-DPI aware. An application should provide both a 16x16 pixel icon and a 32x32 icon in its resource file, and then use LoadIconMetric to ensure that the correct icon is loaded and scaled appropriately.

SIsilicon commented 3 years ago

This could probably be implemented with a script; I mean a shell/powershell script. Said script can be called via OS.execute(). Any output from the script can be written to a file and read by Godot.

Calinou commented 3 years ago

Posting Oen44's comment on my branch in case it gets lost by a force push:

image

jespereggers commented 3 years ago

All big engines support notifications (Unity, UE, CryEngine etc.), Godot must have it in 4.0 as well...

Calinou commented 3 years ago

@TakeLime Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.

9gay commented 2 years ago

There are many use cases for sending desktop notifications in projects:

* Alert the player when a new round starts if the player isn't focused on the game window (usually because they minimized the window, or they alt-tabbed out of it).

* Display chat messages while the player has alt-tabbed out from a game.

more distractful than helpful, especially when they play sounds

We could also benefit from integrating them in the Godot editor:

* If the editor window isn't focused, optionally display a notification when assets have finished reimporting.

* If the editor window isn't focused, display a notification when an asset or export templates have finished downloading.

* If the editor window isn't focused, display a notification when LightmapGI or VoxelGI is done baking.

better all of those be optional, how many people actually need that on their screens?

dalexeev commented 2 years ago

more distractful than helpful, especially when they play sounds

The fact that the examples are not entirely successful does not mean anything in this case. Let's provide this feature, and users will be able to use it when they think it's right.

In most cases, it's better to use standard uniform notifications (which are now available on Android, Windows, and even Linux: KDE and Gnome) rather than creating custom popups. Browsers also have APIs for interacting with OS UI: displaying notifications, determining the theme (light/dark), etc.

9gay commented 2 years ago

desktop notifications in general are disturbing and shouldn't be used by any apps, they are only helpful when they warn about battery almost completely discharged and appointments about to be missed, maybe in chat they are helpful only if they fire when friend or boss writes URGENT or EMERGENCY, but no chat app implements it that way

Oen44 commented 2 years ago

desktop notifications in general are disturbing and shouldn't be used by any apps

Seems like you have some scars and personal issues regarding notifications. You are not really making any good points here. There is nothing wrong with apps supporting notifications and the fact that you can disable them without messing with the app itself (from OS level) is even more convenient when you don't want to be bothered by occasional notification.

9gay commented 2 years ago

not every OS allows to whitelist apps which can send notifications, if those notifications are about battery, appointments or friend/boss needing something immediately then they are really important, but instead I live with a choice of either enabling or disabling all notifications which basically is the choice between being disturbed or missing something important

Calinou commented 2 years ago

This is not the place to discuss whether notifications are relevant in the computing world :slightly_smiling_face:

PeterMarques commented 1 year ago

Having: https://developer.mozilla.org/en-US/docs/Web/API/Push_API AND https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API

Would be a very good dream.

I am having problems with the service worker module on another question, and that function, it would to have to be implemented on the service worker as well, right?

Then, having a way to comunicate with the worker from inside the project as well, we could have server-client and project-client cross platform notification on PWA exports.

Calinou commented 1 year ago

@PeterMarques You can already use those APIs by calling JavaScript code from GDScript in the exported project: https://docs.godotengine.org/en/stable/classes/class_javascript.html

In 3.4 and later, you can also call GDScript code from JavaScript: https://godotengine.org/article/godot-web-progress-report-9

PeterMarques commented 1 year ago

Okay, so thats half of the work, i will try to do the Engine-JS thing later, but as a background service to recieve notifications even when not running, then, it needs to be instanciated on the Service.Worker, right?

Calinou commented 1 year ago

Okay, so thats half of the work, i will try to do the Engine-JS thing later, but as a background service to recieve notifications even when not running, then, it needs to be instanciated on the Service.Worker, right?

You should be able to register a service worker by calling JavaScript code. The service worker is always pure JavaScript code, it can't call into Godot's runtime functions.

JekSun97 commented 7 months ago

I also think that this is necessary in the engine, it is often used in programs, launchers, etc.

Just don’t just display a message - but render a canvas or window in the notification area so that you can create a menu and customize a theme in it.

Calinou commented 7 months ago

Just don’t just display a message - but render a canvas or window in the notification area so that you can create a menu and customize a theme in it.

The issue is that custom notifications don't follow the OS theming, accessibility or do-not-disturb settings. We should really be using OS-provided notification APIs for this :slightly_smiling_face:

In terms of implementation complexity, it ends up being similar anyway.

PTALTS-LK commented 3 months ago

So is there any progress on how to send desktop notifications on Linux/Windows or other platforms?

Calinou commented 3 months ago

So is there any progress on how to send desktop notifications on Linux/Windows or other platforms?

To my knowledge, nobody is currently working on implementing this.

lostminds commented 1 week ago

For macOS/iOS this would be implemented via UNUserNotificationCenter which also has a nice system for responding to user interactions with the notification via UNUserNotificationCenterDelegate. I'm not familiar with Windows or Linux notification systems, but perhaps there is something similar there to support getting a user response to a notification?

For this reason I think it would be very nice to include an optional interaction callback in the notification call: OS.send_notification(title: String, message: String, callback:Callable = null, custom_icon: Image = null, duration: int = -1)

Where the callback would then be called if the user clicks the notification.