diff options
Diffstat (limited to 'browsers/firefox/accent_host.py')
| -rwxr-xr-x | browsers/firefox/accent_host.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/browsers/firefox/accent_host.py b/browsers/firefox/accent_host.py new file mode 100755 index 0000000..ec0a166 --- /dev/null +++ b/browsers/firefox/accent_host.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +import json +import os +import struct +import subprocess +import sys + +def send(msg): + data = json.dumps(msg).encode('utf-8') + sys.stdout.buffer.write(struct.pack('I', len(data))) + sys.stdout.buffer.write(data) + sys.stdout.buffer.flush() + +def read(): + raw = sys.stdin.buffer.read(4) + if len(raw) == 0: + return None + length = struct.unpack('I', raw)[0] + return json.loads(sys.stdin.buffer.read(length).decode('utf-8')) + +def get_accent(): + try: + helper = os.path.join(os.path.dirname(__file__), '..', 'getaccent') + color = subprocess.check_output([helper], stderr=subprocess.DEVNULL).decode().strip() + if color: + return color + except Exception: + pass + return '#000000' + +while True: + msg = read() + if msg is None: + break + if msg.get('query') == 'color': + send({'color': get_accent()}) |
