4 Commits

Author SHA1 Message Date
PoliEcho e51088eb26 add download progress bar
/ sync-to-origin (push) Has been cancelled
2025-04-14 20:03:48 +02:00
PoliEcho ad6f748899 add homework checkbox to README
/ sync-to-origin (push) Waiting to run
2025-04-14 07:26:06 +00:00
PoliEcho 1d0d4e2362 update README to reflect new aditions
/ sync-to-origin (push) Waiting to run
2025-04-14 09:24:23 +02:00
PoliEcho a35242b420 fix attachment window not disapearing 2025-04-14 09:22:39 +02:00
2 changed files with 40 additions and 3 deletions
+2 -1
View File
@@ -10,5 +10,6 @@
> - [x] Login
> - [x] Marks
> - [x] Timetable
> - [ ] Komens
> - [x] Komens
> - [ ] Absence
> - [ ] Homework
+38 -2
View File
@@ -5,10 +5,12 @@
#include "types.h"
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <curses.h>
#include <cwchar>
#include <future>
#include <menu.h>
#include <ncurses.h>
#include <nlohmann/json.hpp>
@@ -199,12 +201,42 @@ void komens_page(koment_type type) {
clrtoeol();
refresh();
char progress_bar[20];
std::fill(progress_bar, progress_bar + 20, '.');
LimitedInt progress_index(0, 0, sizeof(progress_bar) - 1);
// Download the attachment
bakaapi::download_attachment(
auto future = std::async(
std::launch::async, bakaapi::download_attachment,
resp_from_api["Messages"][item_index(current_item(
komens_choise_menu.menu))]["Attachments"][index]["Id"]
.get<std::string>(),
path);
while (true) {
if (future.wait_for(std::chrono::seconds(1)) ==
std::future_status::ready) {
// Future has completed
int result = future.get();
if (result != 0) {
attron(COLOR_PAIR(COLOR_RED));
mvprintw(LINES - 1, 0, "Download failed with error code: %d",
result);
attroff(COLOR_PAIR(COLOR_RED));
} else {
attron(COLOR_PAIR(COLOR_GREEN));
mvprintw(LINES - 1, 0, "Download completed successfully");
attroff(COLOR_PAIR(COLOR_GREEN));
}
break;
} else {
progress_bar[progress_index] = '#';
// Future is still running
mvprintw(LINES - 1, 0, "%s", progress_bar);
progress_bar[progress_index] = '.';
progress_index++;
}
}
komens_print_usage_message();
}
}
@@ -273,7 +305,7 @@ void insert_content(WINDOW *content_win, WINDOW *attachment_win,
mvwprintw(attachment_win, j + 1, 0, "%zu>", j + 1);
wattroff(attachment_win, COLOR_PAIR(COLOR_MAGENTA));
}
{ // remove duplicating spaces
{ // remove duplicating edges
unsigned short attachment_win_top, attachment_win_left,
attachment_win_height, attachment_win_width;
getbegyx(attachment_win, attachment_win_top, attachment_win_left);
@@ -284,6 +316,10 @@ void insert_content(WINDOW *content_win, WINDOW *attachment_win,
}
refresh();
wrefresh(attachment_win);
} else {
// remove attachment window if there are no attachments
wclear(attachment_win);
wrefresh(attachment_win);
}
}