Skip to content

Commit

Permalink
Correction des bugs
Browse files Browse the repository at this point in the history
(La prog evenementielle ça s'invente pas !)
- appel de fonction en cascade. connectComplete() appel unread()
Ajouts des listeners.
- Ajoute un slash a la fin de l'adresse si besoin
- lors du changement du login ou mdp : enleve l'auth et ce connect()
  • Loading branch information
Purexo committed Dec 14, 2014
1 parent f4c3eaa commit 047b62f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 39 deletions.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 72 additions & 34 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ var preferences = require("sdk/simple-prefs").prefs;
var Request = require("sdk/request").Request;
var querystring = require("sdk/querystring");
var notifications = require("sdk/notifications");
/* --- Listener --- */
require("sdk/simple-prefs").on("url", normalizeUserURL);
require("sdk/simple-prefs").on("login", nullAuth);
require("sdk/simple-prefs").on("password", nullAuth);

/* --- variable perso --- */
var api = "/p/api/greader.php/";
var api = "p/api/greader.php/"; // le slash de l'adresse est deja mis, s'il est doublé, le formulaire d'inscription bug
var login = "p/i/?a=formLogin";
var auth = null;
var nbunread = 0;
var json = null;
Expand Down Expand Up @@ -43,31 +48,9 @@ function refreshRSS() {
/* --- --- */
if (auth == null) {
connect();
if (!succes) {
console.log("echec de la connection");
button.badge = -1;
button.badgeColor = preferences.badgeNotEmpty;
button.icon = "./error.png";

notifications.notify({
text: "Connection impossible",
iconURL: "./error.png"
});
return null;
}
} else {
unread();
}
unread();
button.badge = nbunread;
button.badgeColor = nbunread > 0 ? preferences.badgeNotEmpty : preferences.badgeEmpty;
button.icon = nbunread > 0 ? "./icon.png" : "./empty.png";

notifications.notify({
title: "FreshRSS",
text: "Vous avez : " + nbunread + " articles non lu",
onClick: function (data) {
tabs.open(preferences.url);
}
});
}

function connect() {
Expand All @@ -77,8 +60,16 @@ function connect() {
}).get();
}
function connectComplete(response) {
console.log("connectComplete : \n" + response.text);
auth = querystring.parse(response.text, '\n', '=').Auth;
if (auth != null) succes = true;
succes = auth != null;

if (!succes) {
console.log("connectComplete : echec");
error("Connection impossible");
} else {
unread();
}
}

function unread() {
Expand All @@ -92,9 +83,45 @@ function unread() {
}).get();
}
function unreadComplete(response) {
console.log(response.text + "\n" + response.json.max);
nbunread = response.json.max;
json = response.json;
text = response.text;

if (json != null) {
console.log("unreadComplete : Succes ! ");
nbunread = json.max;

button.badge = nbunread;
button.badgeColor = nbunread > 0 ? preferences.badgeNotEmpty : preferences.badgeEmpty;
button.icon = nbunread > 0 ? "./icon.png" : "./empty.png";

notifications.notify({
title: "FreshRSS",
text: "Vous avez : " + nbunread + " articles non lu",
iconURL: button.icon,
onClick: function (data) {
tabs.open(preferences.url + login);
}
});
} else {
console.log("unreadComplete : echec ! \n" + text);
error(text);
}
}

function error(text) {
nbunread = -1;
button.badge = nbunread;
button.badgeColor = preferences.badgeNotEmpty;
button.icon = "./error.png";

notifications.notify({
title: "FreshRSS",
text: "Error : " + text,
iconURL: button.icon,
onClick: function (data) {
tabs.open(preferences.url + login);
}
});
}

function sleep(milliseconds) {
Expand All @@ -108,17 +135,28 @@ function sleep(milliseconds) {

function loop () { // actualise regulierement l'addon
refreshRSS();
setTimeout(loop(), preferences.delay * 60 * 1000);
setTimeout(loop(), preferences.delay * 60 * 1000 / 2);
}

function normalizeUserURL() { // l'URL doi finir par un slash
var url = preferences.url;
preferences.url = !url.endsWith("/") ? url + "/" : url;
console.log(preferences.url);
}

function nullAuth(prefName) {
auth = null;
connect();
}

/* --- test ---
/* --- test --- */
preferences.url = "https://purexo.eu/FreshRSS/";
preferences.login = "Purexo";
preferences.password = "";
preferences.login = "demo";
preferences.password = "demodemo";

/* --- Programmme ---*/
connect();
unread();
preferences.delay = 15;
normalizeUserURL();

loop();
/* --- --- */
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "A FreshRSS Notifier for smart people \n N'oubliez pas d'activer l'api \n siteweb : https://purexo.eu/ \n addons : https://addons.mozilla.org/fr/firefox/user/ptheo93/",
"homepage": "https://github.com/purexo/FreshRSS-Notify",
"author": "Purexo",
"license": "MPL 2.0",
"version": "0.1",
"license": "GPL 3",
"version": "0.2",

"preferences": [
{
Expand All @@ -32,22 +32,22 @@
{
"type": "integer",
"name": "delay",
"value": "15",
"value": 15,
"title": "delay d'actualisation automatique :",
"description": "exprimé en minutes"
},
{
"type": "string",
"name": "badgeEmpty",
"value": "green",
"title": "Color 0 unread:",
"title": "Color 0 unread : ",
"hidden": true
},
{
"type": "string",
"name": "badgeNotEmpty",
"value": "red",
"title": "Color many unread",
"title": "Color many unread : ",
"hidden": true
}
]
Expand Down

0 comments on commit 047b62f

Please sign in to comment.