Show cordova local notifications instead of just vibrating

This is really cool :D
Lorenz Hübschle-Schneider 12 years ago
parent 6fea49a8a4
commit c52a287420
  1. 45
      js/glowingbear.js

@ -566,6 +566,23 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
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
$scope.showSidebar = false;
models.setActiveBuffer(buffer);
}
// Cancel notification
window.plugin.notification.local.cancel(id);
};
}
};
@ -758,6 +775,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
//models.reinitialize();
$rootScope.$emit('notificationChanged');
$scope.connectbutton = 'Connect';
// Clear all cordova notifications
if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) {
window.plugin.notification.local.cancelAll();
}
});
$scope.connectbutton = 'Connect';
@ -1044,6 +1066,22 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
window.focus();
notification.close();
};
} 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,
json: JSON.stringify({ buffer: buffer.id }) // remember buffer id for when the notification is clicked
});
}
if ($scope.soundnotification) {
@ -1052,13 +1090,6 @@ 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>';
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) {

Loading…
Cancel
Save