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

hs.notify autoWithdraw not working after reload #2422

Open
kassi opened this issue Jul 20, 2020 · 4 comments
Open

hs.notify autoWithdraw not working after reload #2422

kassi opened this issue Jul 20, 2020 · 4 comments

Comments

@kassi
Copy link

kassi commented Jul 20, 2020

Behavior as is:
The autoWithdraw functionality in hs.notify doesn't seem to work after the configuration has been reloaded.
If have a function to reload the config (on key press or file change using pathwatcher).

function reloadConfig(files)
  hs.reload()
  hs.notify.new({title="Hammerspoon", informativeText="Configuration reloaded", autoWithdraw=true, withdrawAfter=2}):send()
end

The configuration reloads, the notification appears but stays.
Running only the notify code in the console works as expected.
Running it as a one-liner in the console (concatenated with ";", even without calling the function) doesn't work: the notification stays. Switching order doesn't work either.

Expected behavior:
The configuration reloads, the notification appears and withdraws after 2 seconds.

System information:
Tested on Mac OS 10.13.6 and 10.15.5
Hammerspoon: 0.9.78 (5164)

@kia-nasirzadeh
Copy link

1- This method has no effect if the user has set Hammerspoon notifications to Alert in the Notification Center pane of System Preferences: clicking on either the action or other button will clear the notification automatically.

2- If a notification which was created before your last reload (or restart) of Hammerspoon and is clicked upon before hs.notify has been loaded into memory, this setting will not be honored because the initial application delegate is not aware of this option and is set to automatically withdraw all notifications which are acted upon.

@latenitefilms
Copy link
Contributor

You'll need to store the notification tags somewhere (i.e. in a JSON file), and re-register them when Hammerspoon reloads.

@kia-nasirzadeh
Copy link

kia-nasirzadeh commented Sep 10, 2020

You'll need to store the notification tags somewhere (i.e. in a JSON file), and re-register them when Hammerspoon reloads.

can u explain more please?
i mean how to do that exactly?

@latenitefilms
Copy link
Contributor

Actually, I just remembered that there's some things broken in Hammerspoon that prevent this from working correctly.

I think the only way to really do this currently is using hs.notify.deliveredNotifications() to check for what notifications have been delivered, trigger hs.notify.withdrawAll() to remove them all, then add them again.

Related:

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

3 participants