Skip to content

Commit 4244b51

Browse files
committed
sync cli device colors
1 parent 94f7663 commit 4244b51

4 files changed

Lines changed: 120 additions & 66 deletions

File tree

cmd/go2tv-lite/go2tv.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"go2tv.app/go2tv/v2/devices"
2727
"go2tv.app/go2tv/v2/httphandlers"
2828
"go2tv.app/go2tv/v2/internal/crashlog"
29+
"go2tv.app/go2tv/v2/internal/devicecolors"
2930
"go2tv.app/go2tv/v2/soapcalls"
3031
"go2tv.app/go2tv/v2/utils"
3132
)
@@ -466,17 +467,18 @@ func (m listDevicesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
466467
}
467468

468469
var (
469-
chromecastTag = lipgloss.NewStyle().
470-
Foreground(lipgloss.Color("#1A73E8")).
471-
Background(lipgloss.Color("#E8F0FE")).
472-
Bold(true)
473-
474-
dlnaTag = lipgloss.NewStyle().
475-
Foreground(lipgloss.Color("#6F42C1")).
476-
Background(lipgloss.Color("#F3E8FF")).
477-
Bold(true)
470+
chromecastTag = deviceTagStyle(devices.DeviceTypeChromecast)
471+
dlnaTag = deviceTagStyle(devices.DeviceTypeDLNA)
478472
)
479473

