Commit b26bfcad by Czémán Arnold

dashboard: change window focus detection method

parent 606d4527
Pipeline #60 passed with stage
in 0 seconds
...@@ -169,7 +169,7 @@ $(function() { ...@@ -169,7 +169,7 @@ $(function() {
); );
} else { } else {
in_progress = false; in_progress = false;
if(windowHasFocus === false && userWantNotifications()){ if(document.hasFocus() === false && userWantNotifications()){
sendNotification(generateMessageFromLastActivity()); sendNotification(generateMessageFromLastActivity());
} }
if(reload_vm_detail) location.reload(); if(reload_vm_detail) location.reload();
...@@ -190,17 +190,8 @@ $(function(){ ...@@ -190,17 +190,8 @@ $(function(){
Notification.requestPermission(); Notification.requestPermission();
}); });
// Detect window has focus
windowHasFocus = true;
$(window).blur(function(){
windowHasFocus = false;
});
$(window).focus(function(){
windowHasFocus = true;
});
function generateMessageFromLastActivity(){ function generateMessageFromLastActivity(){
var ac = $('div.activity').first(); var ac = $("div.activity").first();
var error = ac.children(".timeline-icon-failed").length; var error = ac.children(".timeline-icon-failed").length;
var sign = (error === 1) ? "❌ " : "✓ "; var sign = (error === 1) ? "❌ " : "✓ ";
var msg = ac.children("strong").text().replace(/\s+/g, " "); var msg = ac.children("strong").text().replace(/\s+/g, " ");
...@@ -212,7 +203,7 @@ function sendNotification(message) { ...@@ -212,7 +203,7 @@ function sendNotification(message) {
if (Notification.permission === "granted") { if (Notification.permission === "granted") {
var notification = new Notification(message, options); var notification = new Notification(message, options);
} }
else if (Notification.permission !== 'denied') { else if (Notification.permission !== "denied") {
Notification.requestPermission(function (permission) { Notification.requestPermission(function (permission) {
if (permission === "granted") { if (permission === "granted") {
var notification = new Notification(message, options); var notification = new Notification(message, options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment