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:
parent
a5ac31de17
commit
511e8fdd4c
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal 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
|
||||
}
|
||||
]
|
||||
}
|
@ -7,28 +7,7 @@
|
||||
"Icon": "Images/icon",
|
||||
"States": [
|
||||
{
|
||||
"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"
|
||||
"Image": "Images/proxyDisabled"
|
||||
}
|
||||
],
|
||||
"Controllers": [ "Keypad" ],
|
||||
|
58
src/main.go
58
src/main.go
@ -41,10 +41,26 @@ func setup(client *streamdeck.Client) {
|
||||
action.RegisterHandler(streamdeck.KeyDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
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
|
||||
})
|
||||
|
||||
@ -52,7 +68,16 @@ func setup(client *streamdeck.Client) {
|
||||
log.Println("Will Appear")
|
||||
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
|
||||
})
|
||||
|
||||
@ -72,18 +97,15 @@ func setup(client *streamdeck.Client) {
|
||||
ctx := context.Background()
|
||||
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 {
|
||||
/*
|
||||
if on, turn off
|
||||
if off, turn on
|
||||
if broken, turn off
|
||||
*/
|
||||
activeDevice, err := networking.GetActiveDevice()
|
||||
|
||||
if err != nil {
|
||||
@ -102,30 +124,24 @@ func toggleVpn() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getState() int {
|
||||
/*
|
||||
0 for proxy off
|
||||
1 for proxy on
|
||||
2 for no network
|
||||
3 for busted
|
||||
*/
|
||||
func getState() (string, string) {
|
||||
activeDevice, err := networking.GetActiveDevice()
|
||||
|
||||
if err != nil {
|
||||
return 3
|
||||
return "images/error.png", "Error"
|
||||
}
|
||||
|
||||
if activeDevice == "" {
|
||||
return 2
|
||||
return "images/noNetwork.png", "No Network"
|
||||
}
|
||||
|
||||
proxyEnabled, err := networking.IsProxyEnabled(activeDevice)
|
||||
|
||||
if err != nil {
|
||||
return 3
|
||||
return "images/error.png", "Error"
|
||||
}
|
||||
if proxyEnabled {
|
||||
return 1
|
||||
return "images/proxyEnabled.png", "Enabled"
|
||||
}
|
||||
return 0
|
||||
return "images/proxyDisabled.png", "Disabled"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user