Skip to content

Commit

Permalink
cleanup entries
Browse files Browse the repository at this point in the history
  • Loading branch information
itzandroidtab committed Mar 27, 2024
1 parent 497e473 commit 1559b56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
13 changes: 4 additions & 9 deletions ui/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,8 @@ namespace menu {
// notify the user we removed the entry
write_result(entries[i - 1].str, parse_t::deleted_entry);

// move everything after the current entry back by one
for (uint32_t j = i - 1; j < entries.size(); j++) {
entries[j] = entries[j + 1];
}

// remove the last entry
entries.pop_back();
// erase the current entry
entries.erase(&entries[i - 1]);
}

// write the buffer to memory
Expand Down Expand Up @@ -822,9 +817,9 @@ namespace menu {
const auto entries = Storage::get_entries();
uint32_t length = 0;

for (uint32_t i = 0; i < entries.size(); i++) {
for (const auto& entry : entries) {
// increment the length for the total file size
length += get_entry_length(entries[i]);
length += get_entry_length(entry);
}

// add the header size
Expand Down
30 changes: 18 additions & 12 deletions ui/totp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ namespace menu {
// get the rtc time
const auto time = Rtc::get();

// get a reference to the current entry
const auto& entry = entries[current];

// check if we should update the hashes
if ((time != last_epoch) || (last_interval != entries[current].interval)) {
if ((time != last_epoch) || (last_interval != entry.interval)) {
// only update the last epoch and runtime when the
// time has changed
if (time != last_epoch) {
Expand All @@ -202,7 +205,7 @@ namespace menu {

// update the seconds left in this cycle
klib::string::itoa(
entries[current].interval - (last_epoch.value % entries[current].interval),
entry.interval - (last_epoch.value % entry.interval),
seconds_left_buf
);

Expand All @@ -211,30 +214,30 @@ namespace menu {
totp_changed = true;

// update the last interval
last_interval = entries[current].interval;
last_interval = entry.interval;
}

if (totp_changed) {
// update the tokens
const uint32_t current_token = get_token(entries[current], last_epoch);
const uint32_t current_token = get_token(entry, last_epoch);

// copy the token to the buffer and set the width
// based on the amount of digits
klib::string::itoa(current_token, current_token_buf);
klib::string::set_width(current_token_buf,
static_cast<uint8_t>(entries[current].digits), '0'
static_cast<uint8_t>(entry.digits), '0'
);

// get the next token
const uint32_t next_token = get_token(
entries[current], last_epoch + klib::time::s(entries[current].interval)
entry, last_epoch + klib::time::s(entry.interval)
);

// copy the token to the buffer and set the width
// based on the amount of digits
klib::string::itoa(next_token, next_token_buf);
klib::string::set_width(next_token_buf,
static_cast<uint8_t>(entries[current].digits), '0'
static_cast<uint8_t>(entry.digits), '0'
);
}

Expand All @@ -253,11 +256,14 @@ namespace menu {
return;
}

// get a reference to the current entry
const auto& entry = entries[current];

// clear the background
frame_buffer.clear(klib::graphics::black);

// draw the entry text with a small font above the token if we have any
if (klib::string::strlen(entries[current].str)) {
if (klib::string::strlen(entry.str)) {
// draw the title at the top of the screen
screen_base::small_text::template draw<FrameBuffer>(
frame_buffer,
Expand All @@ -271,9 +277,9 @@ namespace menu {
// draw the profile name below the title
screen_base::large_text::template draw<FrameBuffer>(
frame_buffer,
entries[current].str,
entry.str,
klib::vector2i{
(240 - static_cast<int32_t>(klib::string::strlen(entries[current].str) * screen_base::large_text::font::width)) / 2,
(240 - static_cast<int32_t>(klib::string::strlen(entry.str) * screen_base::large_text::font::width)) / 2,
9 + screen_base::small_text::font::height
} - offset.cast<int32_t>(),
klib::graphics::white
Expand Down Expand Up @@ -332,13 +338,13 @@ namespace menu {

const klib::time::ms runtime = (
(last_runtime - last_epoch_runtime) + static_cast<klib::time::ms>(
klib::time::s(last_epoch.value % entries[current].interval)
klib::time::s(last_epoch.value % entry.interval)
)
);

// draw all the circles
for (uint32_t i = 0; i < sizeof(lookuptable_sin) / sizeof(lookuptable_sin[0]); i++) {
draw_timer(frame_buffer, entries[current].interval, position, runtime, lookuptable_sin[i], lookuptable_cos[i]);
draw_timer(frame_buffer, entry.interval, position, runtime, lookuptable_sin[i], lookuptable_cos[i]);
}

// draw the time left in seconds in the circle
Expand Down

0 comments on commit 1559b56

Please sign in to comment.