Browse Source

Manifest fix

Nathaniel van Diepen 10 years ago
parent
commit
c16de35b8b
5 changed files with 22 additions and 11 deletions
  1. 1 1
      bugs.appcache
  2. 2 2
      bugs.webapp
  3. 4 4
      data/pages/index.template
  4. 1 1
      data/version
  5. 14 3
      js/index.js

+ 1 - 1
bugs.appcache

@@ -111,4 +111,4 @@ NETWORK:
 *
 
 FALLBACK:
-Version Mon, Nov 25, 2013  4:45:08 PM
+Version Thu, Nov 28, 2013  3:19:32 PM

+ 2 - 2
bugs.webapp

@@ -16,8 +16,8 @@
 	"chrome": {
 		"navigation": false
 	},
-	"fullscreen": "true"
+	"fullscreen": "true",
 	"permissions": {
-		"desktop-notification":{}
+		"desktop-notification": {}
 	}
 }

+ 4 - 4
data/pages/index.template

@@ -11,14 +11,14 @@
 					$('button#install').click(function(e){
 						e.preventDefault();
 						// install the app
-						var installLocFind = navigator.mozApps.install(location.origin+'/bugs.webapp');
-						installLocFind.onsuccess = function(data){
+						var request = navigator.mozApps.install(location.origin+'/bugs.webapp');
+						request.onsuccess = function(data){
 							replaceState('page-index');
 						};
-						installLocFind.onerror = function(){
+						request.onerror = function(){
 							// App wasn't installed, info is in
 							// installapp.error.name
-							error(installapp.error.name);
+							error(request.error.name);
 						};
 						return false;
 					});

+ 1 - 1
data/version

@@ -1 +1 @@
-Mon, Nov 25, 2013  4:45:08 PM
+Thu, Nov 28, 2013  3:19:32 PM

+ 14 - 3
js/index.js

@@ -213,7 +213,7 @@
 				});
 			}
 		},
-		error = function(e,callback){
+		error = window.error = function(e,callback){
 			if(!flag('error')){
 				flag('error',true);
 				var msg = '['+State.url+']'+e.error;
@@ -534,9 +534,17 @@
 				render.dialog('#dialog',title,callback);
 			}
 		},
+		hasFocus = function(){
+			if(typeof document.hasFocus === 'undefined'){
+				document.hasFocus = function(){
+					return document.visibilityState == 'visible';
+				}
+			}
+			return document.hasFocus();
+		},
 		notify = window.notify = function(title,text,onclick,onclose){
 			var notification;
-			if(exists(window.Notification)&&!exists(window.webkitNotifications)&&!flag('default_notify')){
+			if(exists(window.Notification)&&!exists(window.webkitNotifications)&&!flag('default_notify')&&!hasFocus()){
 				if(Notification.permission === 'denied'){
 					flag('default_notify',true);
 					notify(title,text,onclick,onclose);
@@ -554,7 +562,7 @@
 						notify(title,text,onclick,onclose);
 					});
 				}
-			}else if(exists(window.navigator.mozNotification)){
+			}else if(exists(window.navigator.mozNotification)&&!hasFocus()){
 				notification = window.navigator.mozNotification.createNotification(title,text,'favicon.ico');
 				notification.onclick = onclick;
 				notification.onclose = onclose;
@@ -585,6 +593,9 @@
 		setKey(null);
 	}
 	$(document).ready(function(){
+		if(exists(typeof Notification.permission)&&Notification.permission !== 'granted'){
+			Notification.requestPermission();
+		}
 		$.ajaxSetup({
 			async: false,
 			cache: false,