Skip to content

Commit

Permalink
refactor: client settings object is no longer global
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Jan 22, 2024
1 parent a83cc2b commit b435a71
Show file tree
Hide file tree
Showing 58 changed files with 1,815 additions and 1,451 deletions.
28 changes: 18 additions & 10 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void api_display(const char *const msg)
}

self_window = get_active_window();
line_info_add(self_window, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
line_info_add(self_window, user_toxic->c_config, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}

FriendsList api_get_friendslist(void)
Expand Down Expand Up @@ -105,7 +105,7 @@ void api_send(const char *msg)

snprintf((char *) self_window->chatwin->line, sizeof(self_window->chatwin->line), "%s", msg);
add_line_to_hist(self_window->chatwin);
int id = line_info_add(self_window, true, name, NULL, OUT_MSG, 0, 0, "%s", msg);
const int id = line_info_add(self_window, user_toxic->c_config, true, name, NULL, OUT_MSG, 0, 0, "%s", msg);
cqueue_add(self_window->chatwin->cqueue, msg, strlen(msg), OUT_MSG, id);
free(name);
}
Expand Down Expand Up @@ -138,7 +138,11 @@ void draw_handler_help(WINDOW *win)

void cmd_run(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE])
{
UNUSED_VAR(toxic);
if (toxic == NULL || self == NULL) {
return;
}

const Client_Config *c_config = toxic->c_config;

FILE *fp;
const char *error_str;
Expand All @@ -153,7 +157,7 @@ void cmd_run(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg
error_str = "Only one argument allowed.";
}

line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
return;
}

Expand All @@ -162,27 +166,31 @@ void cmd_run(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*arg
if (fp == NULL) {
error_str = "Path does not exist.";

line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, error_str);
return;
}

run_python(fp, argv[1]);
fclose(fp);
}

void invoke_autoruns(WINDOW *window, ToxWindow *self)
void invoke_autoruns(WINDOW *window, ToxWindow *self, const char *autorun_path)
{
char abspath_buf[PATH_MAX + 256];
char err_buf[PATH_MAX + 128];

if (user_settings->autorun_path[0] == '\0') {
if (autorun_path == NULL) {
return;
}

if (string_is_empty(autorun_path)) {
return;
}

DIR *d = opendir(user_settings->autorun_path);
DIR *d = opendir(autorun_path);

if (d == NULL) {
snprintf(err_buf, sizeof(err_buf), "Autorun path does not exist: %s", user_settings->autorun_path);
snprintf(err_buf, sizeof(err_buf), "Autorun path does not exist: %s", autorun_path);
api_display(err_buf);
return;
}
Expand All @@ -197,7 +205,7 @@ void invoke_autoruns(WINDOW *window, ToxWindow *self)
size_t path_len = strlen(dir->d_name);

if (!strcmp(dir->d_name + path_len - 3, ".py")) {
snprintf(abspath_buf, sizeof(abspath_buf), "%s%s", user_settings->autorun_path, dir->d_name);
snprintf(abspath_buf, sizeof(abspath_buf), "%s%s", autorun_path, dir->d_name);
FILE *fp = fopen(abspath_buf, "r");

if (fp == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int do_plugin_command(int num_args, char (*args)[MAX_STR_SIZE]);
int num_registered_handlers(void);
int help_max_width(void);
void draw_handler_help(WINDOW *win);
void invoke_autoruns(WINDOW *w, ToxWindow *self);
void invoke_autoruns(WINDOW *w, ToxWindow *self, const char *autorun_path);
void cmd_run(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*argv)[MAX_STR_SIZE]);

#endif /* API_H */
Loading

0 comments on commit b435a71

Please sign in to comment.