Updated examples, added property inspector example to one
This commit is contained in:
parent
f3f3f4034c
commit
503477a3c3
@ -1,7 +1,6 @@
|
||||
GO = go
|
||||
GOFLAGS =
|
||||
INSTALLDIR = "$(APPDATA)\Elgato\StreamDeck\Plugins\dev.samwho.streamdeck.counter.sdPlugin"
|
||||
LOGDIR = "$(APPDATA)\Elgato\StreamDeck\logs"
|
||||
|
||||
.PHONY: test install build logs
|
||||
|
||||
@ -18,4 +17,4 @@ install: build
|
||||
cp *.exe $(INSTALLDIR)
|
||||
|
||||
logs:
|
||||
tail -f $(LOGDIR)/counter.log
|
||||
tail -f "$(TMP)"/streamdeck-counter.log*
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -13,20 +14,17 @@ import (
|
||||
"github.com/samwho/streamdeck"
|
||||
)
|
||||
|
||||
const (
|
||||
logFile = "C:\\Users\\samwh\\AppData\\Roaming\\Elgato\\StreamDeck\\logs\\streamdeck-livesplit.log"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
Counter int `json:"counter"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
f, err := ioutil.TempFile("", "streamdeck-counter.log")
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
log.Fatalf("error creating temp file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
log.SetOutput(f)
|
||||
|
||||
ctx := context.Background()
|
||||
@ -42,12 +40,12 @@ func run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
client := streamdeck.NewClient(ctx, params)
|
||||
setupCounter(client)
|
||||
setup(client)
|
||||
|
||||
return client.Run()
|
||||
}
|
||||
|
||||
func setupCounter(client *streamdeck.Client) {
|
||||
func setup(client *streamdeck.Client) {
|
||||
action := client.Action("dev.samwho.streamdeck.counter")
|
||||
settings := make(map[string]*Settings)
|
||||
|
||||
@ -101,9 +99,9 @@ func setupCounter(client *streamdeck.Client) {
|
||||
}
|
||||
|
||||
func background() image.Image {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||
for x := 0; x < 20; x++ {
|
||||
for y := 0; y < 20; y++ {
|
||||
img := image.NewRGBA(image.Rect(0, 0, 72, 72))
|
||||
for x := 0; x < 72; x++ {
|
||||
for y := 0; y < 72; y++ {
|
||||
img.Set(x, y, color.Black)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
GO = go
|
||||
GOFLAGS =
|
||||
INSTALLDIR = "$(APPDATA)\Elgato\StreamDeck\Plugins\dev.samwho.streamdeck.cpu.sdPlugin"
|
||||
LOGDIR = "$(APPDATA)\Elgato\StreamDeck\logs"
|
||||
|
||||
.PHONY: test install build logs
|
||||
|
||||
@ -15,7 +14,9 @@ install: build
|
||||
rm -rf $(INSTALLDIR)
|
||||
mkdir $(INSTALLDIR)
|
||||
cp *.json $(INSTALLDIR)
|
||||
cp *.html $(INSTALLDIR)
|
||||
cp *.css $(INSTALLDIR)
|
||||
cp *.exe $(INSTALLDIR)
|
||||
|
||||
logs:
|
||||
tail -f $(LOGDIR)/cpu.log
|
||||
tail -f "$(TMP)"/streamdeck-cpu.log*
|
47
examples/cpu/cpu_property_inspector.html
Normal file
47
examples/cpu/cpu_property_inspector.html
Normal file
@ -0,0 +1,47 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>CPU graph</title>
|
||||
<link rel="stylesheet" href="sdpi.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="sdpi-wrapper">
|
||||
<div type="checkbox" class="sdpi-item">
|
||||
<div class="sdpi-item-label">Show text</div>
|
||||
<div class="sdpi-item-child">
|
||||
<input id="showText" type="checkbox" value="yes" onchange="sendToPlugin({ showText: document.getElementById('showText').checked })">
|
||||
<label for="showText" class="sdpi-item-label"><span></span></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var websocket = null,
|
||||
uuid = null,
|
||||
actionInfo = {};
|
||||
|
||||
function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo, inActionInfo) {
|
||||
uuid = inUUID;
|
||||
actionInfo = JSON.parse(inActionInfo); // cache the info
|
||||
websocket = new WebSocket('ws://localhost:' + inPort);
|
||||
|
||||
websocket.onopen = function () {
|
||||
websocket.send(JSON.stringify({
|
||||
event: inRegisterEvent,
|
||||
uuid: inUUID
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
function sendToPlugin(obj) {
|
||||
if (websocket) {
|
||||
websocket.send(JSON.stringify({
|
||||
"action": actionInfo['action'],
|
||||
"event": "sendToPlugin",
|
||||
"context": uuid,
|
||||
"payload": obj,
|
||||
}));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
@ -15,16 +17,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
logFile = "C:\\Users\\samwh\\AppData\\Roaming\\Elgato\\StreamDeck\\logs\\cpu.log"
|
||||
|
||||
imgX = 72
|
||||
imgY = 72
|
||||
)
|
||||
|
||||
type PropertyInspectorSettings struct {
|
||||
ShowText bool `json:"showText,omitempty"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
f, err := ioutil.TempFile("", "streamdeck-cpu.log")
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
log.Fatalf("error creating tempfile: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
@ -50,8 +54,13 @@ func run(ctx context.Context) error {
|
||||
func setup(client *streamdeck.Client) {
|
||||
action := client.Action("dev.samwho.streamdeck.cpu")
|
||||
|
||||
pi := &PropertyInspectorSettings{}
|
||||
contexts := make(map[string]struct{})
|
||||
|
||||
action.RegisterHandler(streamdeck.SendToPlugin, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
return json.Unmarshal(event.Payload, pi)
|
||||
})
|
||||
|
||||
action.RegisterHandler(streamdeck.WillAppear, func(ctx context.Context, client *streamdeck.Client, event streamdeck.Event) error {
|
||||
contexts[event.Context] = struct{}{}
|
||||
return nil
|
||||
@ -65,7 +74,7 @@ func setup(client *streamdeck.Client) {
|
||||
readings := make([]float64, imgX, imgX)
|
||||
|
||||
go func() {
|
||||
for range time.Tick(time.Second) {
|
||||
for range time.Tick(time.Second / 4) {
|
||||
for i := 0; i < imgX-1; i++ {
|
||||
readings[i] = readings[i+1]
|
||||
}
|
||||
@ -91,7 +100,12 @@ func setup(client *streamdeck.Client) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := client.SetTitle(ctx, fmt.Sprintf("CPU\n%d%%", int(r[0])), streamdeck.HardwareAndSoftware); err != nil {
|
||||
title := ""
|
||||
if pi.ShowText {
|
||||
title = fmt.Sprintf("CPU\n%d%%", int(r[0]))
|
||||
}
|
||||
|
||||
if err := client.SetTitle(ctx, title, streamdeck.HardwareAndSoftware); err != nil {
|
||||
log.Printf("error setting title: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
"FontSize": "14"
|
||||
}
|
||||
],
|
||||
"PropertyInspectorPath": "cpu_property_inspector.html",
|
||||
"SupportedInMultiActions": false,
|
||||
"Tooltip": "Show a pretty little CPU graph",
|
||||
"UUID": "dev.samwho.streamdeck.cpu"
|
||||
|
1575
examples/cpu/sdpi.css
Normal file
1575
examples/cpu/sdpi.css
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user