-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* notifications: Return success from functions, move warning if no notifier was found, even less output Reduce amount of information output by default Additional documentation np daemon and notify --is-running, improved --stop and process handling Add support for checking if notifications are already running Notification support, at least on OS X with terminal-notifier
- Loading branch information
Showing
16 changed files
with
305 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
source "${BASH_SOURCE%/*}/shared/functions.sh" | ||
source "${BASH_SOURCE%/*}/shared/functionality.sh" | ||
|
||
if [[ "$1" == "--is-running" ]]; | ||
then | ||
if isNotificationsRunning; | ||
then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ "$1" == "--stop" ]]; | ||
then | ||
killNotificationsIfRunning | ||
exit 0 | ||
fi | ||
|
||
exitIfAlreadyRunning "$configNotifyPidFile" "notify" | ||
savePidButDeleteOnExit "notify" "$$" "$configNotifyPidFile" | ||
|
||
checkNotify() { | ||
local mode=$(getMode) | ||
local sound=$(getCurrentSound) | ||
local message | ||
|
||
notificationCount+=1 | ||
|
||
# Don't display upon startup if np is stopped. | ||
if (( notificationCount == 1 )) && [[ "$mode" == "stopped" ]]; | ||
then | ||
return 0 | ||
fi | ||
|
||
if [[ "$mode" == "playing" && -z "$sound" ]]; | ||
then | ||
# Don't display upon startup if queue is empty. | ||
if (( notificationCount == 1 )); | ||
then | ||
return 0 | ||
fi | ||
|
||
message="Reached end of queue." | ||
else | ||
message="$sound" | ||
fi | ||
|
||
notify "$mode" "$message" | ||
} | ||
|
||
whenCurrentSoundIsChanged() { | ||
waitForFileChange "$configPlayingFile" | ||
} | ||
|
||
notifyLoop() { | ||
while true; | ||
do | ||
checkNotify | ||
whenCurrentSoundIsChanged | ||
done | ||
} | ||
|
||
declare -i notificationCount=0 | ||
|
||
notifyLoop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
cleanupDaemon() { | ||
if [[ -e "$configDaemonPidFile" ]]; | ||
then | ||
rm "$configDaemonPidFile" | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
killDaemon() { | ||
if [[ -s "$configDaemonPidFile" ]]; | ||
then | ||
killPidFromFileAndWaitUntilDead "$configDaemonPidFile" | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
isDaemonRunning() { | ||
if isValidPidFile "$configDaemonPidFile" && isPidRunningFromFile "$configDaemonPidFile"; | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
killDaemonIfRunning() { | ||
{ isDaemonRunning && killDaemon; } || true &>/dev/null | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.