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

This commit is contained in:
Green Sky 2024-03-12 12:39:06 +01:00
parent dc081ae2aa
commit aaf8c6adc1
No known key found for this signature in database
3 changed files with 10 additions and 5 deletions

View File

@ -376,7 +376,7 @@ Screen* MainScreen::render(float time_delta, bool&) {
} }
Screen* MainScreen::tick(float time_delta, bool& quit) { Screen* MainScreen::tick(float time_delta, bool& quit) {
quit = !tc.iterate(); // compute quit = !tc.iterate(time_delta); // compute
tcm.iterate(time_delta); // compute tcm.iterate(time_delta); // compute

View File

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

View File

@ -22,6 +22,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
std::string _tox_profile_path; std::string _tox_profile_path;
std::string _tox_profile_password; std::string _tox_profile_password;
bool _tox_profile_dirty {true}; // set in callbacks bool _tox_profile_dirty {true}; // set in callbacks
float _save_heat {0.f};
public: public:
//ToxClient(/*const CommandLine& cl*/); //ToxClient(/*const CommandLine& cl*/);
@ -34,7 +35,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
void setDirty(void) { _tox_profile_dirty = true; } void setDirty(void) { _tox_profile_dirty = true; }
// returns false when we shoul stop the program // returns false when we shoul stop the program
bool iterate(void); bool iterate(float time_delta);
void stop(void); // let it know it should exit void stop(void); // let it know it should exit
void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; } void setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }