This commit is contained in:
fqbn207
2024-12-17 01:26:25 +01:00
parent 413d66e719
commit 142f761930
5 changed files with 55 additions and 6 deletions

View File

@ -28,7 +28,8 @@ COM =\
components/user\ components/user\
components/volume\ components/volume\
components/wifi\ components/wifi\
components/mullvad components/mullvad\
components/relay
all: slstatus all: slstatus
$(COM:=.o): config.mk $(REQ:=.h) slstatus.h $(COM:=.o): config.mk $(REQ:=.h) slstatus.h

View File

@ -12,7 +12,7 @@ static int
mullvad_conn() mullvad_conn()
{ {
FILE *fp; FILE *fp;
char buff[128]; char buff[0x80];
int conn = 0; int conn = 0;
fp = popen(MULLVAD_STAT_CMD, "r"); fp = popen(MULLVAD_STAT_CMD, "r");

45
components/relay.c Normal file
View File

@ -0,0 +1,45 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../slstatus.h"
#include "../util.h"
#define MULLVAD_STAT_CMD "mullvad status"
static const char *get_relay() {
FILE *fp;
char buff[0x80];
static char relay[0x80];
fp = popen("mullvad status", "r");
if (fp == NULL) {
perror("popen");
return NULL;
}
while (fgets(buff, sizeof(buff), fp) != NULL) {
if (strstr(buff, "Relay")) {
if (sscanf(buff, "Relay: %s", relay) == 1) {
fclose(fp);
return relay;
}
}
}
pclose(fp);
return NULL;
}
const char *mullvad_relay(const char *stat) {
static char rtrelay[0x80];
const char *relay = get_relay();
if (relay != NULL) {
snprintf(rtrelay, sizeof(rtrelay), "%s", relay);
} else {
snprintf(rtrelay, sizeof(rtrelay), "No Relay");
}
return rtrelay;
}

View File

@ -11,13 +11,14 @@ static const struct arg args[] = {
{ netspeed_tx, " [ %sB/s]", IFACE }, { netspeed_tx, " [ %sB/s]", IFACE },
{ ipv4, " ^c#fb4934^[ %s]", IFACE }, { ipv4, " ^c#fb4934^[ %s]", IFACE },
{ run_command, " ^c#fb4934^[%s]", "sh /opt/suckless/slstatus/components/wg.sh" }, { run_command, " ^c#fb4934^[%s]", "sh /opt/suckless/slstatus/components/wg.sh" },
{ mullvad_stat, " [VPN: %s]", NULL}, { mullvad_relay, " [%s]", NULL },
{ mullvad_stat, " [%s]", NULL },
//{ battery_perc, " ^c#fe9019^[ %s%%", BAT }, //{ battery_perc, " ^c#fe9019^[ %s%%", BAT },
//{ battery_remaining," %s]", BAT }, //{ battery_remaining," %s]", BAT },
{ run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" }, //{ run_command, " ^c#8ec07c^[ %s]", "amixer sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n1" },
// { vol_perc, " ^c#8ec07c^[ %s]", NULL }, { vol_perc, " ^c#8ec07c^[ %s]", NULL },
{ cpu_perc, " ^c#b8bb26^[%s%%]", NULL }, { cpu_perc, " ^c#b8bb26^[%s%%]", NULL },
{ ram_used, " ^c#d3869b^[ %s]", NULL }, { ram_used, " ^c#d3869b^[ %s]", NULL },
{ datetime, " ^c#ebdbb2^[ %s]", "%H:%M:%S" }, { datetime, " ^c#ebdbb2^[ %s]", "%H:%M:%S" },

View File

@ -86,3 +86,5 @@ const char *wifi_perc(const char *interface);
/* mullvad */ /* mullvad */
const char *mullvad_stat(const char *stat); const char *mullvad_stat(const char *stat);
const char *mullvad_relay(const char *stat);