From 9bf9dbe875fd8e07f313d881a7b721e9762dcd64 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 6 Sep 2013 21:37:16 -0400 Subject: [PATCH] better way to check connection status --- src/main.c | 2 ++ src/prompt.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 8d71e4d..68808a7 100644 --- a/src/main.c +++ b/src/main.c @@ -238,9 +238,11 @@ static void do_tox(Tox *m, ToxWindow *prompt) } } else if (!dht_on && tox_isconnected(m)) { dht_on = true; + prompt_update_connectionstatus(prompt, dht_on); wprintw(prompt->window, "\nDHT connected.\n"); } else if (dht_on && !tox_isconnected(m)) { dht_on = false; + prompt_update_connectionstatus(prompt, dht_on); wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n"); } diff --git a/src/prompt.c b/src/prompt.c index 6852e49..40165d2 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -77,6 +77,13 @@ void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status) statusbar->status = status; } +/* Updates own connection status */ +void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected) +{ + StatusBar *statusbar = (StatusBar *) prompt->s; + statusbar->is_online = is_connected; +} + void prompt_onFriendRequest(ToxWindow *prompt, uint8_t *key, uint8_t *data, uint16_t length) { int n = add_req(key); @@ -584,7 +591,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m) werase(statusbar->topline); - if (tox_isconnected(m)) { + if (statusbar->is_online) { int colour = WHITE; char *status_text = "Unknown";