Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions serverstatus@maksmokriev/files/serverstatus@maksmokriev/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ MyDesklet.prototype = {
this.settings.bind("TextColorWARN", "TextColorWARN", this.onSettingsChanged.bind(this));
this.settings.bind("TextColorERR", "TextColorERR", this.onSettingsChanged.bind(this));
this.settings.bind("ContainerBgColor", "ContainerBgColor", this.onSettingsBgChanged.bind(this));
this.settings.bind("BoxBgColor", "BoxBgColor", this.onSettingsBgChanged.bind(this));
this.settings.bind("FontSize", "FontSize", this.onSettingsBgChanged.bind(this));
this.settings.bind("BoxBgColor", "BoxBgColor", this.onSettingsChanged.bind(this));
this.settings.bind("FontSize", "FontSize", this.onSettingsChanged.bind(this));
this.settings.bind("ContainerFixedWidth", "ContainerFixedWidth", this.onSettingsBgChanged.bind(this));
this.settings.bind("ContainerWidth", "ContainerWidth", this.onSettingsBgChanged.bind(this));

Expand Down Expand Up @@ -86,16 +86,23 @@ MyDesklet.prototype = {

} else {
this.updateServersDisplay();
//Delay the first updateStatus call by 10 seconds
Mainloop.timeout_add_seconds(5, () => {
this.updateStatus();
//After the first call, we start a periodic update
this.mainloop = Mainloop.timeout_add_seconds(this.TimeRepeat, () => {

if (!this.mainloop || this.oldTimeRepeat != this.TimeRepeat) {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable oldTimeRepeat is never initialized in the constructor, which means the first time this condition is evaluated, it will compare undefined != this.TimeRepeat, which will always be true. While this works for the first initialization, it would be clearer to explicitly initialize this.oldTimeRepeat = null in the _init method to make the intent explicit.

Copilot uses AI. Check for mistakes.
this.oldTimeRepeat = this.TimeRepeat;
//Delay the first updateStatus call by 5 seconds
Mainloop.timeout_add_seconds(5, () => {
this.updateStatus();
return true;
if (this.mainloop) {
Mainloop.source_remove(this.mainloop);
}
//After the first call, we start a periodic update
this.mainloop = Mainloop.timeout_add_seconds(this.TimeRepeat, () => {
this.updateStatus();
return true;
});
return false; //Return false so that this timer only runs once
});
Comment on lines +93 to 104
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial 5-second timeout is not tracked, which means if settings are changed during this initial 5-second delay, a new timeout will be created but the old one will continue to execute. This could result in updateStatus() being called and creating a new mainloop even though the settings have changed. Consider storing the initial timeout ID and removing it in the condition check, similar to how the mainloop is handled.

Copilot uses AI. Check for mistakes.
return false; //Return false so that this timer only runs once
});
}
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "A desklet that checks a host via ping or HTTP(S) and displays if it is available.",
"prevent-decorations": true,
"max-instances": "1",
"version": "1.2.0",
"version": "1.2.1",
"cinnamon-version": ["6.4"],
"main": "desklet.js",
"type": "desklet",
Expand Down