Skip to main content
  1. About
  2. For Teams
Asked
Modified 25 days ago
Viewed 34 times
0

I have a self-hosted version of rocket.chat and I tried to slightly change it in both server and electron, and I faced a problem.

The change I made is inside the notification module, and a function called notify. When rocket.chat tries to send a desktop notification, should the client be an electron instance, I send an IPC message to the client to handle notification instead of showing the default browser Notification API.

Everything seems to be working, but sometimes for some reason, it resets to sending browser notification instead of the custom one. I couldn't pinpoint the problem, as this does not happen on development mode, but on the published .exe file.

Something that I noticed recently is that it usually goes on that mode when it's staled (for example when you put your windows on sleep and open it the next day). Also when it was in that mode, I could not open the DevTools to see if there are some errors on the console (the app wouldn't respond to that action at all).

Here is how I am sending the notification to the client:

notify(notification) {
    if (window.Notification && Notification.permission === 'granted') {
        const message = {
            rid: notification.payload != null ? notification.payload.rid : undefined,
            msg: notification.text,
            notification: true,
        };
        return onClientMessageReceived(message).then(function (message) {
            if (window.RocketChatDesktop?.send) {
                //process notification object for the electron version
                window.RocketChatDesktop.send('show-notification', message)
            } else {
                //default browser notification API
            }
        });
    }
},

Any idea what seems to be the problem?

1
  • I think it happens because of window.RocketChatDesktop is injected via the preload script, and in a packaged Electron app (especially after sleep/hibernation), the renderer can get suspended or restarted. When that happens, RocketChatDesktop may be undefined, so your code falls back to the browser notification. A common fix is to wait for the API to be ready before sending, and handle system resume events, e.g., poll for window.RocketChatDesktop?.send or log when it’s missing to avoid silent fallback.
    Kamran
    –  Kamran
    2025-09-15 10:32:49 +00:00
    Commented Sep 15 at 10:32

0

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.