Browse Source

Disable notifications on Android as of https://code.google.com/p/chromium/issues/detail?id=481856

pull/226/head
Simon Eisenmann 11 years ago
parent
commit
ccddf38c80
  1. 39
      static/js/services/desktopnotify.js

39
static/js/services/desktopnotify.js

@ -20,7 +20,7 @@
*/ */
"use strict"; "use strict";
define(['jquery', 'underscore', 'desktop-notify'], function($, _, notify) { define(['jquery', 'underscore', 'desktop-notify', 'webrtc.adapter'], function($, _, notify) {
return ["$window", function($window) { return ["$window", function($window) {
@ -29,8 +29,8 @@ define(['jquery', 'underscore', 'desktop-notify'], function($, _, notify) {
var iconElement = $("<span>").addClass("desktopnotify-icon hidden"); var iconElement = $("<span>").addClass("desktopnotify-icon hidden");
iconElement.appendTo("body"); iconElement.appendTo("body");
var url = iconElement.css('background-image'); var url = iconElement.css('background-image');
url = /^url\((['"]?)(.*)\1\)$/.exec(url); url = /^url\((['"]?)(.*)\1\)$/.exec(url);
url = url ? url[2] : ""; url = url ? url[2] : "";
iconElement.remove(); iconElement.remove();
return url; return url;
}()); }());
@ -55,18 +55,43 @@ define(['jquery', 'underscore', 'desktop-notify'], function($, _, notify) {
DesktopNotify.prototype.enabled = function() { DesktopNotify.prototype.enabled = function() {
if (this.level === "default") { if (this.supported && this.level === "default") {
this.asked = true; this.asked = true;
this.requestPermission(); this.requestPermission();
} }
return (this.supported && this.level === "granted") ? true : false; return this.supported && this.level === "granted";
}; };
DesktopNotify.prototype.refresh = function() { DesktopNotify.prototype.refresh = function() {
this.supported = helper.isSupported; var level = this.level = helper.permissionLevel();
this.level = helper.permissionLevel(); this.supported = (function() {
if (helper.isSupported) {
if ($window.Notification && $window.Notification.requestPermission) {
if (level !== "granted") {
// Aditional check to verify Notification really works. This fails
// on Android, where Notifications raise an exception.
// See https://code.google.com/p/chromium/issues/detail?id=481856
try {
/*jshint nonew: false */
new $window.Notification('');
} catch(e) {
if (e.name == 'TypeError') {
return false;
}
}
} else {
// Disable notifications even if granted and on Android Chrome.
if ($window.webrtcDetectedAndroid) {
return false;
}
}
}
return true;
}
return false;
}());
}; };

Loading…
Cancel
Save