A lightweight Awesome WM widget that displays V2Ray proxy status with Wi‑Fi connection awareness. Toggle your proxy with a single click, with visual feedback that makes your connection state immediately clear.
- Wi‑Fi aware: Automatically detects Wi‑Fi connection state
- Visual indicators: Clear icons for all states
- Single-click toggle: Left click to toggle V2Ray proxy (only when Wi‑Fi is connected)
- Manual refresh: Right click to refresh status without toggling
- Error notifications: Alerts you when operations fail or Wi‑Fi is unavailable
- Singleton pattern: Ensures only one instance exists
| State | Icon | Description |
|---|---|---|
| Wi‑Fi disconnected | 🌚 | No Wi‑Fi connection detected |
| Wi‑Fi connected, proxy off | 📡 | Connected but V2Ray is not running |
| Wi‑Fi connected, proxy on | 🚀 | Connected with V2Ray proxy active |
Save the V2Ray toggle script to a location in your $PATH (e.g., ~/.local/bin/v2ray-toggle):
#!/bin/bash
# The config file you want to use
CONFIG="$HOME/.config/v2ray/latest.json"
# Check if v2ray is already running
if pgrep -f "v2ray run" > /dev/null; then
# It's running → kill it
pkill -f "v2ray run"
echo off # signal the new state
else
# Not running → start it (detached)
v2ray run -c "$CONFIG" &> /dev/null &
echo on # signal the new state
fiMake it executable:
chmod +x ~/.local/bin/v2ray-toggleNote: The widget expects this script to output either
onoroffto stdout and return exit code0on success. Feel free to adapt theCONFIGpath and process matching pattern to your setup.
Copy the widget file to your Awesome WM configuration directory:
cp proxytoggle.lua ~/.config/awesome/Add the widget to your rc.lua:
local proxytoggle = require("proxytoggle")Add the widget to your wibar or any other widget container:
-- Create the widget with defaults
local proxy_widget = proxytoggle()
-- Add to your wibar
s.mywibox:setup {
-- ... other widgets ...
proxy_widget,
-- ... other widgets ...
}The widget accepts configuration options during creation:
local proxy_widget = proxytoggle({
interface = "wlp2s0", -- Network interface to monitor
command = "v2ray-toggle", -- Command to toggle V2Ray
initial_state = false -- Initial V2Ray state (true if running)
})interface(string): Network interface name monitored vianmcli. Default:"wlp2s0"command(string): Path or name of the toggle script. Default:"v2ray-toggle"initial_state(boolean): Starting V2Ray state. Set totrueif V2Ray is running at widget creation. Default:false
- Left click: Toggle V2Ray (if Wi‑Fi is connected)
- Right click: Refresh Wi‑Fi status and update the icon
- Awesome WM 4.x
- NetworkManager with
nmclicommand available - V2Ray installed and configured
- Config file at
~/.config/v2ray/latest.json(or update the toggle script)
- Config file at
- The
v2ray-togglescript accessible in your$PATH
- On left click: The widget checks Wi‑Fi status first
- If Wi‑Fi is connected: It runs the toggle script
- The toggle script:
- Checks if V2Ray is running (via
pgrep) - If running: kills V2Ray and outputs
off - If not running: starts V2Ray with your config and outputs
on
- Checks if V2Ray is running (via
- The widget reads the output and updates the icon accordingly
- Left clicks show an error notification: "Wi‑Fi is not connected"
- V2Ray state remains unchanged
- Widget shows 🌚
- Left click toggles V2Ray on/off
- Widget updates to reflect new proxy state
- Shows 🚀 (V2Ray running) or 📡 (V2Ray stopped)
- Failed Wi‑Fi checks trigger a critical notification
- Failed toggle commands trigger a critical notification
- Errors are non-blocking and won't crash Awesome WM
If your V2Ray setup differs, modify the toggle script:
- Different config path: Change the
CONFIGvariable - Different process name: Update the
pgrep/pkillpattern (e.g.,"v2ray"vs"v2ray run") - Different commands: Replace
v2ray runwithsystemctl --user start v2rayif using systemd
The only requirement is that the script:
- Outputs exactly
onoroffto stdout - Returns exit code
0on success
Free to use and modify. Attribution appreciated.
Created by Aran and DeepSeek AI.