formatting
This commit is contained in:
21 files changed
+843
-582
No files matched your search
+12
-12
@@ -19,9 +19,7 @@
|
||||
|
||||
let
|
||||
unwrapped = pkgs.writeShellScriptBin "proxy-ctl" (
|
||||
builtins.readFile ./proxy-ctl-lib.sh
|
||||
+ "\n"
|
||||
+ builtins.readFile ./proxy-ctl.sh
|
||||
builtins.readFile ./proxy-ctl-lib.sh + "\n" + builtins.readFile ./proxy-ctl.sh
|
||||
);
|
||||
in
|
||||
pkgs.symlinkJoin {
|
||||
@@ -30,15 +28,17 @@ pkgs.symlinkJoin {
|
||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||
postBuild = ''
|
||||
wrapProgram "$out/bin/proxy-ctl" \
|
||||
--prefix PATH : "${lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
pkgs.curl
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
pkgs.proxychains-ng
|
||||
pkgs.systemd
|
||||
]}" \
|
||||
--prefix PATH : "${
|
||||
lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
pkgs.curl
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
pkgs.jq
|
||||
pkgs.proxychains-ng
|
||||
pkgs.systemd
|
||||
]
|
||||
}" \
|
||||
--set CLASH_API ${lib.escapeShellArg clashApi} \
|
||||
--set SELECTION ${lib.escapeShellArg selection} \
|
||||
--set SUB_TAGS_FILE ${lib.escapeShellArg (toString subscriptionTagsFile)} \
|
||||
|
||||
+279
-173
@@ -12,7 +12,6 @@
|
||||
#define PROXY_CTL_BIN "/run/current-system/sw/bin/proxy-ctl"
|
||||
#endif
|
||||
|
||||
|
||||
static AppIndicator *indicator;
|
||||
static GtkWidget *menu;
|
||||
static GtkWidget *status_item;
|
||||
@@ -31,7 +30,8 @@ static GtkWidget *controls_tproxy_button;
|
||||
static GtkWidget *controls_tun_button;
|
||||
static GtkWidget *controls_zapret_button;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
gboolean loaded;
|
||||
gboolean socks_available;
|
||||
gboolean tproxy_available;
|
||||
@@ -46,16 +46,19 @@ typedef struct {
|
||||
|
||||
static ServiceState initial_state;
|
||||
|
||||
static gboolean command_succeeds(gchar **argv) {
|
||||
static gboolean command_succeeds(gchar **argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gint wait_status = 0;
|
||||
|
||||
if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, &wait_status, &error)) {
|
||||
if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, &wait_status, &error))
|
||||
{
|
||||
g_clear_error(&error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_spawn_check_wait_status(wait_status, &error)) {
|
||||
if (!g_spawn_check_wait_status(wait_status, &error))
|
||||
{
|
||||
g_clear_error(&error);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -63,17 +66,20 @@ static gboolean command_succeeds(gchar **argv) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean command_stdout(gchar **argv, gchar **stdout_text) {
|
||||
static gboolean command_stdout(gchar **argv, gchar **stdout_text)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gint wait_status = 0;
|
||||
|
||||
*stdout_text = NULL;
|
||||
if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, stdout_text, NULL, &wait_status, &error)) {
|
||||
if (!g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, stdout_text, NULL, &wait_status, &error))
|
||||
{
|
||||
g_clear_error(&error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_spawn_check_wait_status(wait_status, &error)) {
|
||||
if (!g_spawn_check_wait_status(wait_status, &error))
|
||||
{
|
||||
g_clear_error(&error);
|
||||
g_clear_pointer(stdout_text, g_free);
|
||||
return FALSE;
|
||||
@@ -82,22 +88,28 @@ static gboolean command_stdout(gchar **argv, gchar **stdout_text) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean on_controls_delete(GtkWidget *widget, GdkEvent *event, gpointer data) {
|
||||
(void)event; (void)data;
|
||||
static gboolean on_controls_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
(void)event;
|
||||
(void)data;
|
||||
gtk_widget_hide(widget);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void on_close_controls(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
if (controls_window) {
|
||||
static void on_close_controls(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
if (controls_window)
|
||||
{
|
||||
gtk_widget_hide(controls_window);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_open_controls(GtkWidget *item, gpointer data);
|
||||
|
||||
static gboolean on_open_controls_idle(gpointer data) {
|
||||
static gboolean on_open_controls_idle(gpointer data)
|
||||
{
|
||||
(void)data;
|
||||
on_open_controls(NULL, NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
@@ -107,13 +119,16 @@ static GDBusMessage *on_session_bus_message(
|
||||
GDBusConnection *connection,
|
||||
GDBusMessage *message,
|
||||
gboolean incoming,
|
||||
gpointer user_data
|
||||
) {
|
||||
(void)connection; (void)user_data;
|
||||
if (!incoming || !message) {
|
||||
gpointer user_data)
|
||||
{
|
||||
(void)connection;
|
||||
(void)user_data;
|
||||
if (!incoming || !message)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
if (g_dbus_message_get_message_type(message) != G_DBUS_MESSAGE_TYPE_METHOD_CALL) {
|
||||
if (g_dbus_message_get_message_type(message) != G_DBUS_MESSAGE_TYPE_METHOD_CALL)
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -124,50 +139,55 @@ static GDBusMessage *on_session_bus_message(
|
||||
if (iface && member && path &&
|
||||
strcmp(iface, "org.kde.StatusNotifierItem") == 0 &&
|
||||
strcmp(member, "Activate") == 0 &&
|
||||
g_str_has_prefix(path, "/org/ayatana/NotificationItem/")) {
|
||||
g_str_has_prefix(path, "/org/ayatana/NotificationItem/"))
|
||||
{
|
||||
g_idle_add(on_open_controls_idle, NULL);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
static gboolean run_proxy_ctl1(const char *arg1) {
|
||||
static gboolean run_proxy_ctl1(const char *arg1)
|
||||
{
|
||||
gchar *argv[] = {
|
||||
(gchar *) PROXY_CTL_BIN,
|
||||
(gchar *) arg1,
|
||||
NULL
|
||||
};
|
||||
(gchar *)PROXY_CTL_BIN,
|
||||
(gchar *)arg1,
|
||||
NULL};
|
||||
|
||||
return command_succeeds(argv);
|
||||
}
|
||||
|
||||
static gboolean run_proxy_ctl2(const char *arg1, const char *arg2) {
|
||||
static gboolean run_proxy_ctl2(const char *arg1, const char *arg2)
|
||||
{
|
||||
gchar *argv[] = {
|
||||
(gchar *) PROXY_CTL_BIN,
|
||||
(gchar *) arg1,
|
||||
(gchar *) arg2,
|
||||
NULL
|
||||
};
|
||||
(gchar *)PROXY_CTL_BIN,
|
||||
(gchar *)arg1,
|
||||
(gchar *)arg2,
|
||||
NULL};
|
||||
|
||||
return command_succeeds(argv);
|
||||
}
|
||||
|
||||
static gboolean parse_proxy_ctl_bool(const char *value) {
|
||||
static gboolean parse_proxy_ctl_bool(const char *value)
|
||||
{
|
||||
return value && strcmp(value, "true") == 0;
|
||||
}
|
||||
|
||||
static const char *pick_icon_name(
|
||||
const char *const *candidates,
|
||||
gsize candidates_len,
|
||||
const char *fallback
|
||||
) {
|
||||
const char *fallback)
|
||||
{
|
||||
GtkIconTheme *theme = gtk_icon_theme_get_default();
|
||||
if (!theme) {
|
||||
if (!theme)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
for (gsize i = 0; i < candidates_len; ++i) {
|
||||
if (gtk_icon_theme_has_icon(theme, candidates[i])) {
|
||||
for (gsize i = 0; i < candidates_len; ++i)
|
||||
{
|
||||
if (gtk_icon_theme_has_icon(theme, candidates[i]))
|
||||
{
|
||||
return candidates[i];
|
||||
}
|
||||
}
|
||||
@@ -175,51 +195,72 @@ static const char *pick_icon_name(
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static ServiceState get_service_state(void) {
|
||||
ServiceState state = { 0 };
|
||||
static ServiceState get_service_state(void)
|
||||
{
|
||||
ServiceState state = {0};
|
||||
gchar *stdout_text = NULL;
|
||||
gchar *argv[] = {
|
||||
(gchar *) PROXY_CTL_BIN,
|
||||
(gchar *) "status",
|
||||
(gchar *) "--tray",
|
||||
NULL
|
||||
};
|
||||
(gchar *)PROXY_CTL_BIN,
|
||||
(gchar *)"status",
|
||||
(gchar *)"--tray",
|
||||
NULL};
|
||||
|
||||
if (!command_stdout(argv, &stdout_text)) {
|
||||
if (!command_stdout(argv, &stdout_text))
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
state.loaded = TRUE;
|
||||
|
||||
gchar **lines = g_strsplit(stdout_text, "\n", -1);
|
||||
for (gchar **line = lines; line && *line; ++line) {
|
||||
if ((*line)[0] == '\0') {
|
||||
for (gchar **line = lines; line && *line; ++line)
|
||||
{
|
||||
if ((*line)[0] == '\0')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
gchar **parts = g_strsplit(*line, "=", 2);
|
||||
if (!parts[0] || !parts[1]) {
|
||||
if (!parts[0] || !parts[1])
|
||||
{
|
||||
g_strfreev(parts);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(parts[0], "socks_available") == 0) {
|
||||
if (strcmp(parts[0], "socks_available") == 0)
|
||||
{
|
||||
state.socks_available = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "socks_active") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "socks_active") == 0)
|
||||
{
|
||||
state.socks = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "tproxy_available") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "tproxy_available") == 0)
|
||||
{
|
||||
state.tproxy_available = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "tproxy_active") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "tproxy_active") == 0)
|
||||
{
|
||||
state.tproxy = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "tun_available") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "tun_available") == 0)
|
||||
{
|
||||
state.tun_available = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "tun_active") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "tun_active") == 0)
|
||||
{
|
||||
state.tun = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "zapret_available") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "zapret_available") == 0)
|
||||
{
|
||||
state.zapret_available = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "zapret_active") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "zapret_active") == 0)
|
||||
{
|
||||
state.zapret = parse_proxy_ctl_bool(parts[1]);
|
||||
} else if (strcmp(parts[0], "subscription_update_available") == 0) {
|
||||
}
|
||||
else if (strcmp(parts[0], "subscription_update_available") == 0)
|
||||
{
|
||||
state.subscription_update_available = parse_proxy_ctl_bool(parts[1]);
|
||||
}
|
||||
|
||||
@@ -232,51 +273,59 @@ static ServiceState get_service_state(void) {
|
||||
return state;
|
||||
}
|
||||
|
||||
static const char *traffic_mode_label(const ServiceState *state) {
|
||||
if (state->tun) {
|
||||
static const char *traffic_mode_label(const ServiceState *state)
|
||||
{
|
||||
if (state->tun)
|
||||
{
|
||||
return "TUN tunnel enabled";
|
||||
}
|
||||
if (state->tproxy) {
|
||||
if (state->tproxy)
|
||||
{
|
||||
return "TProxy interception enabled";
|
||||
}
|
||||
return "System-wide routing disabled";
|
||||
}
|
||||
|
||||
static const char *indicator_label_text(const ServiceState *state) {
|
||||
if (state->socks && (state->tproxy || state->tun) && state->zapret) {
|
||||
static const char *indicator_label_text(const ServiceState *state)
|
||||
{
|
||||
if (state->socks && (state->tproxy || state->tun) && state->zapret)
|
||||
{
|
||||
return "Proxy + traffic + zapret";
|
||||
}
|
||||
if (state->socks && (state->tproxy || state->tun)) {
|
||||
if (state->socks && (state->tproxy || state->tun))
|
||||
{
|
||||
return "Proxy + traffic";
|
||||
}
|
||||
if (state->socks && state->zapret) {
|
||||
if (state->socks && state->zapret)
|
||||
{
|
||||
return "Proxy + zapret";
|
||||
}
|
||||
if (state->socks) {
|
||||
if (state->socks)
|
||||
{
|
||||
return "Proxy only";
|
||||
}
|
||||
if (state->zapret) {
|
||||
if (state->zapret)
|
||||
{
|
||||
return "Zapret only";
|
||||
}
|
||||
return "Inactive";
|
||||
}
|
||||
|
||||
static void update_status(void) {
|
||||
static void update_status(void)
|
||||
{
|
||||
ServiceState state = get_service_state();
|
||||
/* Gold: TUN/TProxy active (highest priority) */
|
||||
static const char *const tunnel_icons[] = {
|
||||
"proxy-suite-tunnel",
|
||||
"proxy-suite-tunnel-symbolic",
|
||||
"network-vpn",
|
||||
"network-vpn-symbolic"
|
||||
};
|
||||
"network-vpn-symbolic"};
|
||||
/* Green: proxy + zapret, no tunnel */
|
||||
static const char *const active_icons[] = {
|
||||
"proxy-suite-active",
|
||||
"proxy-suite-active-symbolic",
|
||||
"network-vpn",
|
||||
"network-vpn-symbolic"
|
||||
};
|
||||
"network-vpn-symbolic"};
|
||||
/* Orange: proxy only */
|
||||
static const char *const proxy_icons[] = {
|
||||
"proxy-suite-proxy",
|
||||
@@ -284,8 +333,7 @@ static void update_status(void) {
|
||||
"network-vpn-acquiring",
|
||||
"network-vpn-acquiring-symbolic",
|
||||
"network-vpn",
|
||||
"network-vpn-symbolic"
|
||||
};
|
||||
"network-vpn-symbolic"};
|
||||
/* Blue: zapret only */
|
||||
static const char *const zapret_icons[] = {
|
||||
"proxy-suite-zapret",
|
||||
@@ -293,8 +341,7 @@ static void update_status(void) {
|
||||
"network-vpn-acquiring",
|
||||
"network-vpn-acquiring-symbolic",
|
||||
"network-vpn",
|
||||
"network-vpn-symbolic"
|
||||
};
|
||||
"network-vpn-symbolic"};
|
||||
/* Red: everything disabled */
|
||||
static const char *const disabled_icons[] = {
|
||||
"proxy-suite-disabled",
|
||||
@@ -306,29 +353,33 @@ static void update_status(void) {
|
||||
"network-vpn-disconnected-symbolic",
|
||||
"network-offline-symbolic",
|
||||
"network-error-symbolic",
|
||||
"dialog-error-symbolic"
|
||||
};
|
||||
"dialog-error-symbolic"};
|
||||
|
||||
if (!state.loaded) {
|
||||
if (!state.loaded)
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(disabled_icons, G_N_ELEMENTS(disabled_icons), "network-vpn-disconnected")
|
||||
);
|
||||
pick_icon_name(disabled_icons, G_N_ELEMENTS(disabled_icons), "network-vpn-disconnected"));
|
||||
app_indicator_set_label(indicator, "Status unavailable", "");
|
||||
|
||||
if (status_item) {
|
||||
if (status_item)
|
||||
{
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(status_item), "[Status] proxy-ctl status unavailable");
|
||||
}
|
||||
if (controls_summary_label) {
|
||||
if (controls_summary_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_summary_label), "[Status] proxy-ctl status unavailable");
|
||||
}
|
||||
if (controls_core_status_label) {
|
||||
if (controls_core_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_core_status_label), "[Core] SOCKS proxy: Unknown");
|
||||
}
|
||||
if (controls_traffic_status_label) {
|
||||
if (controls_traffic_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_traffic_status_label), "[Traffic] Mode: Unknown");
|
||||
}
|
||||
if (controls_zapret_status_label) {
|
||||
if (controls_zapret_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_zapret_status_label), "[Zapret] zapret-discord-youtube: Unknown");
|
||||
}
|
||||
return;
|
||||
@@ -341,97 +392,109 @@ static void update_status(void) {
|
||||
"[Status] %s | Traffic: %s | Zapret: %s",
|
||||
state.socks ? "Proxy ready" : "Proxy down",
|
||||
traffic,
|
||||
zapret
|
||||
);
|
||||
zapret);
|
||||
gchar *core_text = g_strdup_printf(
|
||||
"[Core] SOCKS proxy: %s",
|
||||
state.socks ? "Running" : "Stopped"
|
||||
);
|
||||
state.socks ? "Running" : "Stopped");
|
||||
gchar *traffic_text = g_strdup_printf("[Traffic] Mode: %s", traffic);
|
||||
gchar *zapret_text = g_strdup_printf(
|
||||
"[Zapret] zapret-discord-youtube: %s",
|
||||
zapret
|
||||
);
|
||||
zapret);
|
||||
|
||||
if (state.tproxy || state.tun) {
|
||||
if (state.tproxy || state.tun)
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(tunnel_icons, G_N_ELEMENTS(tunnel_icons), "network-vpn")
|
||||
);
|
||||
} else if (state.socks && state.zapret) {
|
||||
pick_icon_name(tunnel_icons, G_N_ELEMENTS(tunnel_icons), "network-vpn"));
|
||||
}
|
||||
else if (state.socks && state.zapret)
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(active_icons, G_N_ELEMENTS(active_icons), "network-vpn")
|
||||
);
|
||||
} else if (state.socks) {
|
||||
pick_icon_name(active_icons, G_N_ELEMENTS(active_icons), "network-vpn"));
|
||||
}
|
||||
else if (state.socks)
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(proxy_icons, G_N_ELEMENTS(proxy_icons), "network-vpn-acquiring")
|
||||
);
|
||||
} else if (state.zapret) {
|
||||
pick_icon_name(proxy_icons, G_N_ELEMENTS(proxy_icons), "network-vpn-acquiring"));
|
||||
}
|
||||
else if (state.zapret)
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(zapret_icons, G_N_ELEMENTS(zapret_icons), "network-vpn-acquiring")
|
||||
);
|
||||
} else {
|
||||
pick_icon_name(zapret_icons, G_N_ELEMENTS(zapret_icons), "network-vpn-acquiring"));
|
||||
}
|
||||
else
|
||||
{
|
||||
app_indicator_set_icon(
|
||||
indicator,
|
||||
pick_icon_name(disabled_icons, G_N_ELEMENTS(disabled_icons), "network-vpn-disconnected")
|
||||
);
|
||||
pick_icon_name(disabled_icons, G_N_ELEMENTS(disabled_icons), "network-vpn-disconnected"));
|
||||
}
|
||||
app_indicator_set_label(indicator, summary, "");
|
||||
|
||||
if (status_item) {
|
||||
if (status_item)
|
||||
{
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(status_item), summary_text);
|
||||
}
|
||||
if (controls_summary_label) {
|
||||
if (controls_summary_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_summary_label), summary_text);
|
||||
}
|
||||
if (controls_core_status_label) {
|
||||
if (controls_core_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_core_status_label), core_text);
|
||||
}
|
||||
if (controls_traffic_status_label) {
|
||||
if (controls_traffic_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_traffic_status_label), traffic_text);
|
||||
}
|
||||
if (controls_zapret_status_label) {
|
||||
if (controls_zapret_status_label)
|
||||
{
|
||||
gtk_label_set_text(GTK_LABEL(controls_zapret_status_label), zapret_text);
|
||||
}
|
||||
if (proxy_item) {
|
||||
if (proxy_item)
|
||||
{
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(proxy_item),
|
||||
state.socks ? "[Core] Stop SOCKS Proxy" : "[Core] Start SOCKS Proxy");
|
||||
state.socks ? "[Core] Stop SOCKS Proxy" : "[Core] Start SOCKS Proxy");
|
||||
}
|
||||
if (controls_proxy_button) {
|
||||
if (controls_proxy_button)
|
||||
{
|
||||
gtk_button_set_label(GTK_BUTTON(controls_proxy_button),
|
||||
state.socks ? "Stop SOCKS Proxy" : "Start SOCKS Proxy");
|
||||
state.socks ? "Stop SOCKS Proxy" : "Start SOCKS Proxy");
|
||||
}
|
||||
|
||||
if (tproxy_item) {
|
||||
if (tproxy_item)
|
||||
{
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(tproxy_item),
|
||||
state.tproxy ? "[Traffic] Stop TProxy Mode" : "[Traffic] Start TProxy Mode");
|
||||
state.tproxy ? "[Traffic] Stop TProxy Mode" : "[Traffic] Start TProxy Mode");
|
||||
}
|
||||
if (controls_tproxy_button) {
|
||||
if (controls_tproxy_button)
|
||||
{
|
||||
gtk_button_set_label(GTK_BUTTON(controls_tproxy_button),
|
||||
state.tproxy ? "Stop TProxy Mode" : "Start TProxy Mode");
|
||||
state.tproxy ? "Stop TProxy Mode" : "Start TProxy Mode");
|
||||
}
|
||||
if (tun_item) {
|
||||
if (tun_item)
|
||||
{
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(tun_item),
|
||||
state.tun ? "[Traffic] Stop TUN Mode" : "[Traffic] Start TUN Mode");
|
||||
state.tun ? "[Traffic] Stop TUN Mode" : "[Traffic] Start TUN Mode");
|
||||
}
|
||||
if (controls_tun_button) {
|
||||
if (controls_tun_button)
|
||||
{
|
||||
gtk_button_set_label(GTK_BUTTON(controls_tun_button),
|
||||
state.tun ? "Stop TUN Mode" : "Start TUN Mode");
|
||||
state.tun ? "Stop TUN Mode" : "Start TUN Mode");
|
||||
}
|
||||
if (zapret_item) {
|
||||
if (zapret_item)
|
||||
{
|
||||
gtk_menu_item_set_label(
|
||||
GTK_MENU_ITEM(zapret_item),
|
||||
state.zapret ? "[Zapret] Stop zapret-discord-youtube" : "[Zapret] Start zapret-discord-youtube"
|
||||
);
|
||||
state.zapret ? "[Zapret] Stop zapret-discord-youtube" : "[Zapret] Start zapret-discord-youtube");
|
||||
}
|
||||
if (controls_zapret_button) {
|
||||
if (controls_zapret_button)
|
||||
{
|
||||
gtk_button_set_label(
|
||||
GTK_BUTTON(controls_zapret_button),
|
||||
state.zapret ? "Stop zapret-discord-youtube" : "Start zapret-discord-youtube"
|
||||
);
|
||||
state.zapret ? "Stop zapret-discord-youtube" : "Start zapret-discord-youtube");
|
||||
}
|
||||
|
||||
g_free(summary_text);
|
||||
@@ -440,64 +503,91 @@ static void update_status(void) {
|
||||
g_free(zapret_text);
|
||||
}
|
||||
|
||||
static void on_proxy_toggle(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_proxy_toggle(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
ServiceState state = get_service_state();
|
||||
if (state.socks) {
|
||||
if (state.socks)
|
||||
{
|
||||
run_proxy_ctl2("proxy", "off");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
run_proxy_ctl2("proxy", "on");
|
||||
}
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_tproxy_toggle(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_tproxy_toggle(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
ServiceState state = get_service_state();
|
||||
if (state.tproxy) {
|
||||
if (state.tproxy)
|
||||
{
|
||||
run_proxy_ctl2("tproxy", "off");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
run_proxy_ctl2("tproxy", "on");
|
||||
}
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_tun_toggle(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_tun_toggle(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
ServiceState state = get_service_state();
|
||||
if (state.tun) {
|
||||
if (state.tun)
|
||||
{
|
||||
run_proxy_ctl2("tun", "off");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
run_proxy_ctl2("tun", "on");
|
||||
}
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_zapret_toggle(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_zapret_toggle(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
ServiceState state = get_service_state();
|
||||
if (state.zapret) {
|
||||
if (state.zapret)
|
||||
{
|
||||
run_proxy_ctl2("zapret", "off");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
run_proxy_ctl2("zapret", "on");
|
||||
}
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_restart(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_restart(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
run_proxy_ctl1("restart");
|
||||
update_status();
|
||||
}
|
||||
|
||||
static void on_subscription_update(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_subscription_update(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
run_proxy_ctl2("subscription", "update");
|
||||
}
|
||||
|
||||
static void on_open_controls(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
if (!controls_window) {
|
||||
static void on_open_controls(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
if (!controls_window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
update_status();
|
||||
@@ -505,18 +595,22 @@ static void on_open_controls(GtkWidget *item, gpointer data) {
|
||||
gtk_window_present(GTK_WINDOW(controls_window));
|
||||
}
|
||||
|
||||
static void on_quit(GtkWidget *item, gpointer data) {
|
||||
(void)item; (void)data;
|
||||
static void on_quit(GtkWidget *item, gpointer data)
|
||||
{
|
||||
(void)item;
|
||||
(void)data;
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
static gboolean on_timer(gpointer data) {
|
||||
static gboolean on_timer(gpointer data)
|
||||
{
|
||||
(void)data;
|
||||
update_status();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void build_controls_window(void) {
|
||||
static void build_controls_window(void)
|
||||
{
|
||||
controls_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(controls_window), "Proxy Suite Controls");
|
||||
gtk_window_set_resizable(GTK_WINDOW(controls_window), FALSE);
|
||||
@@ -554,19 +648,22 @@ static void build_controls_window(void) {
|
||||
gtk_label_set_xalign(GTK_LABEL(controls_traffic_status_label), 0.0f);
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_traffic_status_label, FALSE, FALSE, 0);
|
||||
|
||||
if (initial_state.tproxy_available) {
|
||||
if (initial_state.tproxy_available)
|
||||
{
|
||||
controls_tproxy_button = gtk_button_new_with_label("Start TProxy Mode");
|
||||
g_signal_connect(controls_tproxy_button, "clicked", G_CALLBACK(on_tproxy_toggle), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_tproxy_button, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
if (initial_state.tun_available) {
|
||||
if (initial_state.tun_available)
|
||||
{
|
||||
controls_tun_button = gtk_button_new_with_label("Start TUN Mode");
|
||||
g_signal_connect(controls_tun_button, "clicked", G_CALLBACK(on_tun_toggle), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(traffic_box), controls_tun_button, FALSE, FALSE, 0);
|
||||
}
|
||||
|
||||
if (initial_state.zapret_available) {
|
||||
if (initial_state.zapret_available)
|
||||
{
|
||||
GtkWidget *zapret_frame = gtk_frame_new("[Zapret] DPI bypass");
|
||||
GtkWidget *zapret_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(zapret_box), 6);
|
||||
@@ -588,7 +685,8 @@ static void build_controls_window(void) {
|
||||
gtk_container_add(GTK_CONTAINER(tools_frame), tools_box);
|
||||
gtk_box_pack_start(GTK_BOX(box), tools_frame, FALSE, FALSE, 0);
|
||||
|
||||
if (initial_state.subscription_update_available) {
|
||||
if (initial_state.subscription_update_available)
|
||||
{
|
||||
GtkWidget *sub_update_button = gtk_button_new_with_label("Update Subscriptions");
|
||||
g_signal_connect(sub_update_button, "clicked", G_CALLBACK(on_subscription_update), NULL);
|
||||
gtk_box_pack_start(GTK_BOX(tools_box), sub_update_button, FALSE, FALSE, 0);
|
||||
@@ -610,7 +708,8 @@ static void build_controls_window(void) {
|
||||
gtk_widget_hide(controls_window);
|
||||
}
|
||||
|
||||
static void build_menu(void) {
|
||||
static void build_menu(void)
|
||||
{
|
||||
menu = gtk_menu_new();
|
||||
|
||||
status_item = gtk_menu_item_new_with_label("[Status] Loading service state...");
|
||||
@@ -629,19 +728,22 @@ static void build_menu(void) {
|
||||
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
|
||||
|
||||
if (initial_state.tproxy_available) {
|
||||
if (initial_state.tproxy_available)
|
||||
{
|
||||
tproxy_item = gtk_menu_item_new_with_label("[Traffic] Start TProxy Mode");
|
||||
g_signal_connect(tproxy_item, "activate", G_CALLBACK(on_tproxy_toggle), NULL);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), tproxy_item);
|
||||
}
|
||||
|
||||
if (initial_state.tun_available) {
|
||||
if (initial_state.tun_available)
|
||||
{
|
||||
tun_item = gtk_menu_item_new_with_label("[Traffic] Start TUN Mode");
|
||||
g_signal_connect(tun_item, "activate", G_CALLBACK(on_tun_toggle), NULL);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), tun_item);
|
||||
}
|
||||
|
||||
if (initial_state.zapret_available) {
|
||||
if (initial_state.zapret_available)
|
||||
{
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
|
||||
|
||||
zapret_item = gtk_menu_item_new_with_label("[Zapret] Start zapret-discord-youtube");
|
||||
@@ -649,7 +751,8 @@ static void build_menu(void) {
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), zapret_item);
|
||||
}
|
||||
|
||||
if (initial_state.subscription_update_available) {
|
||||
if (initial_state.subscription_update_available)
|
||||
{
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
|
||||
|
||||
GtkWidget *sub_update_item = gtk_menu_item_new_with_label("Update Subscriptions");
|
||||
@@ -672,31 +775,34 @@ static void build_menu(void) {
|
||||
gtk_widget_show_all(menu);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (!gtk_init_check(&argc, &argv)) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (!gtk_init_check(&argc, &argv))
|
||||
{
|
||||
fprintf(stderr, "proxy-suite-tray: failed to initialize GTK\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
GError *bus_error = NULL;
|
||||
GDBusConnection *session_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &bus_error);
|
||||
if (session_bus) {
|
||||
if (session_bus)
|
||||
{
|
||||
g_dbus_connection_add_filter(session_bus, on_session_bus_message, NULL, NULL);
|
||||
g_object_unref(session_bus);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(
|
||||
stderr,
|
||||
"proxy-suite-tray: warning: failed to monitor session bus: %s\n",
|
||||
bus_error ? bus_error->message : "unknown error"
|
||||
);
|
||||
bus_error ? bus_error->message : "unknown error");
|
||||
g_clear_error(&bus_error);
|
||||
}
|
||||
|
||||
indicator = app_indicator_new(
|
||||
"proxy-suite-tray",
|
||||
"proxy-suite-disabled",
|
||||
APP_INDICATOR_CATEGORY_SYSTEM_SERVICES
|
||||
);
|
||||
APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
|
||||
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
|
||||
|
||||
initial_state = get_service_state();
|
||||
|
||||
Reference in new issue
Block a user