Last active
January 26, 2022 16:17
-
-
Save dom111/94b94a85d68258b9f59eda355489b072 to your computer and use it in GitHub Desktop.
A way to have a GlobalProtect icon in your system tray if it doesn't show up on Ubuntu
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
#!/usr/bin/python | |
import os | |
import gi | |
gi.require_version('Gtk', '3.0') | |
gi.require_version('AppIndicator3', '0.1') | |
from gi.repository import Gtk as gtk, AppIndicator3 as appindicator | |
import subprocess | |
import time | |
import threading | |
def check(indicator): | |
while True: | |
if indicator: | |
result = subprocess.run(['/bin/grep', 'gpd', '/proc/net/route'], capture_output=True) | |
if result.returncode == 0: | |
indicator.set_icon_full('krb-expiring-ticket', '') | |
else: | |
indicator.set_icon_full('krb-valid-ticket', '') | |
time.sleep(5) | |
def main(): | |
indicator = appindicator.Indicator.new('customtray', 'krb-valid-ticket', appindicator.IndicatorCategory.APPLICATION_STATUS) | |
indicator.set_status(appindicator.IndicatorStatus.ACTIVE) | |
indicator.set_menu(menu()) | |
watch = threading.Thread(target=check, args=[indicator], daemon=True) | |
watch.start() | |
gtk.main() | |
def menu(): | |
menu = gtk.Menu() | |
open_gp = gtk.MenuItem(label='Open...') | |
open_gp.connect('activate', show) | |
menu.append(open_gp) | |
menu.show_all() | |
return menu | |
def show(_): | |
os.system('globalprotect launch-ui') | |
if __name__ == '__main__': | |
try: | |
main() | |
except KeyboardInterrupt: | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment