Skip to content

Commit

Permalink
Fix badge
Browse files Browse the repository at this point in the history
  • Loading branch information
laioncamargo committed Feb 1, 2019
1 parent eb5b799 commit 0a56968
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 5 deletions.
64 changes: 64 additions & 0 deletions js/sendControll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,62 @@ $(document).ready(function() {
var defaultPort = "8180";

var defaultStats = "[not available]";

var url = "http://geo.geosurf.io/";
var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
if (xmlhttp.status != 200 && window.localStorage['proxyConfig'][20] != "s") {

// Badge the popup icon.
var RED = [255, 0, 0, 255];
chrome.browserAction.setBadgeBackgroundColor({color: RED});
chrome.browserAction.setBadgeText({text: 'X'});
chrome.browserAction.setTitle({
title: chrome.i18n.getMessage('errorPopupTitle')
});

// delete all existing and opened alerts
var els = document.getElementsByClassName('overlay');

while (els[0]) {
els[0].classList.remove('active')
}

clearErrorDivs();

var success = document.createElement('div');
success.setAttribute('id', 'proxyFail');

if(close == true){
success.classList.add('overlay');
}
else{
success.removeAttribute('hidden', 'hidden');
success.classList.add('proxyFailMsg');
}
success.setAttribute('role', 'alert');

success.textContent = chrome.i18n.getMessage('errorProxyError');

document.getElementById("connectedMsg").innerText = "CONNECTION ERROR";
document.getElementById("tryAgainMsg").innerText = "TRY AGAIN";
document.getElementById("imgError").removeAttribute('hidden', 'hidden');
document.getElementById("dataValue").setAttribute('hidden', 'hidden');

document.getElementById("settingsConfig").setAttribute('hidden', 'hidden');

// switch visible sections, hiding welcome screen and showing the other where error is shown
document.getElementById("fixed_servers").setAttribute('hidden', 'hidden');
document.getElementById("system").removeAttribute('hidden', 'hidden');

document.getElementById("dataValue").setAttribute('hidden', 'hidden');

document.body.appendChild(success);

setTimeout(function() { success.classList.add('visible'); }, 10);
}
}

if (window.localStorage['proxyConfig'] == undefined || window.localStorage['proxyConfig'][20] == "s") {
console.log("Local Storage does not exist");
Expand Down Expand Up @@ -132,6 +188,14 @@ $(document).ready(function() {
}
});


xmlhttp.open("GET", url, true);
xmlhttp.timeout = 2500; // time in milliseconds
xmlhttp.setRequestHeader('Access-Control-Allow-Origin','*');
xmlhttp.setRequestHeader('Access-Control-Allow-Methods', '*');
xmlhttp.setRequestHeader('Access-Control-Allow-Headers', '*');
xmlhttp.send();

// make following action fire when radio button changes
$('input[type=radio]').click(function(){
if(document.getElementById('proxyHostHttp').value.length < 1 && document.getElementById('proxyPortHttp').value.length < 1){
Expand Down
69 changes: 64 additions & 5 deletions proxy_form_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// interval between each online check. Increase if successfull, decrease if unsuccessfull
var defaultOnlineCheckTimeout = 5000;
var onlineCheckTimeout = 5000;
var defaultOnlineCheckTimeout = 1000;
var onlineCheckTimeout = 1000;
var onlineTimeoutID = 0; // id of the latest timeout so we can reset it if needed

var defaultStats = "[not available]";
Expand All @@ -25,6 +25,58 @@ function resetOnlineTimerCheck() {
resetTimeoutOnline();
}

function getBadge() {
if (window.localStorage['proxyConfig'][20] != "s") {
// Badge the popup icon.
var RED = [255, 0, 0, 255];
chrome.browserAction.setBadgeBackgroundColor({color: RED});
chrome.browserAction.setBadgeText({text: 'X'});
chrome.browserAction.setTitle({
title: chrome.i18n.getMessage('errorPopupTitle')
});

// delete all existing and opened alerts
var els = document.getElementsByClassName('overlay');

while (els[0]) {
els[0].classList.remove('active')
}

clearErrorDivs();

var success = document.createElement('div');
success.setAttribute('id', 'proxyFail');

if(close == true){
success.classList.add('overlay');
}
else{
success.removeAttribute('hidden', 'hidden');
success.classList.add('proxyFailMsg');
}
success.setAttribute('role', 'alert');

success.textContent = chrome.i18n.getMessage('errorProxyError');

document.getElementById("connectedMsg").innerText = "CONNECTION ERROR";
document.getElementById("tryAgainMsg").innerText = "TRY AGAIN";
document.getElementById("imgError").removeAttribute('hidden', 'hidden');
document.getElementById("dataValue").setAttribute('hidden', 'hidden');

document.getElementById("settingsConfig").setAttribute('hidden', 'hidden');

// switch visible sections, hiding welcome screen and showing the other where error is shown
document.getElementById("fixed_servers").setAttribute('hidden', 'hidden');
document.getElementById("system").removeAttribute('hidden', 'hidden');

document.getElementById("dataValue").setAttribute('hidden', 'hidden');

document.body.appendChild(success);

setTimeout(function() { success.classList.add('visible'); }, 10);
}
}

// check if extension is online
function getOnline() {
// keep track of the timeout ID so we can reset it
Expand Down Expand Up @@ -61,9 +113,13 @@ function getOnline() {
setServerIP(response.ip);

// increase interval for checks if last request was successfull and recursively call to the function
setOnlineTimerCheck(6 * defaultOnlineCheckTimeout);
setOnlineTimerCheck(5 * defaultOnlineCheckTimeout);
}
else if (xmlhttp.status == 0) {

// Badge the popup icon.
getBadge();

// show an alert and disconnect if we are connected and an error is found

// if this is not an empty array, extension popup is open
Expand All @@ -72,10 +128,10 @@ function getOnline() {
if (views.length != 0) {
if (document.getElementById("system").hidden == false) {
// trigger click on disconnect button
document.getElementById("proxyTypeSystem").click();
//document.getElementById("proxyTypeSystem").click();

// even though we clicked on disconnect, we want to see the try again screen
generateAlert(chrome.i18n.getMessage('errorProxyError'), false);
//generateAlert(chrome.i18n.getMessage('errorProxyError'), false);
//generateAlert("TEST1", false);
}
}
Expand Down Expand Up @@ -233,6 +289,9 @@ function updateProxyStats() {
setTimeout(function() {
updateProxyStats();
}, 1000);
} else {
// Badge the popup icon.
getBadge();
}
/*
console.log(xmlhttp);
Expand Down

0 comments on commit 0a56968

Please sign in to comment.