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

timeout option doesn't work #401

Open
mahmoudAcm opened this issue Mar 12, 2022 · 4 comments
Open

timeout option doesn't work #401

mahmoudAcm opened this issue Mar 12, 2022 · 4 comments

Comments

@mahmoudAcm
Copy link

import Notifier from 'node-notifier';

Notifier.notify({
    message: folder.message,
    title: folderPath.split('\\').reverse()[0],
    wait: true,
    timeout: 10,
});
@MuhammadButt1995
Copy link

^ has anyone figured this out yet?

Having the same issue with WindowsToaster running on Windows 10.

No matter what values I place for 'wait' or 'timeout' nothing is working. Notifications are not waiting for user interaction / ALWAYS time out within 5 seconds. Notifications still appear in the notification/action center, but callback functions do not work (notification clicked/dismissed or buttons clicked on notification in action center do not send any response back).

MacOS Notifications via NotificationCenter are working as expected with proper wait/timeout values, just Windows notifications are not working.

@gertst
Copy link

gertst commented Mar 27, 2024

Same issue here... any updates or alternatives to have a notification that has no timeout?

Thx!

@Aetherinox
Copy link

Also getting the same. I've tried wait, and also tried adding action buttons and hoped that would pause the timeout, but nothing.

@Aetherinox
Copy link

Aetherinox commented Jul 9, 2024

Information about Windows 10 / 11 notifications + Snoretoast + Timeout / Wait

If you are referring to Windows / SnoreToast:

tl;dr: If you're trying to make Windows 10 / 11 notifications stick / wait, or change the time, you can't. Not unless you do what I posted below. And only then, you have two options, 7s short or 25s long.

Edit: I found a way to make notifications stick, read at the bottom. It requires you to edit SnoreToast and re-build the exe. SnoreToast as it is; cannot do infinite notifications.




I decided to go investigate this, and it's a two prong issue

  1. The version of SnoreToast integrated into this node-notifier library is old. There is a newer version of the exe on their repo which was built in 2023. The one node-notifer uses is from 2019.
  2. Because of the old library, the code was never added to node-notifier to allow the time / duration to be set for notifications on Windows 10 / 11.

In the latest version of SnoreToast (this library doesn't use), a new argument was added:

[-d] (short | long)                     | Set the duration default is "short" 7s, "long" is 25s.

This option doesn't take an integer / number, it takes one of two values, short or long.

To actually get this to work in Windows:

  1. Download the latest binary of SnoreToast
  2. Place the exe file in YourProject\node_modules\node-notifier\vendor\snoreToast
    • In that folder, you should already have two exe files, a 32-bit and 64-bit. You need to re-name the exe you just downloaded from snoretoast.exe to snoretoast-x64.exe (Backup the original first)
    • In the old version of SnoreToast, you needed two exes, a 32-bit and 64-bit, the latest binary is a single .exe that works for both architectures. You'd have to change the code to just use the single exe; OR, take the new exe, and put it in the same folder twice, with the different names:
      • snoretoast-x86.exe
      • snoretoast-x64.exe
  3. Open YourProject\node_modules\node-notifier\lib\utils.js. Around line 402, add:
  if (options.time) {
    options.d = options.time;
    delete options.time;
  }
  1. Around line 361, find:
  's',

Add after:

  'd',

Warning

Do not change d or options.d to anything else. That is the actual parameter passed on to SnoreToast. If you change it, you'll be trying to pass a completely different parameter.


In your notification code, add:

notifier.notify({
    title: "Notification",
    message: "Message",
    time: 'long',
})

You should now get a notification on Windows to stay up for 25 seconds.

Unfortunately for Windows toast, there is no "infinite" notification duration. It's either 7 or 25 seconds. I haven't looked at the SnoreToast source code to see if that's a limitation of Toast, or if it's a Windows limitation. But 25 seconds is better than 7.

I've messed with Windows notifications before, and I know there's a way to make notifications stick; so the only thing I can determine is that SnoreToast decided to limit how long a notification stays on screen to prevent abuse maybe, or a limitation of the Windows API.

A quick glance at the SnoreToast code shows

enum class Duration {
    Short, // default 7s
    Long // 25s
};

I'll have to look at it in more detail to determine the limitation.

From what I understand in the code, the only program that allowed for setting the time comes from

const notifier = path.resolve(__dirname, '../vendor/notifu/notifu');

Which is the balloon notification system from https://www.paralint.com/projects/notifu/, and that is for Windows XP / 8. Not 10 / 11.


Edit: The 7s or 25s appears to be a limitation of Windows Toast Notifications, not node-notifier or SnoreToast
As per the Windows documentation:

There are two types of toast notification:

    Standard toast: Most developers should use the standard toast notification. This toast remains on 
the screen for seven seconds, playing a brief sound to alert the user when it appears. The standard 
toast is best for notifications such as an IM contact sign-in, or a social media update.

    Long-duration toast: This notification looks the same as a standard toast but stays on the screen 
for 25 seconds and optionally can play longer, looping audio. This type of toast is used in situations 
where you want to grab the user's attention because there is a human waiting on the other end of 
the connection. This is appropriate for person-to-person communication like instant messages and 
VOIP calls. This type of toast can also be used for calendar reminders.

    Note  Long-duration toast is not supported on Windows Phone 8.1; all toast on the phone is 
shown for the same amount of time.

However, other apps have gotten around this by setting the notification as an "alarn".


Edit 2: After reading through the SnoreToast source code, I was able to successfully get notifications to stick by switching the notification type to incomingCall

To give you an idea, SnoreToast creates a toast by building XML within the SnoreToast app itself. When you create a new notification in SnoreToast, it generates XML code like the following, which SnoreToast will use to create your notification:

<toast duration="long">
  <visual>
    <binding template="ToastGeneric">
      <text>Hello World</text>
      <text>This is a simple toast message</text>
    </binding>
  </visual>
</toast>

As you can see on the first line, there's <toast duration="long">

In order to get notifications to stick, we must change the type of notification

<toast scenario="incomingCall">
  <visual>
    <binding template="ToastGeneric">
      <text>Hello World</text>
      <text>This is a simple toast message</text>
    </binding>
  </visual>
</toast>

In the above line, we replace duration with <toast scenario="incomingCall">, which now makes a notification appear indefinitely.

If we want to modify the SnoreToast source code to implement this feature, open download the SnoreToast source code from their Github repo, open it in Visual Studio, open the file src\snoretoasts.cpp

Find the line

ST_RETURN_ON_ERROR(addAttribute(L"launch", rootAttributes.Get(), data));

Add after:

ST_RETURN_ON_ERROR(addAttribute(L"scenario", rootAttributes.Get(), L"incomingCall"));

You will now have ALL notifications stick until they are dismissed. Go back into Visual Studio, at the top click Build -> Build All

ev0SJA2Acx

A new SnoreToast.exe file will be generated and placed inSnoretoast\out\build\x64-Debug\bin\snoretoast.exe. You can now open your Command Prompt in Windows, change directories to this folder

cd X:\Snoretoast\out\build\x64-Debug\bin

Then run a test notification

snoretoast.exe -t "Test Title" -m "Message"

You should get a test notification in the bottom right of Windows that appears forever.

I have yet to implement a new flag so that I can call "forever" at will. I've been reading the Windows notification API for a few minutes, and I'm noticing that SnoreToast is missing a lot of features that are now available for notifications.

Maybe I'll build my own version. Who knows.


Edit: I decided to add my own new parameter

[-persistent]                           | Notifications don't time out | true or false

Works well

snoretoast.exe -t "Ree" -m "Message" -persistent



I decided that I need to fork my own branch and work on these two projects. There's a lot of features to notifications I need which aren't here, and development has slowed down.

If anyone needs them, this is my version of node-notifier and snoretoasted.

Package Link
toasted-notifier https://github.com/Aetherinox/toasted-notifier
ntfy-toast https://github.com/Aetherinox/ntfy-toast

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

No branches or pull requests

4 participants