From 8228f93d2408b1066b80a0d53ede2e4a2c6dc7ea Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Mon, 4 Sep 2023 17:38:46 +0600 Subject: [PATCH] If unedited, backend will run file/application, if edited, ublexec will --- source/ubl-utils.c | 2 -- source/ublexec.c | 48 +++++++++++++++++++++++++++++++++++++--------- source/ublexec.h | 2 +- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/source/ubl-utils.c b/source/ubl-utils.c index a273009..0225c16 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -1169,7 +1169,6 @@ int yon_config_remove_element(char *key, char *deleted){ new_data = yon_char_append(new_data,found+strlen(deleted)); } dict->data=(void*)(new_data); - // free(data); dict->flag1=1; return 1; } else return 0; @@ -1296,7 +1295,6 @@ config_str yon_config_load(char *command, int *str_len){ if (strcmp(str, "") != 0) { output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); - // printf("%s\n", str); output_strings[i] = NULL; output_strings[i] = yon_char_new(str); memset(str, 0, 4096); diff --git a/source/ublexec.c b/source/ublexec.c index 8590057..e98879f 100644 --- a/source/ublexec.c +++ b/source/ublexec.c @@ -180,14 +180,14 @@ void on_setup_command(GtkWidget *self, main_window *widgets){ int su_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck)); int sudo_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck)); int priority_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)); - char *priority = priority_check ? yon_char_append(" -p ",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin)))) : ""; + char *priority = priority_check ? yon_char_append(" --priority=",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin)))) : ""; int size; - char *command = yon_char_unite(get_run_command_command, - terminal_check ? yon_char_append(" -t ", terminal->name_simple) : "", - user_check ? yon_char_append(" -u ", user) : "", - user_check&&pkexec_check ? " -e pkexec" : "", - user_check&&su_check ? " -e su" : "", - user_check&&sudo_check ? " -e sudo" : "", + char *command = yon_char_unite(get_run_command_command, " -o", + terminal_check ? yon_char_append(" --terminal=", terminal->name_simple) : "", + user_check ? yon_char_append(" --user=", user) : "", + user_check&&pkexec_check ? " --exec=pkexec" : "", + user_check&&su_check ? " --exec=su" : "", + user_check&&sudo_check ? " --exec=sudo" : "", priority_check ? priority : "", yon_char_append(" ",target), NULL); @@ -199,8 +199,38 @@ void on_setup_command(GtkWidget *self, main_window *widgets){ } void on_command_run(GtkWidget *self, main_window *widgets){ - const char *command = gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry)); - yon_launch_thread((char*)command); + if (strcmp(gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry)),"")){ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->commandCheck))){ + const char *command = gtk_entry_get_text(GTK_ENTRY(widgets->commandEntry)); + yon_launch_thread((char*)command); + } else { + char *target = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->TargetNameEntry)); + if (target&&strcmp(target,"")){ + char *final_command; + int terminal_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)); + int chosen_terminal = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo)); + terminal_info *terminal = yon_dictionary_get_data(yon_dictionary_get_nth(main_config.terminals,chosen_terminal),terminal_info*); + int user_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck)); + char *user = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo)); + int pkexec_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck)); + int su_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck)); + int sudo_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck)); + int priority_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)); + char *priority = priority_check ? yon_char_append(" --priority=",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin)))) : ""; + int size; + char *command = yon_char_unite(get_run_command_command, + terminal_check ? yon_char_append(" --terminal=", terminal->name_simple) : "", + user_check ? yon_char_append(" --user=", user) : "", + user_check&&pkexec_check ? " --exec=pkexec" : "", + user_check&&su_check ? " --exec=su" : "", + user_check&&sudo_check ? " --exec=sudo" : "", + priority_check ? priority : "", + yon_char_append(" ",target), + NULL); + yon_launch(command); + } + } + } } // standard functions diff --git a/source/ublexec.h b/source/ublexec.h index e98e0e3..88d1603 100644 --- a/source/ublexec.h +++ b/source/ublexec.h @@ -27,7 +27,7 @@ #define get_user_id_max_command "grep \"^UID_MAX\" /etc/login.defs | sed -e 's/\t/ /g' -e 's/ */ /g'|grep -oE \"[0-9]{1,}\"" #define get_users_command "getent passwd |cut -d: -f1,3" #define get_terminals_info_command "ublexec-cli -l|sed -e 's/\t/ /g' -e 's/^ *//g' -e 's/ */:/g'|cut -d':' -f1,2,3" -#define get_run_command_command "ublexec-cli -q -o" +#define get_run_command_command "ublexec-cli -q" #define LocalePath "/usr/share/locale" #define LocaleName "ublexec" -- 2.35.1