Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load global scripts #365

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,12 @@ void script_init(void)
LOG_I("Loading scripts from %s\n", dir);
sys_list_dir(dir, on_user_script, NULL);
}

if (sys_get_global_dir()) {
snprintf(dir, sizeof(dir), "%s/scripts", sys_get_global_dir());
LOG_I("Loading scripts from %s\n", dir);
sys_list_dir(dir, on_user_script, NULL);
}
}

void script_release(void)
Expand Down
19 changes: 19 additions & 0 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ static const char *get_user_dir_unix(void *user)
return ret;
}

static const char *get_global_dir_unix(void *user)
{
return "/etc/goxel";
}

static void init_unix(void) __attribute__((constructor));
static void init_unix(void)
{
sys_callbacks.get_user_dir = get_user_dir_unix;
sys_callbacks.get_global_dir = get_global_dir_unix;
}

#endif
Expand Down Expand Up @@ -192,6 +198,19 @@ const char *sys_get_user_dir(void)
return get_user_dir_fallback();
}

/*
* Function: sys_get_global_dir
* Return the global config directory for goxel
*
* On linux, this should be /etc/goxel.
*/
const char *sys_get_global_dir(void)
{
if (sys_callbacks.get_global_dir)
return sys_callbacks.get_global_dir(sys_callbacks.user);
return NULL;
}

const char *sys_get_clipboard_text(void* user)
{
if (sys_callbacks.get_clipboard_text)
Expand Down
9 changes: 9 additions & 0 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct {
void (*log)(void *user, const char *msg);
void (*set_window_title)(void *user, const char *title);
const char *(*get_user_dir)(void *user);
const char *(*get_global_dir)(void *user);
const char *(*get_clipboard_text)(void* user);
void (*set_clipboard_text)(void *user, const char *text);
void (*show_keyboard)(void *user, bool has_text);
Expand Down Expand Up @@ -92,6 +93,14 @@ int sys_delete_file(const char *path);
*/
const char *sys_get_user_dir(void);

/*
* Function: sys_get_global_dir
* Return the global config directory for goxel
*
* On linux, this should be /etc/goxel.
*/
const char *sys_get_global_dir(void);

/*
* Function: sys_make_dir
* Create all the directories parent of a given file path if they do not
Expand Down
Loading