Vibrate on notification (cordova)

Also don't expect Notification to exist, mobile Chrome doesn't know it
Lorenz Hübschle-Schneider 12 years ago
parent fd9e030a34
commit e4b8d209cb
  1. 44
      js/glowingbear.js

@ -1023,25 +1023,28 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
title += buffer.shortName; title += buffer.shortName;
title += buffer.fullName.replace(/irc.([^\.]+)\..+/, " ($1)"); title += buffer.fullName.replace(/irc.([^\.]+)\..+/, " ($1)");
var notification = new Notification(title, { // Chrome for Android doesn't know this
body: body, if (typeof Notification !== 'undefined') {
icon: 'assets/img/favicon.png' var notification = new Notification(title, {
}); body: body,
icon: 'assets/img/favicon.png'
});
// Cancel notification automatically // Cancel notification automatically
var timeout = 15*1000; var timeout = 15*1000;
notification.onshow = function() { notification.onshow = function() {
setTimeout(function() { setTimeout(function() {
notification.close(); notification.close();
}, timeout); }, timeout);
}; };
// Click takes the user to the buffer // Click takes the user to the buffer
notification.onclick = function() { notification.onclick = function() {
models.setActiveBuffer(buffer.id); models.setActiveBuffer(buffer.id);
window.focus(); window.focus();
notification.close(); notification.close();
}; };
}
if ($scope.soundnotification) { if ($scope.soundnotification) {
// TODO fill in a sound file // TODO fill in a sound file
@ -1049,6 +1052,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
var soundHTML = '<audio autoplay="autoplay"><source src="' + audioFile + '.ogg" type="audio/ogg" /><source src="' + audioFile + '.mp3" type="audio/mpeg" /></audio>'; 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; document.getElementById("soundNotification").innerHTML = soundHTML;
} }
if (navigator.notification !== undefined) {
console.log('vibrating!');
navigator.notification.vibrate(500);
} else {
console.log('no notification api :(', navigator.notification);
}
}; };
$scope.hasUnread = function(buffer) { $scope.hasUnread = function(buffer) {

Loading…
Cancel
Save