Skip to content

Commit a344c49

Browse files
committed
fix: dont run updater if updates are already 0
1 parent 7befa95 commit a344c49

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

panel/modules/arch_updates.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,29 @@ static inline void set_updates(ModuleState* state, const char* count_string)
1717
}
1818
}
1919

20+
char* get_updates(void)
21+
{
22+
char buffer[32];
23+
FILE* fp = popen("checkupdates | wc -l", "r");
24+
25+
fgets(buffer, 32, fp);
26+
buffer[strcspn(buffer, "\n")] = 0;
27+
28+
pclose(fp);
29+
return strdup(buffer);
30+
}
31+
2032
static void module_on_click(ModuleState* state)
2133
{
2234
(void)state;
35+
36+
char* updates = get_updates();
37+
if (strcmp(updates, "0") == 0) {
38+
free(updates);
39+
return;
40+
}
41+
free(updates);
42+
2343
system("kitty -e sh -c '"
2444
"sudo pacman -Syu;"
2545
"read -n1 -srp \"Press any key to exit...\""
@@ -39,15 +59,11 @@ void* module_init(void* _state)
3959
}
4060
free(binary_path);
4161

42-
char buffer[32];
62+
set_updates(state, "0");
4363
while (*state->running) {
44-
FILE* fp = popen("checkupdates | wc -l", "r");
45-
46-
fgets(buffer, 32, fp);
47-
buffer[strcspn(buffer, "\n")] = 0;
48-
set_updates(state, buffer);
49-
50-
pclose(fp);
64+
char* updates = get_updates();
65+
set_updates(state, updates);
66+
free(updates);
5167
msleep(60 * 60 * 1000);
5268
}
5369

0 commit comments

Comments
 (0)