save cooldown for tox profile (10sec after last) and save on exit

This commit is contained in:
2024-03-12 12:39:06 +01:00
parent dc081ae2aa
commit aaf8c6adc1
3 changed files with 10 additions and 5 deletions

View File

@@ -1,5 +1,4 @@
#include "./tox_client.hpp"
#include "toxcore/tox.h"
// meh, change this
#include <exception>
@@ -121,10 +120,13 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password)
}
ToxClient::~ToxClient(void) {
if (_tox_profile_dirty) {
saveToxProfile();
}
tox_kill(_tox);
}
bool ToxClient::iterate(void) {
bool ToxClient::iterate(float time_delta) {
Tox_Err_Events_Iterate err_e_it = TOX_ERR_EVENTS_ITERATE_OK;
auto* events = tox_events_iterate(_tox, false, &err_e_it);
if (err_e_it == TOX_ERR_EVENTS_ITERATE_OK && events != nullptr) {
@@ -136,7 +138,8 @@ bool ToxClient::iterate(void) {
tox_events_free(events);
if (_tox_profile_dirty) {
_save_heat -= time_delta;
if (_tox_profile_dirty && _save_heat <= 0.f) {
saveToxProfile();
}
@@ -180,5 +183,6 @@ void ToxClient::saveToxProfile(void) {
}
_tox_profile_dirty = false;
_save_heat = 10.f;
}