Skip to content

Commit 29e593f

Browse files
authored
SpiceSpy v5.1.0: Better update of the number of comments (#6851)
1 parent 8971820 commit 29e593f

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

SpiceSpy@claudiux/files/SpiceSpy@claudiux/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v5.1.0~20250204
2+
* Better update of the number of comments.
3+
* Improved menu management.
4+
15
### v5.0.0~20250128
26
* Fixes menu display.
37
* Changes this applet settings.

SpiceSpy@claudiux/files/SpiceSpy@claudiux/applet.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ const CACHE_UPDATER = SCRIPTS_DIR + "/spices-cache-updater.py";
3434
const TYPES = ["actions", "applets", "desklets", "extensions", "themes"];
3535
const SPICES_URL = "https://cinnamon-spices.linuxmint.com";
3636
const HTML_COUNT_ID = "count";
37-
const COMMENTS_REGEX = new RegExp(`<[a-z]+ id="${HTML_COUNT_ID}">([0-9]+)</[a-z]+>`);
37+
38+
// <h3 class="cs-comments-amount"><span id="count">173</span> Comments</h3>
39+
//~ const COMMENTS_REGEX = new RegExp(`<[a-z]+ id="${HTML_COUNT_ID}">([0-9]+)</[a-z]+>`);
40+
const COMMENTS_REGEX = new RegExp(`<span id="${HTML_COUNT_ID}">([0-9]+)</span>`);
3841
const ISSUES_REGEX = new RegExp(`([0-9]+) Open`);
3942

4043
const DIR_MAP = {
@@ -359,7 +362,7 @@ class SpiceSpy extends Applet.TextIconApplet {
359362
} // End of constructor
360363

361364
get_user_settings() {
362-
this.settings.bind("update-interval-hours", "update_interval", this.update_interval_value.bind(this));
365+
this.settings.bind("update-interval-hours", "update_interval", () => { this.update_interval_value() });
363366
if (this.settings.getValue("update-interval") > 0) {
364367
// Converts old "update-interval" in minutes to new this.update_interval in hours.
365368
this.update_interval = 0.5 * Math.round(this.settings.getValue("update-interval") / 30);
@@ -368,7 +371,7 @@ class SpiceSpy extends Applet.TextIconApplet {
368371
//~ this.settings.bind("standard-opacity", "standard_opacity", this.make_menu.bind(this));
369372
this.settings.bind("standard-opacity", "standard_opacity");
370373
//~ this.settings.bind("color-on-change", "color_on_change", this.make_menu.bind(this));
371-
this.settings.bind("color-on-change", "color_on_change");
374+
this.settings.bind("color-on-change", "color_on_change", () => { this.make_menu() });
372375
//~ this.settings.bind("show-icon-in-menu", "show_icon_in_menu");
373376
this.show_icon_in_menu = true;
374377
this.settings.bind("icon-size", "icon_size");
@@ -383,8 +386,8 @@ class SpiceSpy extends Applet.TextIconApplet {
383386
this.settings.bind("display-on-panel", "display_on_panel");
384387
//~ this.settings.bind("useful-only", "useful_only", this.make_menu.bind(this));
385388
this.settings.bind("useful-only", "useful_only");
386-
this.settings.bind("author-list", "author_list", this.update_authors.bind(this));
387-
this.settings.bind("uuid-list", "uuid_list", this.update_uuids.bind(this));
389+
this.settings.bind("author-list", "author_list", () => { this.update_authors() });
390+
this.settings.bind("uuid-list", "uuid_list", () => { this.update_uuids() });
388391
this.settings.bind("spices_to_spy", "spices_to_spy");
389392
this.settings.bind("old_spices_to_spy", "old_spices_to_spy");
390393
} // End of get_user_settings
@@ -547,6 +550,7 @@ class SpiceSpy extends Applet.TextIconApplet {
547550
}
548551
//~ logDebug("do_issuesJob: "+type+" "+uuid+": "+issuesNumber+" issues.");
549552
this.spices_to_spy[type][uuid]["issues"] = issuesNumber;
553+
this.make_menu();
550554
} // End of do_issuesJob
551555

552556
do_issuesJob_OLD(type, spice, command) {
@@ -584,17 +588,22 @@ class SpiceSpy extends Applet.TextIconApplet {
584588
//~ return this.is_looping;
585589
} // End of commentsJobs_loop
586590

587-
do_commentsJob(type, spice, page) {
591+
async do_commentsJob(type, spice, page) {
592+
logDebug(`do_commentsJob(${type}, ${spice}, ${page})`);
588593
if (!this.spices_to_spy[type] || !this.spices_to_spy[type][spice]) {
589594
this.commentsJobsList.push([type, spice, page]);
595+
//~ logDebug("Re-inserted at the end of the list.")
590596
return
591597
}
592598
var http = new HttpLib();
593-
let response = http.LoadAsync(page);
599+
let response = await http.LoadAsync(page.slice(0, -6));
594600
if (response.Success) {
601+
//~ logDebug("Success");
595602
let result = COMMENTS_REGEX.exec(response.Data);
603+
//~ logDebug("result: "+result);
596604
if (result && result[1]) {
597605
let count = parseInt(result[1]);
606+
//~ logDebug("count: "+count);
598607
this.spices_to_spy[type][spice]['comments'] = count;
599608
//~ this.make_menu();
600609
} else {
@@ -603,7 +612,10 @@ class SpiceSpy extends Applet.TextIconApplet {
603612
+ "Spices now OR the Cinnamon Spices changed the ID "
604613
+ "(please report if there are 0 items)");
605614
}
615+
} else {
616+
//~ logDebug("Check and mate");
606617
}
618+
this.make_menu();
607619
} // End of do_commentsJob
608620

609621
loop() {
@@ -634,9 +646,8 @@ class SpiceSpy extends Applet.TextIconApplet {
634646
this.settings.setValue("old_spices_to_spy", this.old_spices_to_spy);
635647
}
636648
this.fistTime = false;
637-
638-
//~ this.make_menu();
639649
this.set_applet_tooltip(this.metadata.name);
650+
this.make_menu();
640651

641652
let sec = Math.round(this.update_interval * 3600);
642653
this.loopId = timeout_add_seconds(sec, () => { this.loop() });
@@ -747,7 +758,7 @@ class SpiceSpy extends Applet.TextIconApplet {
747758
update_comments() {
748759
//~ const interval = 13000; //ms = 13 seconds (the spices website accepts a maximum of 5 requests per minute.)
749760
//~ var index = 0;
750-
var http = new HttpLib();
761+
//~ var http = new HttpLib();
751762
for (let type of TYPES) {
752763
let spices = this.spices_to_spy[type];
753764
for (let spice of Object.keys(spices)) {
@@ -979,6 +990,7 @@ class SpiceSpy extends Applet.TextIconApplet {
979990
if (!spice) return;
980991
this.old_spices_to_spy[spice.type][spice.uuid] = this.spices_to_spy[spice.type][spice.uuid];
981992
//~ this.settings.setValue("old_spices_to_spy", this.old_spices_to_spy);
993+
this.make_menu();
982994
} // End of mark_as_read
983995

984996
on_applet_added_to_panel() {
@@ -997,7 +1009,7 @@ class SpiceSpy extends Applet.TextIconApplet {
9971009
this.jobsLoopId = timeout_add_seconds(13, () => { this.commentsJobs_loop(); return this.is_looping; });
9981010

9991011
this.update_issues_json();
1000-
this.make_menu();
1012+
//~ this.make_menu();
10011013
} // End of on_applet_added_to_panel
10021014

10031015
on_applet_clicked() {

SpiceSpy@claudiux/files/SpiceSpy@claudiux/lib/httpLib.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function log(message, alwaysLog=false) {
99
if (DEBUG || alwaysLog) global.log("[SpicesSpy httpLib.js]: " + message);
1010
}
1111

12+
function logDebug(message) {
13+
log(message, true);
14+
}
15+
1216
function logError(error) {
1317
global.logError("\n[SpicesSpy httpLib.js]: " + error + "\n")
1418
}

SpiceSpy@claudiux/files/SpiceSpy@claudiux/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"uuid": "SpiceSpy@claudiux",
33
"name": "SpiceSpy",
44
"description": "Notifies you when there's a change to your favorite Spices on the website.",
5-
"version": "5.0.0",
5+
"version": "5.1.0",
66
"max-instances": 1,
77
"author": "claudiux"
88
}

0 commit comments

Comments
 (0)