improve tox client (prevent excessive saving)
and reorder construction/destruction order of plugin manager in main
This commit is contained in:
parent
4b39541d93
commit
4b7ef79f38
@ -198,7 +198,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
}
|
||||
|
||||
PluginManager pm;
|
||||
|
||||
ToxEventLogger tel{std::cout}; // TODO: config
|
||||
|
||||
@ -222,6 +221,8 @@ int main(int argc, char** argv) {
|
||||
ToxMessageManager tmm{rmm, cr, tcm, tc, tc};
|
||||
ToxTransferManager ttm{rmm, cr, tcm, tc, tc};
|
||||
|
||||
PluginManager pm;
|
||||
|
||||
{ // setup plugin instances
|
||||
g_provideInstance<ConfigModelI>("ConfigModelI", "host", &conf);
|
||||
g_provideInstance<Contact3Registry>("Contact3Registry", "1", "host", &cr);
|
||||
@ -313,7 +314,7 @@ int main(int argc, char** argv) {
|
||||
const bool tick = time_delta_tick >= last_min_interval;
|
||||
|
||||
if (tick) {
|
||||
quit = !tc.iterate();
|
||||
quit = !tc.iterate(time_delta_tick);
|
||||
tcm.iterate(time_delta_tick);
|
||||
ttm.iterate();
|
||||
|
||||
|
@ -155,10 +155,13 @@ ToxClient::ToxClient(ConfigModelI& conf, std::string_view save_path, std::string
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -170,7 +173,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();
|
||||
}
|
||||
|
||||
@ -214,5 +218,6 @@ void ToxClient::saveToxProfile(void) {
|
||||
}
|
||||
|
||||
_tox_profile_dirty = false;
|
||||
_save_heat = 10.f;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,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(ConfigModelI& conf, std::string_view save_path, std::string_view save_password);
|
||||
@ -35,7 +36,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; }
|
||||
@ -48,4 +49,3 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
||||
void saveToxProfile(void);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user