#!/usr/bin/python
from subprocess import run
import time


def main():
    detected = True
    while True:
        output = run(['ps', '-aux'], capture_output=True).stdout.decode('utf-8')
        if 'GenshinImpact.exe' in output:
            if detected == False:
                print('Game detected')
                detected = True
                print('Disabling network connection')
                run(['nmcli', 'n', 'off'], check=True)
                run([
                    'ffplay', '-f', 'lavfi', '-i',
                    'sine=frequency=400:duration=0.1',
                    '-autoexit', '-nodisp'], check=True)
                time.sleep(15)
                print('Enabling network connection')
                run(['nmcli', 'n', 'on'], check=True)
                run([
                    'ffplay', '-f', 'lavfi', '-i',
                    'sine=frequency=800:duration=0.1',
                    '-autoexit', '-nodisp'], check=True)
        else:
            detected = False
        time.sleep(1)

if __name__ == "__main__":
    main()
