mirror of
https://github.com/Tha14/toxic.git
synced 2025-06-20 04:26:36 +02:00
Add config option to set data file auto-save frequency
This commit is contained in:
@ -122,8 +122,8 @@ static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
#ifdef PYTHON
|
||||
"/run",
|
||||
#endif /* PYTHON */
|
||||
"/title",
|
||||
"/sendfile",
|
||||
"/title",
|
||||
};
|
||||
|
||||
/* Returns true if input command is in the special_commands array. */
|
||||
|
@ -63,6 +63,7 @@ static struct ui_strings {
|
||||
const char *show_welcome_msg;
|
||||
const char *show_connection_msg;
|
||||
const char *nodeslist_update_freq;
|
||||
const char *autosave_freq;
|
||||
|
||||
const char *line_join;
|
||||
const char *line_quit;
|
||||
@ -90,6 +91,7 @@ static struct ui_strings {
|
||||
"show_welcome_msg",
|
||||
"show_connection_msg",
|
||||
"nodeslist_update_freq",
|
||||
"autosave_freq",
|
||||
"line_join",
|
||||
"line_quit",
|
||||
"line_alert",
|
||||
@ -117,6 +119,7 @@ static void ui_defaults(struct user_settings *settings)
|
||||
settings->show_welcome_msg = SHOW_WELCOME_MSG_ON;
|
||||
settings->show_connection_msg = SHOW_CONNECTION_MSG_ON;
|
||||
settings->nodeslist_update_freq = 7;
|
||||
settings->autosave_freq = 600;
|
||||
|
||||
snprintf(settings->line_join, LINE_HINT_MAX + 1, "%s", LINE_JOIN);
|
||||
snprintf(settings->line_quit, LINE_HINT_MAX + 1, "%s", LINE_QUIT);
|
||||
@ -370,6 +373,7 @@ int settings_load(struct user_settings *s, const char *patharg)
|
||||
|
||||
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
||||
config_setting_lookup_int(setting, ui_strings.nodeslist_update_freq, &s->nodeslist_update_freq);
|
||||
config_setting_lookup_int(setting, ui_strings.autosave_freq, &s->autosave_freq);
|
||||
|
||||
if (config_setting_lookup_string(setting, ui_strings.line_join, &str)) {
|
||||
snprintf(s->line_join, sizeof(s->line_join), "%s", str);
|
||||
|
@ -54,6 +54,7 @@ struct user_settings {
|
||||
int show_welcome_msg; /* boolean */
|
||||
int show_connection_msg; /* boolean */
|
||||
int nodeslist_update_freq; /* int (<= 0 to disable updates) */
|
||||
int autosave_freq; /* int (<= 0 to disable autosave) */
|
||||
|
||||
char line_join[LINE_HINT_MAX + 1];
|
||||
char line_quit[LINE_HINT_MAX + 1];
|
||||
|
@ -94,7 +94,6 @@ ToxWindow *prompt = NULL;
|
||||
#define DATANAME "toxic_profile.tox"
|
||||
#define BLOCKNAME "toxic_blocklist"
|
||||
|
||||
#define AUTOSAVE_FREQ 600
|
||||
#define MIN_PASSWORD_LEN 6
|
||||
#define MAX_PASSWORD_LEN 64
|
||||
|
||||
@ -1364,7 +1363,7 @@ int main(int argc, char **argv)
|
||||
|
||||
time_t cur_time = get_unix_time();
|
||||
|
||||
if (timed_out(last_save, AUTOSAVE_FREQ)) {
|
||||
if (user_settings->autosave_freq > 0 && timed_out(last_save, user_settings->autosave_freq)) {
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
|
||||
if (store_data(m, DATA_FILE) != 0) {
|
||||
|
Reference in New Issue
Block a user