Skip to content

Commit

Permalink
fix: Fix custom accent color using RGBA instead of RGB. closes shdwmt…
Browse files Browse the repository at this point in the history
  • Loading branch information
shdwmtr committed Feb 10, 2025
1 parent 4e1cc7f commit 4b095d6
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions assets/core/api/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,19 @@ def adjust_hex_color(hex_color, percent=15):
adjusted_hex = f'#{r:02x}{g:02x}{b:02x}'
return adjusted_hex

def hex_to_rgba(hex_color):
def hex_to_rgb(hex_color):
# Remove the '#' character if present
hex_color = hex_color.lstrip('#')

# Check if the input has an alpha channel (8 characters)
if len(hex_color) == 8:
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
a = int(hex_color[6:8], 16) / 255 # Normalize alpha to [0, 1]
elif len(hex_color) == 6:
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
a = 1.0 # Fully opaque
else:
raise ValueError("Invalid hex color format. Use 6 or 8 characters.")
if len(hex_color) != 6:
raise ValueError("Invalid hex color format. Use 6 characters (e.g., #RRGGBB).")

r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)

return (r, g, b, a)
return (r, g, b)

original_accent = Colors.get_accent_color_win32() if os.name == 'nt' else Colors.get_accent_color_posix()

Expand All @@ -100,13 +94,13 @@ def hex_to_rgba(hex_color):
'dark1': adjust_hex_color(accent_color, -15),
'dark2': adjust_hex_color(accent_color, -30),
'dark3': adjust_hex_color(accent_color, -45),
'accentRgb': hex_to_rgba(accent_color),
'light1Rgb': hex_to_rgba(adjust_hex_color(accent_color, 15)),
'light2Rgb': hex_to_rgba(adjust_hex_color(accent_color, 30)),
'light3Rgb': hex_to_rgba(adjust_hex_color(accent_color, 45)),
'dark1Rgb': hex_to_rgba(adjust_hex_color(accent_color, -15)),
'dark2Rgb': hex_to_rgba(adjust_hex_color(accent_color, -30)),
'dark3Rgb': hex_to_rgba(adjust_hex_color(accent_color, -45)),
'accentRgb': hex_to_rgb(accent_color),
'light1Rgb': hex_to_rgb(adjust_hex_color(accent_color, 15)),
'light2Rgb': hex_to_rgb(adjust_hex_color(accent_color, 30)),
'light3Rgb': hex_to_rgb(adjust_hex_color(accent_color, 45)),
'dark1Rgb': hex_to_rgb(adjust_hex_color(accent_color, -15)),
'dark2Rgb': hex_to_rgb(adjust_hex_color(accent_color, -30)),
'dark3Rgb': hex_to_rgb(adjust_hex_color(accent_color, -45)),
'systemAccent': False,
'originalAccent': original_accent
})
Expand Down

0 comments on commit 4b095d6

Please sign in to comment.