From 595bb807ce2cacc76ea91d403d3b981f9e2dba5b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 9 Mar 2021 23:45:48 +0000 Subject: [PATCH 1/4] Document desktop notifications --- README_commandline.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README_commandline.md b/README_commandline.md index a68e5d586..0d8981214 100644 --- a/README_commandline.md +++ b/README_commandline.md @@ -408,3 +408,11 @@ python3 epicyon.py --screenreader picospeaker --notify yournickname@yourdomain - ``` This will then stay running and incoming posts will be announced as they arrive. + +## Desktop notifications + +You can get desktop notifications either by running the screen reader as shown above, or if you only want notifications and not spoken messages then you can run the client as follows, without the *screenreader* option: + +``` bash +python3 epicyon.py --notify yournickname@yourdomain --password [yourpassword] +``` From fe180abb84b5c751f53d1d42acb60956e6bb30df Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 09:57:19 +0000 Subject: [PATCH 2/4] Desktop notification sounds are optional --- epicyon.py | 5 ++++- notifications_client.py | 48 ++++++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/epicyon.py b/epicyon.py index 874207ba0..5336a19fb 100644 --- a/epicyon.py +++ b/epicyon.py @@ -310,6 +310,9 @@ parser.add_argument("--positivevoting", type=str2bool, nargs='?', parser.add_argument("--debug", type=str2bool, nargs='?', const=True, default=False, help="Show debug messages") +parser.add_argument("--notificationSounds", type=str2bool, nargs='?', + const=True, default=True, + help="Play notification sounds") parser.add_argument("--authenticatedFetch", type=str2bool, nargs='?', const=True, default=False, help="Enable authentication on GET requests" + @@ -1932,7 +1935,7 @@ if args.notifications: runNotificationsClient(baseDir, proxyType, httpPrefix, nickname, domain, port, args.password, args.screenreader, args.language, - args.debug) + args.notificationSounds, args.debug) sys.exit() if federationList: diff --git a/notifications_client.py b/notifications_client.py index f6836c894..545073a6c 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -101,7 +101,9 @@ def _desktopNotification(notificationType: str, def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, nickname: str, domain: str, port: int, password: str, screenreader: str, - systemLanguage: str, debug: bool) -> None: + systemLanguage: str, + notificationSounds: bool, + debug: bool) -> None: """Runs the notifications and screen reader client, which announces new inbox items """ @@ -116,6 +118,10 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, print('Running ' + screenreader + ' for ' + nickname + '@' + domain) else: print('Running desktop notifications for ' + nickname + '@' + domain) + if notificationSounds: + print('Notification sounds ON') + else: + print('Notification sounds OFF') print('/q or /quit to exit') domainFull = getFullDomain(domain, port) @@ -155,47 +161,57 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, soundsDir = 'theme/default/sounds' if speakerJson['notify']['dm'] != prevDM: if speakerJson['notify']['dm'] is True: - _playNotificationSound(soundsDir + '/' + - dmSoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + dmSoundFilename, player) _desktopNotification(notificationType, title, 'New direct message ' + actor + '/dm') prevDM = speakerJson['notify']['dm'] elif speakerJson['notify']['reply'] != prevReply: if speakerJson['notify']['reply'] is True: - _playNotificationSound(soundsDir + '/' + - replySoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + replySoundFilename, + player) _desktopNotification(notificationType, title, 'New reply ' + actor + '/tlreplies') prevReply = speakerJson['notify']['reply'] elif speakerJson['notify']['calendar'] != prevCalendar: if speakerJson['notify']['calendar'] is True: - _playNotificationSound(soundsDir + '/' + - calendarSoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + calendarSoundFilename, + player) _desktopNotification(notificationType, title, 'New calendar event ' + actor + '/calendar') prevCalendar = speakerJson['notify']['calendar'] elif speakerJson['notify']['followRequests'] != prevFollow: if speakerJson['notify']['followRequests'] is True: - _playNotificationSound(soundsDir + '/' + - followSoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + followSoundFilename, + player) _desktopNotification(notificationType, title, 'New follow request ' + actor + '/followers#buttonheader') prevFollow = speakerJson['notify']['followRequests'] elif speakerJson['notify']['likedBy'] != prevLike: - _playNotificationSound(soundsDir + '/' + - likeSoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + likeSoundFilename, player) _desktopNotification(notificationType, title, 'New like ' + speakerJson['notify']['likedBy']) prevLike = speakerJson['notify']['likedBy'] elif speakerJson['notify']['share'] != prevShare: if speakerJson['notify']['share'] is True: - _playNotificationSound(soundsDir + '/' + - shareSoundFilename, player) + if notificationSounds: + _playNotificationSound(soundsDir + '/' + + shareSoundFilename, + player) _desktopNotification(notificationType, title, 'New shared item ' + actor + '/shares') @@ -257,3 +273,9 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, keyPress = keyPress[1:] if keyPress == 'q' or keyPress == 'quit' or keyPress == 'exit': break + elif keyPress == 'sounds on' or keyPress == 'sound': + print('Notification sounds ON') + notificationSounds = True + elif keyPress == 'sounds off' or keyPress == 'nosound': + print('Notification sounds OFF') + notificationSounds = False From 67cbebe7abbc7530615d61376016daf1a2d61970 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 10:25:41 +0000 Subject: [PATCH 3/4] Turn speaker on or off --- notifications_client.py | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/notifications_client.py b/notifications_client.py index 545073a6c..88655c465 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -98,6 +98,25 @@ def _desktopNotification(notificationType: str, title + "\", '" + message + "'") +def _sayCommand(sayStr: str, screenreader: str, + systemLanguage: str, espeak=None) -> None: + """Speaks a command + """ + print(sayStr) + cmdSpeakerName = 'screen reader' + + pitch = getSpeakerPitch(cmdSpeakerName, + screenreader, 'They/Them') + rate = getSpeakerRate(cmdSpeakerName, screenreader) + srange = getSpeakerRange(cmdSpeakerName) + + if screenreader == 'espeak': + _speakerEspeak(espeak, pitch, rate, srange, sayStr) + elif screenreader == 'picospeaker': + _speakerPicospeaker(pitch, rate, + systemLanguage, sayStr) + + def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, nickname: str, domain: str, port: int, password: str, screenreader: str, @@ -107,6 +126,7 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, """Runs the notifications and screen reader client, which announces new inbox items """ + espeak = None if screenreader: if screenreader == 'espeak': print('Setting up espeak') @@ -124,6 +144,7 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, print('Notification sounds OFF') print('/q or /quit to exit') + originalScreenReader = screenreader domainFull = getFullDomain(domain, port) actor = httpPrefix + '://' + domainFull + '/users/' + nickname prevSay = '' @@ -279,3 +300,27 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, elif keyPress == 'sounds off' or keyPress == 'nosound': print('Notification sounds OFF') notificationSounds = False + elif keyPress == 'speak' or \ + keyPress == 'screen reader on' or \ + keyPress == 'speaker on' or \ + keyPress == 'talker on' or \ + keyPress == 'reader on': + if originalScreenReader: + screenreader = originalScreenReader + sayStr = 'Screen reader ON' + _sayCommand(sayStr, screenreader, + systemLanguage, espeak) + else: + print('No --screenreader option was specified') + elif keyPress == 'quiet' or \ + keyPress == 'screen reader off' or \ + keyPress == 'speaker off' or \ + keyPress == 'talker off' or \ + keyPress == 'reader off': + if originalScreenReader: + screenreader = None + sayStr = 'Screen reader OFF' + _sayCommand(sayStr, originalScreenReader, + systemLanguage, espeak) + else: + print('No --screenreader option was specified') From a39212a732b9ddc2544bdaf907c69b5114e2c7a1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 10 Mar 2021 10:32:08 +0000 Subject: [PATCH 4/4] Speak notification sounds command --- notifications_client.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/notifications_client.py b/notifications_client.py index 88655c465..6e8431bbd 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -103,8 +103,10 @@ def _sayCommand(sayStr: str, screenreader: str, """Speaks a command """ print(sayStr) - cmdSpeakerName = 'screen reader' + if not screenreader: + return + cmdSpeakerName = 'screen reader' pitch = getSpeakerPitch(cmdSpeakerName, screenreader, 'They/Them') rate = getSpeakerRate(cmdSpeakerName, screenreader) @@ -295,16 +297,20 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, if keyPress == 'q' or keyPress == 'quit' or keyPress == 'exit': break elif keyPress == 'sounds on' or keyPress == 'sound': - print('Notification sounds ON') + sayStr = 'Notification sounds ON' + _sayCommand(sayStr, screenreader, + systemLanguage, espeak) notificationSounds = True elif keyPress == 'sounds off' or keyPress == 'nosound': - print('Notification sounds OFF') + sayStr = 'Notification sounds OFF' + _sayCommand(sayStr, screenreader, + systemLanguage, espeak) notificationSounds = False - elif keyPress == 'speak' or \ - keyPress == 'screen reader on' or \ - keyPress == 'speaker on' or \ - keyPress == 'talker on' or \ - keyPress == 'reader on': + elif (keyPress == 'speak' or + keyPress == 'screen reader on' or + keyPress == 'speaker on' or + keyPress == 'talker on' or + keyPress == 'reader on'): if originalScreenReader: screenreader = originalScreenReader sayStr = 'Screen reader ON' @@ -312,11 +318,11 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, systemLanguage, espeak) else: print('No --screenreader option was specified') - elif keyPress == 'quiet' or \ - keyPress == 'screen reader off' or \ - keyPress == 'speaker off' or \ - keyPress == 'talker off' or \ - keyPress == 'reader off': + elif (keyPress == 'mute' or + keyPress == 'screen reader off' or + keyPress == 'speaker off' or + keyPress == 'talker off' or + keyPress == 'reader off'): if originalScreenReader: screenreader = None sayStr = 'Screen reader OFF'