-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwal-to-chrome.py
46 lines (38 loc) · 1.76 KB
/
wal-to-chrome.py
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
37
38
39
40
41
42
43
44
45
46
import json, os
waldir = "~/.cache/wal/"
dest_file = "manifest.json"
walfile = "colors.json"
new_colors=[]
def hex_to_rgb(hexin):
hexin = hexin.lstrip("#")
rgb_out = tuple(int(hexin[i:i+2], 16) for i in (0, 2, 4))
#rgb_out is like (255, 255, 255)
# need to convert it to something like [255, 255, 255]
rgb_out = list(rgb_out)
return rgb_out
waltocrx = {'special.background': 'theme.colors.ntpbackground',
'special.foreground': 'theme.colors.frame',
'colors.color1': 'theme.colors.button_background',
'colors.color2': 'theme.colors.ntp_text',
'colors.color3': 'theme.colors.tab_background_text',
'colors.color4': 'theme.colors.tab_text',
'special.cursor': 'theme.colors.toolbar'}
# read wal's colors
with open(walfile, "r") as read_file:
wal_colors = json.load(read_file)
# read manifest's colors
with open(dest_file, "r") as read_file:
chrome_colors = json.load(read_file)
#loop through each key, read wal's color, and put it in manifest's json
with open(dest_file, 'r+') as f:
chrome_colors = json.load(f)
for key in waltocrx:
hexcolor = wal_colors[key.split('.')[0]][key.split('.')[1]]
rgbcolor = hex_to_rgb(hexcolor)
chrome_colors[waltocrx[key].split('.')[0]][waltocrx[key].split('.')[1]][waltocrx[key].split('.')[2]] = rgbcolor # f.seek(0) # <--- should reset file position to the beginning.
os.remove(dest_file) #need to overwrite it, might be better ways
with open(dest_file, "w+") as f:
json.dump(chrome_colors, f, indent=None) #this puts it in a compacted form but it works, not sure if its possible to preserve original form, every other indent level adds newlines to each RGB value
f.truncate() # remove remaining part
# manifest.json should be updated now, proceed as normal packing .crx
# this can be done from CLI as well, additional feature