|
|
|
@ -22,6 +22,21 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu |
|
|
|
|
window.webkitNotifications.requestPermission(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add cordova local notification click handler
|
|
|
|
|
if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) { |
|
|
|
|
window.plugin.notification.local.onclick = function (id, state, json) { |
|
|
|
|
// Parse payload
|
|
|
|
|
var data = JSON.parse(json); |
|
|
|
|
var buffer = data.buffer; |
|
|
|
|
if (buffer) { |
|
|
|
|
// Hide sidebar, open notification buffer
|
|
|
|
|
// TODO does this work?
|
|
|
|
|
$rootScope.hideSidebar(); |
|
|
|
|
models.setActiveBuffer(buffer); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -85,40 +100,54 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu |
|
|
|
|
title += buffer.shortName; |
|
|
|
|
title += buffer.fullName.replace(/irc.([^\.]+)\..+/, " ($1)"); |
|
|
|
|
|
|
|
|
|
var notification = new Notification(title, { |
|
|
|
|
body: body, |
|
|
|
|
icon: 'assets/img/favicon.png' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Save notification, so we can close all outstanding ones when disconnecting
|
|
|
|
|
notification.id = notifications.length; |
|
|
|
|
notifications.push(notification); |
|
|
|
|
// Chrome for Android doesn't know this
|
|
|
|
|
if (typeof Notification !== 'undefined') { |
|
|
|
|
var notification = new Notification(title, { |
|
|
|
|
body: body, |
|
|
|
|
icon: 'assets/img/favicon.png' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Cancel notification automatically
|
|
|
|
|
var timeout = 15*1000; |
|
|
|
|
notification.onshow = function() { |
|
|
|
|
setTimeout(function() { |
|
|
|
|
// Save notification, so we can close all outstanding ones when disconnecting
|
|
|
|
|
notification.id = notifications.length; |
|
|
|
|
notifications.push(notification); |
|
|
|
|
|
|
|
|
|
// Cancel notification automatically
|
|
|
|
|
var timeout = 15*1000; |
|
|
|
|
notification.onshow = function() { |
|
|
|
|
setTimeout(function() { |
|
|
|
|
notification.close(); |
|
|
|
|
}, timeout); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Click takes the user to the buffer
|
|
|
|
|
notification.onclick = function() { |
|
|
|
|
models.setActiveBuffer(buffer.id); |
|
|
|
|
window.focus(); |
|
|
|
|
notification.close(); |
|
|
|
|
}, timeout); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Click takes the user to the buffer
|
|
|
|
|
notification.onclick = function() { |
|
|
|
|
models.setActiveBuffer(buffer.id); |
|
|
|
|
window.focus(); |
|
|
|
|
notification.close(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Remove from list of active notifications
|
|
|
|
|
notification.onclose = function() { |
|
|
|
|
delete notifications[this.id]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (settings.soundnotification) { |
|
|
|
|
// TODO fill in a sound file
|
|
|
|
|
var audioFile = "assets/audio/sonar"; |
|
|
|
|
var soundHTML = '<audio autoplay="autoplay"><source src="' + audioFile + '.ogg" type="audio/ogg" /><source src="' + audioFile + '.mp3" type="audio/mpeg" /></audio>'; |
|
|
|
|
document.getElementById("soundNotification").innerHTML = soundHTML; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Remove from list of active notifications
|
|
|
|
|
notification.onclose = function() { |
|
|
|
|
delete notifications[this.id]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} else if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) { |
|
|
|
|
// Cordova local notification
|
|
|
|
|
// Calculate notification id from buffer ID
|
|
|
|
|
// Needs to be unique number, but we'll only ever have one per buffer
|
|
|
|
|
var id = parseInt(buffer.id, 16); |
|
|
|
|
|
|
|
|
|
// Cancel previous notification for buffer (if there was one)
|
|
|
|
|
window.plugin.notification.local.cancel(id); |
|
|
|
|
|
|
|
|
|
// Send new notification
|
|
|
|
|
window.plugin.notification.local.add({ |
|
|
|
|
id: id, |
|
|
|
|
message: body, |
|
|
|
|
title: title, |
|
|
|
|
autoCancel: true, |
|
|
|
|
json: JSON.stringify({ buffer: buffer.id }) // remember buffer id for when the notification is clicked
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|