blob: ec0a166304c5a4456a109194b2919ea5327ca27f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()})
|