-
Notifications
You must be signed in to change notification settings - Fork 213
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
'multi' backend and screen locking detection #170
base: master
Are you sure you want to change the base?
Conversation
separate backends implemented via a 'multi' meta-backend. Uses config like this: ``` backends: [multi] multi: locked: pushover: user_key: user-api-key unfocused: default: {} focused: {} ``` This config would cause no notifications if the shell is focused, desktop notifications when unfocused, and pushover notifications when the screen is locked. Freaking magic. 🎉
WIP of dschep#125: screen locking detection * dschep/locked: yapf-ify WIP of dschep#125: screen locking detection
…reenlock * commit '84903e7ae7b7ff6ba102558948cd15e5a361a555': Add screensaver detection for MacOS
I can't really explain what happened with that last merge commit... |
2 similar comments
* master: virtualenv already installed i think use pyenv for py3k Switch to pywin32
8e836b7
to
db07043
Compare
for the new config file format, what about # specify a version number to maintain compatibility with the old parser
version: 2
backends:
-
# use pushover when the screen is locked
type: pushover
# it *might* make sense to put user key under a config hash so that every
# backend in the list has the same schema except for whatever is in `config`.
user_key: user-api-key
enable:
- locked
-
# use native notifications when the terminal in question is unfocused
type: darwin
enable:
- unfocused
-
# do not use growl
type: growl
enable: [] Rather than having a hash of configurations and a list of which configurations to use, just mash them all together and include their operational mode as part of their config. |
Any updates on this? I'm getting the same as you here. This happens in both |
@unai-ndz, assuming you’re referring to the failure to notify on long commands, I ended up switching to zsh. The behavior is built in rather than relying on the hacks in bash-preexec |
Yes, on long running commands. I actually use zsh already. Mainstream works well but when I use your branches it stops working. I'm using the default config from this PR and the eval line on my zshrc |
I'm not using oh-my-zsh (found it added a lot of overhead that I wasn't using). I source the following file in # shellcheck disable
AUTO_NTFY_DONE_IGNORE=${AUTO_NTFY_DONE_IGNORE:-ntfy emacs info less mail man meld most mutt nano screen ssh tail tmux vi vim watch bash zsh}
# Bash option example
#AUTO_NTFY_DONE_OPTS='-b default'
# Zsh option example
AUTO_NTFY_DONE_OPTS=(-b multi)
# notify for unfocused only (Used by ntfy internally)
#AUTO_NTFY_DONE_UNFOCUSED_ONLY=-b
# notify for commands runing longer than N sec only (Used by ntfy internally)
AUTO_NTFY_DONE_LONGER_THAN=-L5
function _ntfy_precmd () {
local ret_value="$?"
[ -n "$ntfy_start_time" ] || return
local duration=$(( $(date +%s) - $ntfy_start_time ))
ntfy_start_time=''
local appname=$(basename "${ntfy_command%% *}")
[[ " $AUTO_NTFY_DONE_IGNORE " == *" $appname "* ]] && return
ntfy $AUTO_NTFY_DONE_OPTS done \
$AUTO_NTFY_DONE_UNFOCUSED_ONLY $AUTO_NTFY_DONE_LONGER_THAN \
--formatter "$ntfy_command" "$ret_value" "$duration"
}
function _ntfy_preexec () {
ntfy_start_time=$(date +%s)
ntfy_command="$1"
}
function _contains_element() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
# Only setup ntfy shell integration if it's been configured
if [[ -f "$HOME/.ntfy.yml" ]]; then
if ! _contains_element _ntfy_preexec "${preexec_functions[@]}"; then
preexec_functions+=(_ntfy_preexec)
fi
if ! _contains_element _ntfy_precmd "${precmd_functions[@]}"; then
precmd_functions+=(_ntfy_precmd)
fi
fi This is mostly just what
2 seems like the only relevant difference. |
It was actually line 5 of Changing line 5 of And i also needed to change line 33 to: It was failing silently before and then started showing errors which helped me fix this. I guess i can provide a patch but being changes so small i don't think is worth it. |
@unai-ndz no need to open a PR, but could you post the output of |
Sure, I actually changed it slightly. index e6decb4..2e11046 100644
--- a/ntfy/screensaver.py
+++ b/ntfy/screensaver.py
@@ -16,7 +16,7 @@ def xscreensaver_detect():
def xscreensaver_is_locked():
- return 'screen locked' in check_output(split('xscreensaver-command -time'))
+ return b'screen locked' in check_output(split('xscreensaver-command -time'))
def lightlocker_detect():
@@ -29,7 +29,7 @@ def lightlocker_detect():
def lightlocker_is_active():
- return 'The screensaver is active' in check_output(
+ return b'The screensaver is active' in check_output(
split('light-locker-command -q'))
diff --git a/ntfy/terminal.py b/ntfy/terminal.py
index 30cd3b6..206ce6d 100644
--- a/ntfy/terminal.py
+++ b/ntfy/terminal.py
@@ -2,7 +2,7 @@ import shlex
from os import environ, ttyname
from subprocess import PIPE, Popen, check_output, CalledProcessError
from sys import platform, stdout
-from screensaver import is_locked
+from .screensaver import is_locked
def linux_window_is_focused(): |
separate backends implemented via a 'multi' meta-backend.
Uses config like this:
This config would cause no notifications if the shell is focused, desktop
notifications when unfocused, and pushover notifications when the screen is
locked. Freaking magic. 🎉
There's also a
--locked-only
cli option.Todo:
multi
moduleFixes #168 & fixes #125 & supercedes #147