Skip to content

Commit

Permalink
Merge pull request #467 from averissimo/feature-notifications-icon-an…
Browse files Browse the repository at this point in the history
…d-sound

Improvements in notifications -- Adds yakyak icon and sound in linux, avatar in Mac OS X
  • Loading branch information
davibe committed Dec 3, 2016
2 parents 87e9da2 + 22b1d5c commit 12b1952
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ $ npm run deploy:darwin-x64
| `src/` | Is where sources live |
| `src/ui/` | Holds renderer code (client side) |
| `dist/` | Everything is compiled to this directory |

### Acknowledgement

- All the users and developers of YakYak
- ["You wouldn't believe"](https://notificationsounds.com/notification-sounds/you-wouldnt-believe-510) as the 'new message' sound for some platforms and is licensed under CC
8 changes: 7 additions & 1 deletion gulpfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ paths =
html: './src/**/*.html'
images: './src/**/images/*.*'
icons: './src/icons'
media: './src/media/*.*'
less: './src/ui/css/manifest.less'
lessd: './src/ui/css/**/*.less'
css: './src/**/*.css'
Expand Down Expand Up @@ -104,6 +105,11 @@ gulp.task 'html', ->
.pipe htmlInject()
.pipe gulp.dest outapp

# copy images
gulp.task 'media', ->
gulp.src paths.media
.pipe gulp.dest path.join outapp, 'media'

# copy images
gulp.task 'images', ->
gulp.src paths.images
Expand Down Expand Up @@ -172,7 +178,7 @@ gulp.task 'reloader', ->
gulp.task 'clean', (cb) ->
rimraf outapp, cb

gulp.task 'default', ['package', 'coffee', 'html', 'images',
gulp.task 'default', ['package', 'coffee', 'html', 'images', 'media',
'icons', 'less', 'fontello']

gulp.task 'watch', ['default', 'reloader', 'html'], ->
Expand Down
Binary file added src/media/new_message.ogg
Binary file not shown.
9 changes: 9 additions & 0 deletions src/ui/dispatcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ handle 'sendmessage', (txt = '') ->
handle 'toggleshowtray', ->
viewstate.setShowTray(not viewstate.showtray)

handle 'forcecustomsound', (value) ->
viewstate.setForceCustomSound(value)

handle 'showiconnotification', (value) ->
viewstate.setShowIconNotification(value)

handle 'mutesoundnotification', ->
viewstate.setMuteSoundNotification(not viewstate.muteSoundNotification)

handle 'toggleshowseenstatus', ->
viewstate.setShowSeenStatus(not viewstate.showseenstatus)

Expand Down
20 changes: 19 additions & 1 deletion src/ui/models/viewstate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ module.exports = exp = {
startminimizedtotray: tryparse(localStorage.startminimizedtotray) or false
closetotray: tryparse(localStorage.closetotray) or false
showDockOnce: true
showseenstatus: tryparse(localStorage.showseenstatus) or false
showseenstatus: tryparse(localStorage.showseenstatus) ? false
showIconNotification: tryparse(localStorage.showIconNotification) ? true
muteSoundNotification: tryparse(localStorage.muteSoundNotification) ? false
forceCustomSound: tryparse(localStorage.forceCustomSound) ? false
messageMemory: {}

setState: (state) ->
Expand Down Expand Up @@ -210,6 +213,21 @@ module.exports = exp = {
@showUsernameInNotification = localStorage.showUsernameInNotification = doshow
updated 'viewstate'

setForceCustomSound: (doshow) ->
return if localStorage.forceCustomSound == doshow
@forceCustomSound = localStorage.forceCustomSound = doshow
updated 'viewstate'

setShowIconNotification: (doshow) ->
return if localStorage.showIconNotification == doshow
@showIconNotification = localStorage.showIconNotification = doshow
updated 'viewstate'

setMuteSoundNotification: (doshow) ->
return if localStorage.muteSoundNotification == doshow
@muteSoundNotification = localStorage.muteSoundNotification = doshow
updated 'viewstate'

setConvertEmoji: (doshow) ->
return if @convertEmoji == doshow
@convertEmoji = localStorage.convertEmoji = doshow
Expand Down
13 changes: 12 additions & 1 deletion src/ui/util.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
URL = require 'url'
notifier = require 'node-notifier'

notificationCenterSupportsSound = () ->
# check if sound should be played via notification
# documentation says that only WindowsToaster and
# NotificationCenter supports sound
playSoundIn = ['WindowsToaster', 'NotificationCenter']
# check if currect notifier supports sound
notifierSupportsSound = playSoundIn.find( (str) ->
str == notifier.constructor.name
)?

nameof = (e) -> e?.display_name ? e?.fallback_name ? e?.first_name ? 'Unknown'

Expand Down Expand Up @@ -100,4 +111,4 @@ convertEmoji = (text) ->
return text
module.exports = {nameof, initialsof, nameofconv, linkto, later, throttle, uniqfn,
isAboutLink, getProxiedName, tryparse, fixlink, topof, isImg, getImageUrl,
toggleVisibility, convertEmoji}
toggleVisibility, convertEmoji, notificationCenterSupportsSound}
28 changes: 27 additions & 1 deletion src/ui/views/menu.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
remote = require('electron').remote
Menu = remote.Menu

{notificationCenterSupportsSound} = require '../util'

platform = require('os').platform()
# to reduce number of == comparisons
isDarwin = platform == 'darwin'
isNotDarwin = platform != 'darwin'

# true if it does, false otherwise
notifierSupportsSound = notificationCenterSupportsSound()

acceleratorMap = {
# MacOSX specific
hideyakyak: { default: 'CmdOrCtrl+H' }
Expand Down Expand Up @@ -152,7 +157,28 @@ templateView = (viewstate) ->
enabled: viewstate.loggedin && viewstate.showPopUpNotifications
click: (it) -> action 'showusernameinnotification', it.checked
}
]
{
type: 'checkbox'
label: "Show #{if isDarwin then 'User avatar' else 'YakYak'} icon in notifications"
enabled: viewstate.loggedin && viewstate.showPopUpNotifications
checked: viewstate.showIconNotification
click: (it) -> action 'showiconnotification', it.checked
}
{
type: 'checkbox'
label: 'Disable sound in notifications'
checked: viewstate.muteSoundNotification
enabled: viewstate.loggedin && viewstate.showPopUpNotifications
click: (it) -> action 'mutesoundnotification', it.checked
}
{
type: 'checkbox'
label: 'Use YakYak custom sound for notifications'
checked: viewstate.forceCustomSound
enabled: viewstate.loggedin && viewstate.showPopUpNotifications && !viewstate.muteSoundNotification
click: (it) -> action 'forcecustomsound', it.checked
} if notifierSupportsSound
].filter (n) -> n != undefined
}
{
type: 'checkbox'
Expand Down
45 changes: 37 additions & 8 deletions src/ui/views/notifications.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ shell = require('electron').shell
path = require 'path'
remote = require('electron').remote

{nameof, getProxiedName} = require '../util'
{nameof, getProxiedName, fixlink, notificationCenterSupportsSound} = require '../util'

# conv_id markers for call notifications
callNeedAnswer = {}

notifierSupportsSound = notificationCenterSupportsSound()

# Custom sound for new message notifications
audioFile = path.join __dirname, '..', '..', 'media',
'new_message.ogg'
audioEl = new Audio(audioFile)
audioEl.volume = .4


module.exports = (models) ->
{conv, notify, entity, viewstate} = models
tonot = notify.popToNotify()
Expand Down Expand Up @@ -55,26 +64,46 @@ module.exports = (models) ->

# maybe trigger OS notification
return if !text or quietIf(c, chat_id)

if viewstate.showPopUpNotifications
isNotificationCenter = notifier.constructor.name == 'NotificationCenter'
#
icon = path.join __dirname, '..', '..', 'icons', 'icon@8.png'
# Only for NotificationCenter (darwin)
if isNotificationCenter && viewstate.showIconNotification
contentImage = fixlink entity[cid]?.photo_url
else
contentImage = undefined
#
notifier.notify
title: if viewstate.showUsernameInNotification
sender
if !isNotificationCenter && !viewstate.showIconNotification
"#{sender} (via YakYak)"
else
sender
else
'YakYak'
message: if viewstate.showMessageInNotification
text
else
'New Message'
text
else
'New Message'
wait: true
sender: 'com.github.yakyak'
sound: true
sound: !viewstate.muteSoundNotification && (notifierSupportsSound && !viewstate.forceCustomSound)
icon: icon if !isNotificationCenter && viewstate.showIconNotification
contentImage: contentImage
, (err, res) ->
if res?.trim().match(/Activate/i)
action 'appfocus'
action 'selectConv', c

mainWindow = remote.getCurrentWindow() # And we hope we don't get another ;)
# only play if it is not playing already
# and notifier does not support sound or force custom sound is set
# and mute option is not set
if (!notifierSupportsSound || viewstate.forceCustomSound) && !viewstate.muteSoundNotification && audioEl.paused
audioEl.play()
# And we hope we don't get another 'currentWindow' ;)
mainWindow = remote.getCurrentWindow()
mainWindow.flashFrame(true)

textMessage = (cont, proxied) ->
Expand Down

0 comments on commit 12b1952

Please sign in to comment.