Initial commit
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# ---> Go
|
||||
# If you prefer the allow list template instead of the deny list, see community template:
|
||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||
#
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 dlprows
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Stream Deck Go Plugin
|
||||
|
||||
|
||||
find everywhere with {{{NAME}}} and replace it with appropriate values
|
||||
do the manifest
|
||||
write code
|
15
src/.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": "${command:pickGoProcess}"
|
||||
}
|
||||
]
|
||||
}
|
BIN
src/DistributionTool
Executable file
45
src/Makefile
Normal file
@ -0,0 +1,45 @@
|
||||
INSTALLDIR = ~/Library/Application\ Support/com.elgato.StreamDeck/Plugins/com.dlprows.{{{NAME}}}.sdPlugin
|
||||
#BUILDDIR = build
|
||||
#RELEASEDIR = release
|
||||
#SDPLUGINDIR = "./com.dlprows.{{{NAME}}}.sdPlugin"
|
||||
|
||||
update:
|
||||
killall Stream\ Deck || true
|
||||
go build -o $(INSTALLDIR) .
|
||||
open -a Elgato\ Stream\ Deck
|
||||
|
||||
build:
|
||||
go build -o com.dlprows.{{{NAME}}}.sdPlugin
|
||||
rm com.dlprows.{{{NAME}}}.streamDeckPlugin
|
||||
./DistributionTool -b -i com.dlprows.{{{NAME}}}.sdPlugin -o .
|
||||
|
||||
|
||||
#.PHONY: test install build logs
|
||||
|
||||
#build:
|
||||
#$(GO) build $(GOFLAGS)
|
||||
|
||||
#test:
|
||||
#$(GO) run $(GOFLAGS) main.go -port 12345 -pluginUUID 213 -registerEvent test -info "{\"application\":{\"language\":\"en\",\"platform\":\"windows\",\"version\":\"10\"},\"plugin\":{\"version\":\"1.1\"},\"devicePixelRatio\":2,\"devices\":[{\"id\":\"55F16B35884A859CCE4FFA1FC8D3DE5B\",\"name\":\"Device Name\",\"size\":{\"columns\":5,\"rows\":3},\"type\":0},{\"id\":\"B8F04425B95855CF417199BCB97CD2BB\",\"name\":\"Another Device\",\"size\":{\"columns\":3,\"rows\":2},\"type\":1}]}"
|
||||
#
|
||||
#sdplugin: build
|
||||
#rm -rf $(SDPLUGINDIR)
|
||||
#mkdir -p $(SDPLUGINDIR)
|
||||
#cp *.json $(SDPLUGINDIR)
|
||||
#cp *.exe $(SDPLUGINDIR)
|
||||
#cp *.html $(SDPLUGINDIR)
|
||||
#cp -r images $(SDPLUGINDIR)
|
||||
#
|
||||
#install: uninstall sdplugin
|
||||
#mv $(SDPLUGINDIR) $(INSTALLDIR)
|
||||
#
|
||||
#uninstall:
|
||||
#rm -rf $(INSTALLDIR)
|
||||
#
|
||||
#logs:
|
||||
#tail -f "$(TMP)"/$(MAKEFILEDIR).log*
|
||||
#
|
||||
#release: sdplugin
|
||||
#rm -rf $(RELEASEDIR)
|
||||
#mkdir $(RELEASEDIR)
|
||||
#DistributionTool -b -i $(SDPLUGINDIR) -o $(RELEASEDIR)
|
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/actionIcon.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/actionIcon@2x.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/categoryIcon.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/categoryIcon@2x.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/download (12).png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/icon.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/icon@2x.png
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/pluginAction.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/pluginAction@2x.png
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/pluginIcon.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
src/com.dlprows.{{{NAME}}}.sdPlugin/images/pluginIcon@2x.png
Normal file
After Width: | Height: | Size: 36 KiB |
49
src/com.dlprows.{{{NAME}}}.sdPlugin/manifest.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"Actions": [
|
||||
{
|
||||
"UUID": "com.dlprows.{{{NAME}}}.dialaction",
|
||||
"Name": "Volume",
|
||||
"Tooltip": "Control system volume",
|
||||
"Icon": "Images/icon",
|
||||
"States": [
|
||||
{
|
||||
"Image": "Images/pluginAction",
|
||||
"TitleAlignment": "middle",
|
||||
"FontSize": "12"
|
||||
}
|
||||
],
|
||||
"Controllers": [ "Encoder" ],
|
||||
"Encoder": {
|
||||
"background": "backgroundImage",
|
||||
"Icon": "Images/actionIcon",
|
||||
"layout": "$B1",
|
||||
"StackColor": "#AABBCC",
|
||||
"TriggerDescription": {
|
||||
"Rotate": "System Volume",
|
||||
"Push": "Mute",
|
||||
"Touch": "Mute"
|
||||
}
|
||||
},
|
||||
"SupportedInMultiActions": false
|
||||
}
|
||||
],
|
||||
"Author": "dlprows",
|
||||
"Name": "{{{NAME}}}",
|
||||
"Description": "Control volume on mac",
|
||||
"URL": "https://encyclopediaofdaniel.com",
|
||||
"Version": "1.0",
|
||||
"CodePath": "{{{NAME}}}",
|
||||
"Category": "Volume Control [dlprows]",
|
||||
"Icon": "Images/pluginIcon",
|
||||
"CategoryIcon": "Images/categoryIcon",
|
||||
"OS": [
|
||||
{
|
||||
"Platform": "mac",
|
||||
"MinimumVersion": "13.0"
|
||||
}
|
||||
],
|
||||
"SDKVersion": 2,
|
||||
"Software": {
|
||||
"MinimumVersion": "6.0"
|
||||
}
|
||||
}
|
7
src/go.mod
Normal file
@ -0,0 +1,7 @@
|
||||
module macvolumecontrol
|
||||
|
||||
go 1.20
|
||||
|
||||
require code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk v1.0.1
|
||||
|
||||
require github.com/gorilla/websocket v1.5.0 // indirect
|
6
src/go.sum
Normal file
@ -0,0 +1,6 @@
|
||||
code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk v1.0.1 h1:2IoDJrWt6Bp5IcXTtqjdygDo3Ruh5VHsS9R5MjI2WWQ=
|
||||
code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk v1.0.1/go.mod h1:SaMt3PIkPtNwkgrcLpD89GK/7tLaUkcEvOZaHUC66+4=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/samwho/streamdeck v0.0.0-20190725183037-2b866fdcb4a6 h1:ocHB+wIjLCdideequ8l8dUem6DxHf/A4Mmo0TRxBf1U=
|
||||
github.com/samwho/streamdeck v0.0.0-20190725183037-2b866fdcb4a6/go.mod h1:OjeKL1Q8xRGm1zHGmtu9JeQUFNOXXXIcSZvCNzRP3GM=
|
32
src/logging/logging.go
Normal file
@ -0,0 +1,32 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk"
|
||||
)
|
||||
|
||||
func directory() string {
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Fatalf("error getting directory: %v", err)
|
||||
}
|
||||
return filepath.Base(filepath.Dir(ex))
|
||||
}
|
||||
|
||||
// Enable turns logging on for the StreamDeck API client as well as the global
|
||||
// log object. It sends both to a temp file that contains <project_directory>.log.
|
||||
func Enable() {
|
||||
os.Mkdir("./logs/", 0775)
|
||||
d := directory()
|
||||
f, err := os.CreateTemp("./logs/", fmt.Sprintf("%s.log", d))
|
||||
if err != nil {
|
||||
log.Fatalf("error creating temp file: %v", err)
|
||||
}
|
||||
streamdeck.Log().SetOutput(f)
|
||||
log.SetPrefix(fmt.Sprintf("%s ", d))
|
||||
log.SetOutput(f)
|
||||
}
|
173
src/main.go
Normal file
@ -0,0 +1,173 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"macvolumecontrol/logging"
|
||||
"macvolumecontrol/volume"
|
||||
|
||||
"code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk"
|
||||
sdcontext "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk/context"
|
||||
)
|
||||
|
||||
var _currentSettings *volume.VolumeSettings = &volume.VolumeSettings{}
|
||||
|
||||
func main() {
|
||||
logging.Enable()
|
||||
log.Println("Starting plugin")
|
||||
|
||||
params, err := streamdeck.ParseRegistrationParams(os.Args)
|
||||
if err != nil {
|
||||
log.Fatalf("error parsing registration params: %v", err)
|
||||
}
|
||||
|
||||
sd := streamdeck.NewClient(context.Background(), params)
|
||||
defer sd.Close()
|
||||
|
||||
setup(sd)
|
||||
|
||||
if err := sd.Run(); err != nil {
|
||||
log.Fatalf("error running streamdeck client: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func setup(client *streamdeck.Client) {
|
||||
log.Println("Registering actions")
|
||||
action := client.Action("com.dlprows.macvolumecontrol.dialaction")
|
||||
|
||||
contexts := make(map[string]struct{})
|
||||
|
||||
action.RegisterHandler(streamdeck.DialRotate, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
log.Println("dial rotate")
|
||||
|
||||
p := streamdeck.DialRotatePayload[any]{}
|
||||
|
||||
if err := json.Unmarshal(event.Payload, &p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//volume.ChangeVolumeWithKeyboard(p.Ticks)
|
||||
newSettings, err := volume.ChangeVolume(p.Ticks)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return setFeedbackIfNeeded(ctx, client, newSettings)
|
||||
})
|
||||
|
||||
action.RegisterHandler(streamdeck.DialDown, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
log.Println("dial down")
|
||||
|
||||
newSettings, err := volume.ToggleMute()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return setFeedbackIfNeeded(ctx, client, newSettings)
|
||||
})
|
||||
|
||||
action.RegisterHandler(streamdeck.TouchTap, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
log.Println("touch tap")
|
||||
|
||||
newSettings, err := volume.ToggleMute()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return setFeedbackIfNeeded(ctx, client, newSettings)
|
||||
})
|
||||
|
||||
action.RegisterHandler(streamdeck.WillAppear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
log.Println("Will Appear")
|
||||
contexts[event.Context] = struct{}{}
|
||||
|
||||
newSettings, err := volume.GetVolumeSettings()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return setFeedback(ctx, client, newSettings)
|
||||
})
|
||||
|
||||
action.RegisterHandler(streamdeck.WillDisappear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
log.Println("Will Disappear")
|
||||
delete(contexts, event.Context)
|
||||
return nil
|
||||
})
|
||||
|
||||
//start background thread to keep the display up to date if changed outside the stream deck
|
||||
go func() {
|
||||
for range time.Tick(time.Second * 1) {
|
||||
newSettings, err := volume.GetVolumeSettings()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for ctxStr := range contexts {
|
||||
//for each context
|
||||
//build a new context that can be used to perform outbound requests
|
||||
ctx := context.Background()
|
||||
ctx = sdcontext.WithContext(ctx, ctxStr)
|
||||
|
||||
setFeedback(ctx, client, newSettings)
|
||||
}
|
||||
_currentSettings = newSettings
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func setFeedback(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error {
|
||||
|
||||
payload := FeedbackPayload{}
|
||||
|
||||
opacity := 1.0
|
||||
|
||||
if newSettings.OutputMuted {
|
||||
opacity = 0.5
|
||||
}
|
||||
|
||||
payload.Value = ValueWithOpacity[string]{
|
||||
fmt.Sprintf("%d%%", newSettings.OutputVolume),
|
||||
opacity,
|
||||
}
|
||||
|
||||
payload.Indicator = ValueWithOpacity[int]{
|
||||
newSettings.OutputVolume,
|
||||
opacity,
|
||||
}
|
||||
|
||||
payload.Icon = ValueWithOpacity[any]{nil, opacity}
|
||||
|
||||
return client.SetFeedback(ctx, payload)
|
||||
}
|
||||
|
||||
func setFeedbackIfNeeded(ctx context.Context, client *streamdeck.Client, newSettings *volume.VolumeSettings) error {
|
||||
|
||||
if _currentSettings.OutputVolume == newSettings.OutputVolume && _currentSettings.OutputMuted == newSettings.OutputMuted {
|
||||
return nil
|
||||
}
|
||||
|
||||
_currentSettings = newSettings
|
||||
return setFeedback(ctx, client, newSettings)
|
||||
}
|
||||
|
||||
type FeedbackPayload struct {
|
||||
Value ValueWithOpacity[string] `json:"value"`
|
||||
Indicator ValueWithOpacity[int] `json:"indicator"`
|
||||
Icon ValueWithOpacity[any] `json:"icon"`
|
||||
}
|
||||
|
||||
type ValueWithOpacity[T any] struct {
|
||||
Value T `json:"value,omitempty"`
|
||||
Opacity float64 `json:"opacity"`
|
||||
}
|