Updating states to just use 1 and use code for the images and title because it turns out more than 2 states doesn't work right

This commit is contained in:
Daniel Prows 2023-08-24 22:45:26 -06:00
parent a5ac31de17
commit 511e8fdd4c
3 changed files with 53 additions and 43 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 0
}
]
}

View File

@ -7,28 +7,7 @@
"Icon": "Images/icon", "Icon": "Images/icon",
"States": [ "States": [
{ {
"Image": "Images/proxyDisabled", "Image": "Images/proxyDisabled"
"TitleAlignment": "middle",
"FontSize": "12",
"Title" : "Disabled"
},
{
"Image": "Images/proxyEnabled",
"TitleAlignment": "middle",
"FontSize": "12",
"Title": "Enabled"
},
{
"Image": "Images/noNetwork",
"TitleAlignment": "middle",
"FontSize": "12",
"Title": "No Network"
},
{
"Image": "Images/error",
"TitleAlignment": "middle",
"FontSize": "12",
"Title": "Error"
} }
], ],
"Controllers": [ "Keypad" ], "Controllers": [ "Keypad" ],

View File

@ -41,10 +41,26 @@ func setup(client *streamdeck.Client) {
action.RegisterHandler(streamdeck.KeyDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error { action.RegisterHandler(streamdeck.KeyDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
log.Println("Key Down") log.Println("Key Down")
toggleVpn() err := toggleVpn()
client.SetState(ctx, getState()) if err != nil {
client.ShowAlert(ctx)
return err
}
client.ShowOk(ctx)
time.Sleep(time.Millisecond * 500)
image, title := getState()
err1 := client.SetImage(ctx, image, streamdeck.HardwareAndSoftware)
err2 := client.SetTitle(ctx, title, streamdeck.HardwareAndSoftware)
if err1 != nil {
return err1
}
if err2 != nil {
return err2
}
return nil return nil
}) })
@ -52,7 +68,16 @@ func setup(client *streamdeck.Client) {
log.Println("Will Appear") log.Println("Will Appear")
contexts[event.Context] = struct{}{} contexts[event.Context] = struct{}{}
client.SetState(ctx, getState()) image, title := getState()
err1 := client.SetImage(ctx, image, streamdeck.HardwareAndSoftware)
err2 := client.SetTitle(ctx, title, streamdeck.HardwareAndSoftware)
if err1 != nil {
return err1
}
if err2 != nil {
return err2
}
return nil return nil
}) })
@ -72,18 +97,15 @@ func setup(client *streamdeck.Client) {
ctx := context.Background() ctx := context.Background()
ctx = sdcontext.WithContext(ctx, ctxStr) ctx = sdcontext.WithContext(ctx, ctxStr)
client.SetState(ctx, getState()) image, title := getState()
client.SetImage(ctx, image, streamdeck.HardwareAndSoftware)
client.SetTitle(ctx, title, streamdeck.HardwareAndSoftware)
} }
} }
}() }()
} }
func toggleVpn() error { func toggleVpn() error {
/*
if on, turn off
if off, turn on
if broken, turn off
*/
activeDevice, err := networking.GetActiveDevice() activeDevice, err := networking.GetActiveDevice()
if err != nil { if err != nil {
@ -102,30 +124,24 @@ func toggleVpn() error {
return nil return nil
} }
func getState() int { func getState() (string, string) {
/*
0 for proxy off
1 for proxy on
2 for no network
3 for busted
*/
activeDevice, err := networking.GetActiveDevice() activeDevice, err := networking.GetActiveDevice()
if err != nil { if err != nil {
return 3 return "images/error.png", "Error"
} }
if activeDevice == "" { if activeDevice == "" {
return 2 return "images/noNetwork.png", "No Network"
} }
proxyEnabled, err := networking.IsProxyEnabled(activeDevice) proxyEnabled, err := networking.IsProxyEnabled(activeDevice)
if err != nil { if err != nil {
return 3 return "images/error.png", "Error"
} }
if proxyEnabled { if proxyEnabled {
return 1 return "images/proxyEnabled.png", "Enabled"
} }
return 0 return "images/proxyDisabled.png", "Disabled"
} }