save cooldown for tox profile (10sec after last) and save on exit
This commit is contained in:
parent
dc081ae2aa
commit
aaf8c6adc1
@ -376,7 +376,7 @@ Screen* MainScreen::render(float time_delta, bool&) {
|
||||
}
|
||||
|
||||
Screen* MainScreen::tick(float time_delta, bool& quit) {
|
||||
quit = !tc.iterate(); // compute
|
||||
quit = !tc.iterate(time_delta); // compute
|
||||
|
||||
tcm.iterate(time_delta); // compute
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
||||
std::string _tox_profile_path;
|
||||
std::string _tox_profile_password;
|
||||
bool _tox_profile_dirty {true}; // set in callbacks
|
||||
float _save_heat {0.f};
|
||||
|
||||
public:
|
||||
//ToxClient(/*const CommandLine& cl*/);
|
||||
@ -34,7 +35,7 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
||||
void setDirty(void) { _tox_profile_dirty = true; }
|
||||
|
||||
// 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 setToxProfilePath(const std::string& new_path) { _tox_profile_path = new_path; }
|
||||
|
Loading…
Reference in New Issue
Block a user