474+
func deviceTagStyle(deviceType string) lipgloss.Style {
475+
palette := devicecolors.DarkPalette(deviceType)
476+
return lipgloss.NewStyle().
477+
Foreground(lipgloss.Color(devicecolors.Hex(palette.Text))).
478+
Background(lipgloss.Color(devicecolors.Hex(palette.Fill))).
479+
Bold(true)
480+
}
481+
480482
func typeTag(t string) string {
481483
switch strings.ToLower(t) {
482484
case "chromecast":

cmd/go2tv/go2tv.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"go2tv.app/go2tv/v2/devices"
2727
"go2tv.app/go2tv/v2/httphandlers"
2828
"go2tv.app/go2tv/v2/internal/crashlog"
29+
"go2tv.app/go2tv/v2/internal/devicecolors"
2930
"go2tv.app/go2tv/v2/internal/gui"
3031
"go2tv.app/go2tv/v2/internal/interactive"
3132
"go2tv.app/go2tv/v2/soapcalls"
@@ -444,17 +445,18 @@ func (m listDevicesModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
444445
}
445446

446447
var (
447-
chromecastTag = lipgloss.NewStyle().
448-
Foreground(lipgloss.Color("#1A73E8")).
449-
Background(lipgloss.Color("#E8F0FE")).
450-
Bold(true)
451-
452-
dlnaTag = lipgloss.NewStyle().
453-
Foreground(lipgloss.Color("#6F42C1")).
454-
Background(lipgloss.Color("#F3E8FF")).
455-
Bold(true)
448+
chromecastTag = deviceTagStyle(devices.DeviceTypeChromecast)
449+
dlnaTag = deviceTagStyle(devices.DeviceTypeDLNA)
456450
)
457451

452+
func deviceTagStyle(deviceType string) lipgloss.Style {
453+
palette := devicecolors.DarkPalette(deviceType)
454+
return lipgloss.NewStyle().
455+
Foreground(lipgloss.Color(devicecolors.Hex(palette.Text))).
456+
Background(lipgloss.Color(devicecolors.Hex(palette.Fill))).
457+
Bold(true)
458+
}
459+
458460
func typeTag(t string) string {
459461
switch strings.ToLower(t) {
460462
case "chromecast":
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package devicecolors
2+
3+
import (
4+
"image/color"
5+
6+
"go2tv.app/go2tv/v2/devices"
7+
)
8+
9+
type Palette struct {
10+
Fill color.NRGBA
11+
Stroke color.NRGBA
12+
Text color.NRGBA
13+
}
14+
15+
func LightPalette(deviceType string) Palette {
16+
switch deviceType {
17+
case devices.DeviceTypeChromecast:
18+
return Palette{
19+
Fill: color.NRGBA{R: 0xda, G: 0xee, B: 0xe7, A: 0xff},
20+
Stroke: color.NRGBA{R: 0xda, G: 0xee, B: 0xe7, A: 0xff},
21+
Text: color.NRGBA{R: 0x34, G: 0x6d, B: 0x5f, A: 0xff},
22+
}
23+
case devices.DeviceTypeDLNA:
24+
return Palette{
25+
Fill: color.NRGBA{R: 0xe2, G: 0xe8, B: 0xfa, A: 0xff},
26+
Stroke: color.NRGBA{R: 0xe2, G: 0xe8, B: 0xfa, A: 0xff},
27+
Text: color.NRGBA{R: 0x46, G: 0x5d, B: 0x96, A: 0xff},
28+
}
29+
default:
30+
return Palette{
31+
Fill: color.NRGBA{R: 0xea, G: 0xea, B: 0xea, A: 0xff},
32+
Stroke: color.NRGBA{R: 0xea, G: 0xea, B: 0xea, A: 0xff},
33+
Text: color.NRGBA{R: 0x5f, G: 0x5f, B: 0x5f, A: 0xff},
34+
}
35+
}
36+
}
37+
38+
func DarkPalette(deviceType string) Palette {
39+
switch deviceType {
40+
case devices.DeviceTypeChromecast:
41+
return Palette{
42+
Fill: color.NRGBA{R: 0x36, G: 0x47, B: 0x42, A: 0xff},
43+
Stroke: color.NRGBA{R: 0x36, G: 0x47, B: 0x42, A: 0xff},
44+
Text: color.NRGBA{R: 0xbd, G: 0xd4, B: 0xcb, A: 0xff},
45+
}
46+
case devices.DeviceTypeDLNA:
47+
return Palette{
48+
Fill: color.NRGBA{R: 0x3a, G: 0x40, B: 0x52, A: 0xff},
49+
Stroke: color.NRGBA{R: 0x3a, G: 0x40, B: 0x52, A: 0xff},
50+
Text: color.NRGBA{R: 0xc3, G: 0xcd, B: 0xe8, A: 0xff},
51+
}
52+
default:
53+
return Palette{
54+
Fill: color.NRGBA{R: 0x3a, G: 0x3a, B: 0x3a, A: 0xff},
55+
Stroke: color.NRGBA{R: 0x3a, G: 0x3a, B: 0x3a, A: 0xff},
56+
Text: color.NRGBA{R: 0xbe, G: 0xbe, B: 0xbe, A: 0xff},
57+
}
58+
}
59+
}
60+
61+
func AudioOnlyLightPalette() Palette {
62+
return Palette{
63+
Fill: color.NRGBA{R: 0xf6, G: 0xea, B: 0xd6, A: 0xff},
64+
Stroke: color.NRGBA{R: 0xf6, G: 0xea, B: 0xd6, A: 0xff},
65+
Text: color.NRGBA{R: 0x83, G: 0x64, B: 0x2f, A: 0xff},
66+
}
67+
}
68+
69+
func AudioOnlyDarkPalette() Palette {
70+
return Palette{
71+
Fill: color.NRGBA{R: 0x48, G: 0x3c, B: 0x2d, A: 0xff},
72+
Stroke: color.NRGBA{R: 0x48, G: 0x3c, B: 0x2d, A: 0xff},
73+
Text: color.NRGBA{R: 0xe1, G: 0xc0, B: 0x92, A: 0xff},
74+
}
75+
}
76+
77+
func Hex(c color.NRGBA) string {
78+
const digits = "0123456789abcdef"
79+
buf := []byte{'#', 0, 0, 0, 0, 0, 0}
80+
buf[1] = digits[c.R>>4]
81+
buf[2] = digits[c.R&0x0f]
82+
buf[3] = digits[c.G>>4]
83+
buf[4] = digits[c.G&0x0f]
84+
buf[5] = digits[c.B>>4]
85+
buf[6] = digits[c.B&0x0f]
86+
return string(buf)
87+
}

internal/gui/device_badges.go

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fyne.io/fyne/v2/widget"
1212
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
1313
"go2tv.app/go2tv/v2/devices"
14+
"go2tv.app/go2tv/v2/internal/devicecolors"
1415
)
1516

1617
type badgePalette struct {
@@ -189,63 +190,25 @@ func (r *deviceRowRenderer) Refresh() {
189190

190191
func deviceBadgePalette(deviceType string) badgePalette {
191192
if currentThemeVariant() == theme.VariantLight {
192-
switch deviceType {
193-
case devices.DeviceTypeChromecast:
194-
return badgePalette{
195-
fill: color.NRGBA{R: 0xda, G: 0xee, B: 0xe7, A: 0xff},
196-
stroke: color.NRGBA{R: 0xda, G: 0xee, B: 0xe7, A: 0xff},
197-
text: color.NRGBA{R: 0x34, G: 0x6d, B: 0x5f, A: 0xff},
198-
}
199-
case devices.DeviceTypeDLNA:
200-
return badgePalette{
201-
fill: color.NRGBA{R: 0xe2, G: 0xe8, B: 0xfa, A: 0xff},
202-
stroke: color.NRGBA{R: 0xe2, G: 0xe8, B: 0xfa, A: 0xff},
203-
text: color.NRGBA{R: 0x46, G: 0x5d, B: 0x96, A: 0xff},
204-
}
205-
default:
206-
return badgePalette{
207-
fill: color.NRGBA{R: 0xea, G: 0xea, B: 0xea, A: 0xff},
208-
stroke: color.NRGBA{R: 0xea, G: 0xea, B: 0xea, A: 0xff},
209-
text: color.NRGBA{R: 0x5f, G: 0x5f, B: 0x5f, A: 0xff},
210-
}
211-
}
193+
return badgePaletteFromDeviceColors(devicecolors.LightPalette(deviceType))
212194
}
213195

214-
switch deviceType {
215-
case devices.DeviceTypeChromecast:
216-
return badgePalette{
217-
fill: color.NRGBA{R: 0x36, G: 0x47, B: 0x42, A: 0xff},
218-
stroke: color.NRGBA{R: 0x36, G: 0x47, B: 0x42, A: 0xff},
219-
text: color.NRGBA{R: 0xbd, G: 0xd4, B: 0xcb, A: 0xff},
220-
}
221-
case devices.DeviceTypeDLNA:
222-
return badgePalette{
223-
fill: color.NRGBA{R: 0x3a, G: 0x40, B: 0x52, A: 0xff},
224-
stroke: color.NRGBA{R: 0x3a, G: 0x40, B: 0x52, A: 0xff},
225-
text: color.NRGBA{R: 0xc3, G: 0xcd, B: 0xe8, A: 0xff},
226-
}
227-
default:
228-
return badgePalette{
229-
fill: color.NRGBA{R: 0x3a, G: 0x3a, B: 0x3a, A: 0xff},
230-
stroke: color.NRGBA{R: 0x3a, G: 0x3a, B: 0x3a, A: 0xff},
231-
text: color.NRGBA{R: 0xbe, G: 0xbe, B: 0xbe, A: 0xff},
232-
}
233-
}
196+
return badgePaletteFromDeviceColors(devicecolors.DarkPalette(deviceType))
234197
}
235198

236199
func audioOnlyBadgePalette() badgePalette {
237200
if currentThemeVariant() == theme.VariantLight {
238-
return badgePalette{
239-
fill: color.NRGBA{R: 0xf6, G: 0xea, B: 0xd6, A: 0xff},
240-
stroke: color.NRGBA{R: 0xf6, G: 0xea, B: 0xd6, A: 0xff},
241-
text: color.NRGBA{R: 0x83, G: 0x64, B: 0x2f, A: 0xff},
242-
}
201+
return badgePaletteFromDeviceColors(devicecolors.AudioOnlyLightPalette())
243202
}
244203

204+
return badgePaletteFromDeviceColors(devicecolors.AudioOnlyDarkPalette())
205+
}
206+
207+
func badgePaletteFromDeviceColors(p devicecolors.Palette) badgePalette {
245208
return badgePalette{
246-
fill: color.NRGBA{R: 0x48, G: 0x3c, B: 0x2d, A: 0xff},
247-
stroke: color.NRGBA{R: 0x48, G: 0x3c, B: 0x2d, A: 0xff},
248-
text: color.NRGBA{R: 0xe1, G: 0xc0, B: 0x92, A: 0xff},
209+
fill: p.Fill,
210+
stroke: p.Stroke,
211+
text: p.Text,
249212
}
250213
}
251214

0 commit comments

Comments
 (0)