1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Run the main loop with GMainLoop

This commit is contained in:
Rodrigo Arias 2022-01-09 21:53:52 +01:00 committed by John Hernandez
parent 605ee6e99a
commit f995944734
No known key found for this signature in database
GPG Key ID: 00B2D64859378A94

View File

@ -43,6 +43,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
@ -86,15 +87,15 @@
static void _init(char* log_level, char* config_file, char* log_file, char* theme_name);
static void _shutdown(void);
static void _connect_default(const char* const account);
static gboolean _main_update(gpointer data);
pthread_mutex_t lock;
static gboolean force_quit = FALSE;
static GMainLoop* main_loop = NULL;
void
prof_run(char* log_level, char* account_name, char* config_file, char* log_file, char* theme_name)
{
gboolean cont = TRUE;
_init(log_level, config_file, log_file, theme_name);
plugins_on_start();
_connect_default(account_name);
@ -105,33 +106,9 @@ prof_run(char* log_level, char* account_name, char* config_file, char* log_file,
session_init_activity();
char* line = NULL;
while (cont && !force_quit) {
log_stderr_handler();
session_check_autoaway();
line = inp_readline();
if (line) {
ProfWin* window = wins_get_current();
cont = cmd_process_input(window, line);
free(line);
line = NULL;
} else {
cont = TRUE;
}
#ifdef HAVE_LIBOTR
otr_poll();
#endif
plugins_run_timed();
notify_remind();
session_process_events();
iq_autoping_check();
ui_update();
#ifdef HAVE_GTK
tray_update();
#endif
}
main_loop = g_main_loop_new(NULL, TRUE);
g_timeout_add(1000/60, _main_update, NULL);
g_main_loop_run(main_loop);
}
void
@ -140,6 +117,40 @@ prof_set_quit(void)
force_quit = TRUE;
}
static gboolean
_main_update(gpointer data)
{
log_stderr_handler();
session_check_autoaway();
gboolean cont = TRUE;
char *line = inp_readline();
if (line) {
ProfWin* window = wins_get_current();
cont = cmd_process_input(window, line);
free(line);
line = NULL;
}
#ifdef HAVE_LIBOTR
otr_poll();
#endif
plugins_run_timed();
notify_remind();
session_process_events();
iq_autoping_check();
ui_update();
#ifdef HAVE_GTK
tray_update();
#endif
if (!cont)
g_main_loop_quit(main_loop);
// Always repeat
return TRUE;
}
static void
_connect_default(const char* const account)
{