Skip to content
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

Add support for sending desktop notifications #1338

Open
Calinou opened this issue Aug 8, 2020 · 22 comments
Open

Add support for sending desktop notifications #1338

Calinou opened this issue Aug 8, 2020 · 22 comments

Comments

@Calinou
Copy link
Member

Calinou commented Aug 8, 2020

Describe the project you are working on:

The Godot editor 🙂

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:

  • 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.
  • Non-game applications can probably find creative ways to use them as well.

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.

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
Copy link
Contributor

Xrayez commented Aug 8, 2020

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
Copy link

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
Copy link

Oen44 commented Aug 16, 2020

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
Copy link

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
Copy link
Member Author

Calinou commented Jan 25, 2021

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

image

@jespereggers

This comment has been minimized.

@Calinou

This comment has been minimized.

@ghost

This comment was marked as off-topic.

@dalexeev

This comment was marked as off-topic.

@ghost

This comment was marked as off-topic.

@Oen44

This comment was marked as off-topic.

@ghost

This comment was marked as off-topic.

@Calinou

This comment was marked as off-topic.

@PeterMarques
Copy link

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
Copy link
Member Author

Calinou commented Dec 3, 2022

@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
Copy link

PeterMarques commented Dec 3, 2022

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
Copy link
Member Author

Calinou commented Dec 4, 2022

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
Copy link

JekSun97 commented Feb 5, 2024

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
Copy link
Member Author

Calinou commented Feb 6, 2024

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 🙂

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

@PTALTS-LK
Copy link

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

@Calinou
Copy link
Member Author

Calinou commented May 22, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests