1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-13 02:03:03 +01:00

autosave every 60 seconds

This commit is contained in:
Jfreegman 2014-07-08 14:46:50 -04:00
parent 442f68cd31
commit 5b9fd70f30
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 17 additions and 7 deletions

View File

@ -46,6 +46,12 @@ uint64_t get_unix_time(void)
return current_unix_time;
}
/* Returns 1 if connection has timed out, 0 otherwise */
int timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout)
{
return timestamp + timeout <= curtime;
}
/* Get the current local time */
struct tm *get_time(void)
{
@ -135,12 +141,6 @@ int wcs_to_mbs_buf(char *buf, const wchar_t *string, size_t n)
return len;
}
/* Returns 1 if connection has timed out, 0 otherwise */
int timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout)
{
return timestamp + timeout <= curtime;
}
/* Colours the window tab according to type. Beeps if is_beep is true */
void alert_window(ToxWindow *self, int type, bool is_beep)
{

View File

@ -67,6 +67,8 @@ ToxAv *av;
char *DATA_FILE = NULL;
ToxWindow *prompt = NULL;
#define AUTOSAVE_FREQ 60
struct arg_opts {
int ignore_data_file;
int use_ipv4;
@ -640,13 +642,21 @@ int main(int argc, char *argv[])
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
sort_friendlist_index();
prompt_init_statusbar(prompt, m);
uint64_t last_save = get_unix_time();
while (true) {
update_unix_time();
do_toxic(m, prompt);
uint64_t cur_time = get_unix_time();
if (timed_out(last_save, cur_time, AUTOSAVE_FREQ)) {
store_data(m, DATA_FILE);
last_save = cur_time;
}
usleep(40000);
}