Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

feat(linux/gui): Profile is a menu of its own, like the Windows app, and every item works directly

anof-cyber42fe97a71f10
diff --git a/Linux/README.md b/Linux/README.md
index 2e81bfe..6c87b3b 100644
--- a/Linux/README.md
+++ b/Linux/README.md
@@ -102,7 +102,7 @@ The GTK3-based GUI provides:
The CLI takes the same options as the Windows CLI. Everything else (proxies, rules, DNS via proxy, connection-log setting) lives in a **profile**, which you build in the GUI (or write by hand) and run with `--profile`.
```
-sudo ProxyBridge --profile work # a profile saved by the GUI (Proxy > Profiles)
+sudo ProxyBridge --profile work # a profile saved by the GUI (the Profile menu)
sudo ProxyBridge --profile ./myconfig.pbprofile --verbose 2 # any .pbprofile, e.g. exported from the Windows or macOS app
ProxyBridge --update # look for a newer version (no root)
```
@@ -143,7 +143,7 @@ Rules are evaluated **in order and the first match wins** (put specific rules be
### Profiles
-A profile is a named set of proxies and rules. The GUI keeps any number of them (Proxy menu, **Profiles**: Switch, New, Duplicate, Rename, Delete, **Import**, **Export**), and the CLI runs one with `--profile`.
+A profile is a named set of proxies and rules. The GUI keeps any number of them, in a **Profile** menu of its own like the Windows app (New, Duplicate, Rename, Delete, **Import**, **Export**, and **Switch Profile** with the active profile checked); every item works on the active profile at once, with no list dialog, and the CLI runs one with `--profile`.
Profiles are stored in the **same `.pbprofile` JSON format as the Windows and macOS apps**, so a file exported on one platform imports on the others:
```bash
diff --git a/Linux/cli/main.c b/Linux/cli/main.c
index 5efee90..2b64ec5 100644
--- a/Linux/cli/main.c
+++ b/Linux/cli/main.c
@@ -55,7 +55,7 @@ static void show_help(void)
show_banner();
printf("Options:\n");
printf(" --profile <path> Path to a .pbprofile file exported from the GUI, or the name of a\n");
- printf(" profile saved by the GUI (Proxy > Profiles)\n\n");
+ printf(" profile saved by the GUI (the Profile menu)\n\n");
printf(" --verbose <0-3> Logging verbosity\n");
printf(" 0 - Silent (default)\n");
printf(" 1 - Log messages only\n");
diff --git a/Linux/gui/gui.h b/Linux/gui/gui.h
index 72c7031..f4adedb 100644
--- a/Linux/gui/gui.h
+++ b/Linux/gui/gui.h
@@ -114,7 +114,15 @@ bool profile_export(const Profile *prof, const char *path, char *err, size_t err
Profile *profile_import(const char *path, char *err, size_t errlen); // not activated
void on_proxy_configure(GtkWidget *widget, gpointer data);
-void on_profiles_clicked(GtkWidget *widget, gpointer data);
+// Profile menu: every action works on the active profile
+void on_profile_new(GtkWidget *widget, gpointer data);
+void on_profile_duplicate(GtkWidget *widget, gpointer data);
+void on_profile_rename(GtkWidget *widget, gpointer data);
+void on_profile_delete(GtkWidget *widget, gpointer data);
+void on_profile_import(GtkWidget *widget, gpointer data);
+void on_profile_export(GtkWidget *widget, gpointer data);
+void on_profile_switch_item(GtkWidget *item, gpointer data); // data: the profile name
+void gui_refresh_profile_menu(void); // rebuilds Profile > Switch (main.c)
ProxyData *find_proxy_by_name(const char *name);
uint32_t resolve_proxy_id(const char *name);
void free_proxy_data(ProxyData *p);
diff --git a/Linux/gui/gui_settings.c b/Linux/gui/gui_settings.c
index 1fefd25..dcea41f 100644
--- a/Linux/gui/gui_settings.c
+++ b/Linux/gui/gui_settings.c
@@ -479,12 +479,6 @@ void on_proxy_configure(GtkWidget *widget, gpointer data) {
gtk_widget_destroy(info.dialog);
}
-typedef struct {
- GtkWidget *dialog;
- GtkWidget *tree;
- GtkListStore *store;
-} ProfilesInfo;
-
static void update_profile_ui() {
char *boot_err = NULL;
char *ppath = profile_path(g_active_profile);
@@ -500,6 +494,7 @@ static void update_profile_ui() {
title = g_strdup_printf("Active profile: %s", g_active_profile);
gtk_statusbar_push(GTK_STATUSBAR(status_bar), status_context_id, title);
g_free(title);
+ gui_refresh_profile_menu(); // the checkmark in Profile > Switch follows the active profile
}
// engine keeps running, only its proxies and rules are replaced
@@ -513,25 +508,6 @@ static void reapply_active_profile() {
update_profile_ui();
}
-static void refresh_profile_store(ProfilesInfo *pi) {
- gtk_list_store_clear(pi->store);
- for (GList *l = g_profiles; l != NULL; l = l->next) {
- Profile *p = (Profile *)l->data;
- GtkTreeIter iter;
- gtk_list_store_append(pi->store, &iter);
- gtk_list_store_set(pi->store, &iter, 0, p->name, 1, strcmp(p->name, g_active_profile) == 0 ? "Active" : "", -1);
- }
-}
-
-static char *selected_profile_name(ProfilesInfo *pi) {
- GtkTreeModel *model;
- GtkTreeIter iter;
- char *name = NULL;
- if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(pi->tree)), &model, &iter))
- gtk_tree_model_get(model, &iter, 0, &name, -1);
- return name;
-}
-
// NULL on cancel
static char *ask_profile_name(GtkWindow *parent, const char *title, const char *initial) {
GtkWidget *d = gtk_dialog_new_with_buttons(title, parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -560,77 +536,60 @@ static char *ask_profile_name(GtkWindow *parent, const char *title, const char *
return result;
}
-static void on_profile_switch(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *name = selected_profile_name(pi);
- if (name && strcmp(name, g_active_profile) != 0 && profile_activate(name)) {
- reapply_active_profile();
- refresh_profile_store(pi);
- }
- g_free(name);
+// ---- the Profile menu: every item acts on the active profile, like in the Windows app ----
+
+static GtkWindow *profile_parent() { return GTK_WINDOW(window); }
+
+static void profile_switch_to(const char *name) {
+ if (name && strcmp(name, g_active_profile) != 0 && profile_activate(name)) reapply_active_profile();
}
-static void on_profile_new(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *name = ask_profile_name(GTK_WINDOW(pi->dialog), "New Profile", "");
+// Profile > Switch > <name>
+void on_profile_switch_item(GtkWidget *item, gpointer data) {
+ if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))) return; // the item that just lost its check
+ profile_switch_to((const char *)data);
+}
+
+void on_profile_new(GtkWidget *widget, gpointer data) {
+ char *name = ask_profile_name(profile_parent(), "New Profile", "");
if (name && profile_create(name, false)) {
+ profile_switch_to(name); // like the Windows app: the new profile is the active one
save_config();
- refresh_profile_store(pi);
}
g_free(name);
}
-static void on_profile_duplicate(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *src = selected_profile_name(pi);
- if (!src) return;
- char *initial = g_strdup_printf("%s copy", src);
- char *name = ask_profile_name(GTK_WINDOW(pi->dialog), "Duplicate Profile", initial);
- char *prev = g_strdup(g_active_profile);
- // copies the active profile, so make the source active for a moment (library state is untouched)
- if (name && profile_activate(src)) {
- profile_create(name, true);
- profile_activate(prev);
+void on_profile_duplicate(GtkWidget *widget, gpointer data) {
+ char *initial = g_strdup_printf("%s copy", g_active_profile);
+ char *name = ask_profile_name(profile_parent(), "Duplicate Profile", initial);
+ if (name && profile_create(name, true)) { // a copy of the active profile
+ profile_switch_to(name);
save_config();
- refresh_profile_store(pi);
}
- g_free(prev); g_free(initial); g_free(name); g_free(src);
+ g_free(initial);
+ g_free(name);
}
-static void on_profile_rename(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *old = selected_profile_name(pi);
- if (!old) return;
- char *name = ask_profile_name(GTK_WINDOW(pi->dialog), "Rename Profile", old);
- if (name && profile_rename(profile_find(old), name)) {
+void on_profile_rename(GtkWidget *widget, gpointer data) {
+ char *name = ask_profile_name(profile_parent(), "Rename Profile", g_active_profile);
+ if (name && profile_rename(profile_find(g_active_profile), name)) {
save_config();
- refresh_profile_store(pi);
update_profile_ui();
}
g_free(name);
- g_free(old);
-}
-
-static void on_profile_delete(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *name = selected_profile_name(pi);
- if (!name) return;
- if (!g_profiles->next) {
- show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_WARNING, "The last profile cannot be deleted.");
- } else if (confirm(GTK_WINDOW(pi->dialog), "Delete profile '%s' with all its proxies and rules?", name)) {
- bool was_active = strcmp(g_active_profile, name) == 0;
- if (profile_delete(profile_find(name))) {
- if (was_active) reapply_active_profile();
- else save_config();
- refresh_profile_store(pi);
- }
+}
+
+void on_profile_delete(GtkWidget *widget, gpointer data) {
+ if (!g_profiles || !g_profiles->next) {
+ show_message(profile_parent(), GTK_MESSAGE_WARNING, "The last profile cannot be deleted.");
+ } else if (confirm(profile_parent(), "Delete profile '%s' with all its proxies and rules?", g_active_profile)) {
+ // the active profile goes: another one becomes active
+ if (profile_delete(profile_find(g_active_profile))) reapply_active_profile();
}
- g_free(name);
}
-static void on_profile_import(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- GtkWidget *dialog = gtk_file_chooser_dialog_new("Import Profile", GTK_WINDOW(pi->dialog), GTK_FILE_CHOOSER_ACTION_OPEN,
+void on_profile_import(GtkWidget *widget, gpointer data) {
+ GtkWidget *dialog = gtk_file_chooser_dialog_new("Import Profile", profile_parent(), GTK_FILE_CHOOSER_ACTION_OPEN,
"Cancel", GTK_RESPONSE_CANCEL, "Import", GTK_RESPONSE_ACCEPT, NULL);
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, "ProxyBridge profiles (*.pbprofile)");
@@ -645,86 +604,37 @@ static void on_profile_import(GtkWidget *widget, gpointer data) {
char err[256];
Profile *p = filename ? profile_import(filename, err, sizeof err) : NULL;
if (p) {
+ char *name = g_strdup(p->name);
save_config();
- refresh_profile_store(pi);
- show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_INFO, "Imported as profile '%s'. Use Switch to activate it.", p->name);
+ profile_switch_to(name); // like the Windows app: the imported profile becomes the active one
+ gui_refresh_profile_menu();
+ g_free(name);
} else {
- show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_ERROR, "Import failed: %s", filename ? err : "no file selected");
+ show_message(profile_parent(), GTK_MESSAGE_ERROR, "Import failed: %s", filename ? err : "no file selected");
}
g_free(filename);
}
gtk_widget_destroy(dialog);
}
-static void on_profile_export(GtkWidget *widget, gpointer data) {
- ProfilesInfo *pi = (ProfilesInfo *)data;
- char *name = selected_profile_name(pi);
- if (!name) return;
- GtkWidget *dialog = gtk_file_chooser_dialog_new("Export Profile", GTK_WINDOW(pi->dialog), GTK_FILE_CHOOSER_ACTION_SAVE,
+void on_profile_export(GtkWidget *widget, gpointer data) {
+ GtkWidget *dialog = gtk_file_chooser_dialog_new("Export Profile", profile_parent(), GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel", GTK_RESPONSE_CANCEL, "Export", GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
- char *suggested = g_strdup_printf("%s.pbprofile", name);
+ char *suggested = g_strdup_printf("%s.pbprofile", g_active_profile);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggested);
g_free(suggested);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
char err[256];
- if (filename && profile_export(profile_find(name), filename, err, sizeof err))
- show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_INFO,
- "Profile '%s' exported to %s.\nThe file contains your proxy credentials, so it is readable by you only.", name, filename);
+ if (filename && profile_export(profile_find(g_active_profile), filename, err, sizeof err))
+ show_message(profile_parent(), GTK_MESSAGE_INFO,
+ "Profile '%s' exported to %s.\nThe file contains your proxy credentials, so it is readable by you only.", g_active_profile, filename);
else
- show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_ERROR, "Export failed: %s", filename ? err : "no file selected");
+ show_message(profile_parent(), GTK_MESSAGE_ERROR, "Export failed: %s", filename ? err : "no file selected");
g_free(filename);
}
gtk_widget_destroy(dialog);
- g_free(name);
-}
-
-static void on_profile_row_activated(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) {
- on_profile_switch(NULL, data);
-}
-
-void on_profiles_clicked(GtkWidget *widget, gpointer data) {
- ProfilesInfo pi = {0};
- pi.dialog = gtk_dialog_new_with_buttons("Profiles", GTK_WINDOW(window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- "Close", GTK_RESPONSE_CLOSE, NULL);
- gtk_window_set_default_size(GTK_WINDOW(pi.dialog), 560, 360);
- gtk_widget_set_name(pi.dialog, "dlg_profiles");
- GtkWidget *box = gtk_dialog_get_content_area(GTK_DIALOG(pi.dialog));
- gtk_container_set_border_width(GTK_CONTAINER(box), 10);
-
- pi.store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
- pi.tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pi.store));
- g_object_unref(pi.store);
- const char *titles[] = {"Profile", "Status"};
- for (int i = 0; i < 2; i++) {
- GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes(titles[i], gtk_cell_renderer_text_new(), "text", i, NULL);
- gtk_tree_view_column_set_expand(c, i == 0);
- gtk_tree_view_append_column(GTK_TREE_VIEW(pi.tree), c);
- }
- gtk_widget_set_name(pi.tree, "profile_tree");
- g_signal_connect(pi.tree, "row-activated", G_CALLBACK(on_profile_row_activated), &pi);
- GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
- gtk_container_add(GTK_CONTAINER(scroll), pi.tree);
- gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
-
- GtkWidget *btns = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
- const char *labels[] = {"Switch", "New", "Duplicate", "Rename", "Delete", "Import...", "Export..."};
- void (*cbs[])(GtkWidget *, gpointer) = {on_profile_switch, on_profile_new, on_profile_duplicate, on_profile_rename, on_profile_delete,
- on_profile_import, on_profile_export};
- const char *bnames[] = {"pf_switch", "pf_new", "pf_duplicate", "pf_rename", "pf_delete", "pf_import", "pf_export"};
- for (int i = 0; i < 7; i++) {
- GtkWidget *b = gtk_button_new_with_label(labels[i]);
- gtk_widget_set_name(b, bnames[i]);
- g_signal_connect(b, "clicked", G_CALLBACK(cbs[i]), &pi);
- gtk_box_pack_start(GTK_BOX(btns), b, FALSE, FALSE, 0);
- }
- gtk_box_pack_start(GTK_BOX(box), btns, FALSE, FALSE, 5);
-
- refresh_profile_store(&pi);
- gtk_widget_show_all(pi.dialog);
- gtk_dialog_run(GTK_DIALOG(pi.dialog));
- gtk_widget_destroy(pi.dialog);
}
diff --git a/Linux/gui/main.c b/Linux/gui/main.c
index 03a07f1..80afc6a 100644
--- a/Linux/gui/main.c
+++ b/Linux/gui/main.c
@@ -77,6 +77,37 @@ static gboolean on_focus_out(GtkWidget *w, GdkEvent *ev, gpointer menubar) {
return FALSE;
}
+// ---- Profile > Switch Profile: one radio item per profile, the active one is checked ----
+static GtkWidget *switch_menu;
+static guint switch_rebuild_source;
+
+static void free_closure_name(gpointer data, GClosure *closure) { g_free(data); }
+
+static gboolean rebuild_switch_menu(gpointer unused) {
+ switch_rebuild_source = 0;
+ if (!switch_menu) return G_SOURCE_REMOVE;
+ GList *kids = gtk_container_get_children(GTK_CONTAINER(switch_menu));
+ for (GList *k = kids; k; k = k->next) gtk_widget_destroy(GTK_WIDGET(k->data));
+ g_list_free(kids);
+ GSList *group = NULL;
+ for (GList *l = g_profiles; l; l = l->next) {
+ Profile *p = l->data;
+ GtkWidget *item = gtk_radio_menu_item_new_with_label(group, p->name);
+ group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), strcmp(p->name, g_active_profile) == 0); // before the handler exists
+ g_signal_connect_data(item, "toggled", G_CALLBACK(on_profile_switch_item), g_strdup(p->name), free_closure_name, 0);
+ gtk_menu_shell_append(GTK_MENU_SHELL(switch_menu), item);
+ }
+ gtk_widget_show_all(switch_menu);
+ return G_SOURCE_REMOVE;
+}
+
+// called after any change of the profile list or of the active profile. Deferred: it is usually called from the handler of a
+// menu item that the rebuild would destroy.
+void gui_refresh_profile_menu(void) {
+ if (!switch_rebuild_source) switch_rebuild_source = g_idle_add(rebuild_switch_menu, NULL);
+}
+
static void on_auto_clear_toggled(GtkCheckMenuItem *item, gpointer data) {
g_chk_auto_clear = gtk_check_menu_item_get_active(item);
save_config();
@@ -570,7 +601,6 @@ int main(int argc, char *argv[]) {
GtkWidget *proxy_menu = add_submenu(menubar, "Proxy");
add_menu_item(proxy_menu, "Proxy Settings...", G_CALLBACK(on_proxy_configure));
add_menu_item(proxy_menu, "Proxy Rules...", G_CALLBACK(on_proxy_rules_clicked));
- add_menu_item(proxy_menu, "Profiles...", G_CALLBACK(on_profiles_clicked));
add_separator(proxy_menu);
log_item = add_check_item(proxy_menu, "Enable Traffic Logging", g_chk_logging, G_CALLBACK(on_log_traffic_toggled));
every_item = add_check_item(proxy_menu, "Log Every Connection", g_chk_log_every, G_CALLBACK(on_log_every_toggled));
@@ -582,6 +612,21 @@ int main(int argc, char *argv[]) {
start_item = add_menu_item(proxy_menu, "Start Engine", G_CALLBACK(on_start_engine));
stop_item = add_menu_item(proxy_menu, "Stop Engine", G_CALLBACK(on_stop_engine));
add_menu_item(proxy_menu, "Exit", G_CALLBACK(on_window_destroy));
+ // like the Windows app: Profile is a menu of its own and every item acts at once on the active profile
+ GtkWidget *profile_menu = add_submenu(menubar, "Profile");
+ add_menu_item(profile_menu, "New Profile...", G_CALLBACK(on_profile_new));
+ add_menu_item(profile_menu, "Duplicate Profile...", G_CALLBACK(on_profile_duplicate));
+ add_menu_item(profile_menu, "Rename Profile...", G_CALLBACK(on_profile_rename));
+ add_menu_item(profile_menu, "Delete Profile...", G_CALLBACK(on_profile_delete));
+ add_separator(profile_menu);
+ add_menu_item(profile_menu, "Import Profile...", G_CALLBACK(on_profile_import));
+ add_menu_item(profile_menu, "Export Profile...", G_CALLBACK(on_profile_export));
+ add_separator(profile_menu);
+ GtkWidget *switch_item = gtk_menu_item_new_with_label("Switch Profile");
+ switch_menu = gtk_menu_new();
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(switch_item), switch_menu);
+ gtk_menu_shell_append(GTK_MENU_SHELL(profile_menu), switch_item);
+ rebuild_switch_menu(NULL);
GtkWidget *view_menu = add_submenu(menubar, "View");
GtkAccelGroup *accel = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel);
diff --git a/Linux/gui/tests/ui_test.c b/Linux/gui/tests/ui_test.c
index fecc890..278b200 100644
--- a/Linux/gui/tests/ui_test.c
+++ b/Linux/gui/tests/ui_test.c
@@ -201,29 +201,7 @@ static int model_rows(const char *tree_name) {
return t ? gtk_tree_model_iter_n_children(gtk_tree_view_get_model(GTK_TREE_VIEW(t)), NULL) : -1;
}
-static bool select_by_first_column(const char *tree_name, const char *text) {
- GtkWidget *t = find_named(tree_name);
- if (!t) return false;
- GtkTreeModel *m = gtk_tree_view_get_model(GTK_TREE_VIEW(t));
- GtkTreeIter it;
- bool ok = gtk_tree_model_get_iter_first(m, &it);
- while (ok) {
- char *v = NULL;
- gtk_tree_model_get(m, &it, 0, &v, -1);
- bool hit = v && strcmp(v, text) == 0;
- g_free(v);
- if (hit) { gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(t)), &it); return true; }
- ok = gtk_tree_model_iter_next(m, &it);
- }
- return false;
-}
-static void show_profiles(const char *when) {
- printf(" profiles %s:", when);
- for (GList *l = g_profiles; l; l = l->next) printf(" [%s]", ((Profile *)l->data)->name);
- printf(" active=%s\n", g_active_profile);
- fflush(stdout);
-}
// ---- the profile file on disk ---------------------------------------------------------------------------------------------
static bool load_disk(const char *profile, struct pbp_profile *p) {
@@ -608,114 +586,164 @@ static void submit_refused(GtkWidget *d, gpointer arg) {
arm("msg", msg_then_arm_cancel, NULL, GTK_RESPONSE_OK);
}
-static void profiles_body(GtkWidget *dlg, gpointer arg) {
- (void)arg;
- STEP("profiles dialog open");
- CHECK(model_rows("profile_tree") == 1);
+// Profile > Switch Profile > <name>. The submenu is rebuilt in an idle callback after every change, hence the pumps.
+static void switch_to_profile(const char *name) {
+ pump(150);
+ GtkWidget *sw = menu_item("Switch Profile");
+ CHECK(sw != NULL);
+ GtkWidget *sub = sw ? gtk_menu_item_get_submenu(GTK_MENU_ITEM(sw)) : NULL;
+ GtkWidget *hit = NULL;
+ GList *kids = sub ? gtk_container_get_children(GTK_CONTAINER(sub)) : NULL;
+ for (GList *k = kids; k; k = k->next)
+ if (strcmp(gtk_menu_item_get_label(GTK_MENU_ITEM(k->data)), name) == 0) hit = k->data;
+ g_list_free(kids);
+ CHECK(hit != NULL);
+ if (hit) gtk_menu_item_activate(GTK_MENU_ITEM(hit));
+ pump(150);
+}
+
+// the names in Profile > Switch Profile, in order, and which one is checked
+static char *switch_menu_text(void) {
+ pump(150);
+ GtkWidget *sw = menu_item("Switch Profile");
+ GtkWidget *sub = sw ? gtk_menu_item_get_submenu(GTK_MENU_ITEM(sw)) : NULL;
+ GString *out = g_string_new("");
+ GList *kids = sub ? gtk_container_get_children(GTK_CONTAINER(sub)) : NULL;
+ for (GList *k = kids; k; k = k->next)
+ g_string_append_printf(out, "%s%s;", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(k->data)) ? "*" : "", gtk_menu_item_get_label(GTK_MENU_ITEM(k->data)));
+ g_list_free(kids);
+ return g_string_free(out, FALSE);
+}
+
+static void profiles_scenario(void) {
+ STEP("profile menu");
+ // like the Windows app: Profile is a menu of its own, and there is no list dialog any more
+ CHECK(menu_item("New Profile...") && menu_item("Duplicate Profile...") && menu_item("Rename Profile...") && menu_item("Delete Profile...") &&
+ menu_item("Import Profile...") && menu_item("Export Profile...") && menu_item("Switch Profile"));
+ CHECK(menu_item("Profiles...") == NULL);
+ char *shown = switch_menu_text();
+ CHECK_STR(shown, "*Default;");
+ g_free(shown);
arm("dlg_profile_name", fill_name, (gpointer)"Work", GTK_RESPONSE_ACCEPT);
- click("pf_new");
- CHECK(profile_find("Work") && model_rows("profile_tree") == 2);
+ activate("New Profile...");
+ pump(150);
+ CHECK(profile_find("Work") != NULL);
+ CHECK_STR(g_active_profile, "Work"); // a new profile becomes the active one at once
+ CHECK_HAS(gtk_window_get_title(GTK_WINDOW(window)), "ProxyBridge - Work");
struct pbp_profile disk;
CHECK(load_disk("Work", &disk) && disk.nrules == 0 && disk.nproxies == 0);
pbp_free(&disk);
+ shown = switch_menu_text();
+ CHECK_STR(shown, "Default;*Work;"); // the check follows the active profile
+ g_free(shown);
refused_name = "";
arm("dlg_profile_name", submit_refused, NULL, GTK_RESPONSE_ACCEPT);
- click("pf_new");
+ activate("New Profile...");
CHECK_HAS(last_msg, "cannot be empty");
refused_name = "Work";
arm("dlg_profile_name", submit_refused, NULL, GTK_RESPONSE_ACCEPT);
- click("pf_new");
+ activate("New Profile...");
CHECK_HAS(last_msg, "already exists");
- CHECK(model_rows("profile_tree") == 2);
-
- STEP("duplicate");
- // duplicate copies proxies, rules and switches
- CHECK(select_by_first_column("profile_tree", "Default"));
- arm("dlg_profile_name", fill_name, (gpointer)"Home", GTK_RESPONSE_ACCEPT);
- click("pf_duplicate");
- Profile *home = profile_find("Home");
- CHECK(home && g_list_length(home->proxies) == 1 && g_list_length(home->rules) == 1);
-
- // rename
- CHECK(select_by_first_column("profile_tree", "Home"));
- arm("dlg_profile_name", fill_name, (gpointer)"Office", GTK_RESPONSE_ACCEPT);
- click("pf_rename");
- CHECK(profile_find("Home") == NULL && profile_find("Office"));
- struct pbp_profile d2;
- CHECK(load_disk("Office", &d2));
- pbp_free(&d2);
- CHECK(!load_disk("Home", &d2)); // the old file is gone
+ CHECK(g_list_length(g_profiles) == 2);
STEP("switch");
// switch: the window title, the engine's rules and the profile's own switches follow
+ switch_to_profile("Default");
+ CHECK_STR(g_active_profile, "Default");
GtkWidget *log_item = menu_item("Enable Traffic Logging");
CHECK(log_item && menu_item("DNS via Proxy") == NULL); // DNS via proxy is a per-proxy option, not a menu switch
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(log_item), FALSE); // Default: logging off
CHECK(!g_chk_logging);
- CHECK(select_by_first_column("profile_tree", "Work"));
- click("pf_switch");
+ switch_to_profile("Work");
CHECK_STR(g_active_profile, "Work");
CHECK_HAS(gtk_window_get_title(GTK_WINDOW(window)), "ProxyBridge - Work");
CHECK(g_chk_logging && gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(log_item))); // Work has its own, default-on switches
g_chk_dns = false; save_config(); // Work: DNS routing off (profile field)
- CHECK(select_by_first_column("profile_tree", "Default"));
- click("pf_switch");
+ switch_to_profile("Default");
CHECK_STR(g_active_profile, "Default");
CHECK(!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(log_item)) && g_chk_dns);
+ struct pbp_profile d2;
CHECK(load_disk("Work", &d2) && !d2.dns_via_proxy && d2.logging);
pbp_free(&d2);
+ switch_to_profile("Default"); // choosing the active profile again changes nothing
+ CHECK_STR(g_active_profile, "Default");
+
+ STEP("duplicate");
+ // duplicate copies proxies, rules and switches of the active profile, and the copy becomes the active one
+ arm("dlg_profile_name", fill_name, (gpointer)"Home", GTK_RESPONSE_ACCEPT);
+ activate("Duplicate Profile...");
+ pump(150);
+ Profile *home = profile_find("Home");
+ CHECK(home && g_list_length(home->proxies) == 1 && g_list_length(home->rules) == 1);
+ CHECK_STR(g_active_profile, "Home");
+
+ // rename: the active profile
+ arm("dlg_profile_name", fill_name, (gpointer)"Office", GTK_RESPONSE_ACCEPT);
+ activate("Rename Profile...");
+ pump(150);
+ CHECK(profile_find("Home") == NULL && profile_find("Office"));
+ CHECK_STR(g_active_profile, "Office");
+ CHECK_HAS(gtk_window_get_title(GTK_WINDOW(window)), "ProxyBridge - Office");
+ CHECK(load_disk("Office", &d2));
+ pbp_free(&d2);
+ CHECK(!load_disk("Home", &d2)); // the old file is gone
+ shown = switch_menu_text();
+ CHECK_STR(shown, "Default;Work;*Office;");
+ g_free(shown);
STEP("profile export / import");
- // export and import through the file chooser
+ // export the active profile and import it again: the import becomes the active profile
char *file = tmp_path("exported.pbprofile");
unlink(file);
- CHECK(select_by_first_column("profile_tree", "Office"));
arm("chooser", choose_file, file, GTK_RESPONSE_ACCEPT);
arm_msg(GTK_RESPONSE_OK);
- click("pf_export");
+ activate("Export Profile...");
CHECK_HAS(last_msg, "exported");
struct stat st;
CHECK(stat(file, &st) == 0 && (st.st_mode & 0777) == 0600);
arm("chooser", choose_file, file, GTK_RESPONSE_ACCEPT);
- arm_msg(GTK_RESPONSE_OK);
- click("pf_import");
- CHECK_HAS(last_msg, "Imported as profile");
+ activate("Import Profile...");
+ pump(150);
CHECK(profile_find("Office (2)") != NULL);
+ CHECK_STR(g_active_profile, "Office (2)");
char *junk = tmp_path("junk.pbprofile");
g_file_set_contents(junk, "{ nope", -1, NULL);
arm("chooser", choose_file, junk, GTK_RESPONSE_ACCEPT);
arm_msg(GTK_RESPONSE_OK);
- click("pf_import");
+ activate("Import Profile...");
CHECK_HAS(last_msg, "Import failed");
+ CHECK_STR(g_active_profile, "Office (2)");
g_free(file); g_free(junk);
STEP("profile delete");
- // delete: asks first; the last profile stays
- CHECK(select_by_first_column("profile_tree", "Office (2)"));
- show_profiles("before deleting");
+ // delete the active profile: asks first, another profile becomes active; the last profile stays
arm_msg(GTK_RESPONSE_NO);
- click("pf_delete");
+ activate("Delete Profile...");
CHECK(profile_find("Office (2)") != NULL);
arm_msg(GTK_RESPONSE_YES);
- click("pf_delete");
+ activate("Delete Profile...");
+ pump(150);
CHECK(profile_find("Office (2)") == NULL);
- CHECK(select_by_first_column("profile_tree", "Office"));
+ CHECK(g_active_profile && profile_find(g_active_profile) != NULL); // an existing profile is active
+ switch_to_profile("Office");
arm_msg(GTK_RESPONSE_YES);
- click("pf_delete");
- show_profiles("after deleting Office");
- CHECK(select_by_first_column("profile_tree", "Work"));
+ activate("Delete Profile...");
+ pump(150);
+ switch_to_profile("Work");
arm_msg(GTK_RESPONSE_YES);
- click("pf_delete");
- show_profiles("after deleting Work");
+ activate("Delete Profile...");
+ pump(150);
CHECK(g_list_length(g_profiles) == 1);
- CHECK(select_by_first_column("profile_tree", "Default"));
+ CHECK_STR(g_active_profile, "Default");
+ shown = switch_menu_text();
+ CHECK_STR(shown, "*Default;");
+ g_free(shown);
arm_msg(GTK_RESPONSE_OK);
- click("pf_delete");
+ activate("Delete Profile...");
CHECK_HAS(last_msg, "last profile");
CHECK(profile_find("Default") != NULL);
- gtk_dialog_response(GTK_DIALOG(dlg), GTK_RESPONSE_CLOSE);
}
@@ -912,6 +940,7 @@ static void zoom_scenario(void)
gui_set_zoom(130);
CHECK(profile_create("Zoomed", false) != NULL);
CHECK(profile_activate("Zoomed"));
+ gui_refresh_profile_menu(); // (the menu items do this themselves; here the engine calls are used directly)
gui_sync_switches();
CHECK(g_zoom == 100 && strstr(gui_zoom_css(), "100%") != NULL);
gui_set_zoom(180);
@@ -1119,13 +1148,6 @@ static void make_fake_systemctl(const char *path, const char *log)
g_free(script);
}
-static void switch_to(GtkWidget *dlg, gpointer arg)
-{
- select_by_first_column("profile_tree", arg);
- click("pf_switch");
- gtk_dialog_response(GTK_DIALOG(dlg), GTK_RESPONSE_CLOSE);
-}
-
static void boot_scenario(void)
{
STEP("start at boot");
@@ -1155,16 +1177,14 @@ static void boot_scenario(void)
g_free(log);
// another active profile is what the service runs after the next boot
- arm("dlg_profiles", switch_to, (gpointer)"Zoomed", 0);
- activate("Profiles...");
+ switch_to_profile("Zoomed");
CHECK_STR(g_active_profile, "Zoomed");
CHECK(g_file_get_contents(unit, &text, NULL, NULL));
char *want_zoom = g_strdup_printf("--profile \"%s\"", zoom_path);
CHECK_HAS(text, want_zoom);
g_free(want_zoom);
g_free(text);
- arm("dlg_profiles", switch_to, (gpointer)"Default", 0);
- activate("Profiles...");
+ switch_to_profile("Default");
CHECK(g_file_get_contents(unit, &text, NULL, NULL));
char *want_def2 = g_strdup_printf("--profile \"%s\"", def_path);
CHECK_HAS(text, want_def2);
@@ -1256,7 +1276,7 @@ static void startup_update_scenario(void)
static void ui_main(void) {
pump(300);
CHECK_HAS(gtk_window_get_title(GTK_WINDOW(window)), "ProxyBridge - Default");
- CHECK(menu_item("Proxy Settings...") && menu_item("Proxy Rules...") && menu_item("Profiles..."));
+ CHECK(menu_item("Proxy Settings...") && menu_item("Proxy Rules..."));
printf("== proxy settings\n");
arm("dlg_proxies", proxies_body, NULL, 0);
@@ -1272,8 +1292,7 @@ static void ui_main(void) {
rules_scenario();
printf("== profiles\n");
- arm("dlg_profiles", profiles_body, NULL, 0);
- activate("Profiles...");
+ profiles_scenario();
printf("== update check\n");
updates_scenario();