Created
January 20, 2024 14:26
-
-
Save 1208nn/e10b8979f385c2613c02caf8e4716c0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import pystray | |
from pystray import MenuItem as item | |
from PIL import Image, ImageDraw | |
def get_warp_status(): | |
result = subprocess.run( | |
["warp-cli", "status"], capture_output=True, text=True, shell=True | |
) | |
return "connected" if "Connected" in result.stdout else "disconnected" | |
def switch(icon, item): | |
status = get_warp_status() | |
if status == "connected": | |
icon.icon = disconnected_ico | |
subprocess.run(["warp-cli", "disconnect"], shell=True) | |
else: | |
icon.icon = connected_ico | |
subprocess.run(["warp-cli", "connect"], shell=True) | |
def close(icon, item): | |
icon.stop() | |
connected_ico = Image.new("RGBA", (16, 16), (255, 255, 255, 0)) | |
draw = ImageDraw.Draw(connected_ico) | |
draw.line((2, 8, 6, 12), fill="green", width=2) | |
draw.line((6, 12, 14, 4), fill="green", width=2) | |
disconnected_ico = Image.new("RGBA", (16, 16), (255, 255, 255, 0)) | |
draw = ImageDraw.Draw(disconnected_ico) | |
draw.line((2, 2, 13, 13), fill="red", width=2) | |
draw.line((3, 13, 14, 2), fill="red", width=2) | |
pystray.Icon( | |
"warp", | |
connected_ico if get_warp_status() == "connected" else disconnected_ico, | |
"Warp", | |
(item("Connect/Disconnect", switch), item("Exit", close)), | |
).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment