feature: Stream Deck plugin (#9)

This commit is contained in:
iGoX 2024-12-27 10:39:23 +01:00
parent 42957a9a70
commit 77659b6b97
24 changed files with 2834 additions and 1 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
.DS_Store .DS_Store
**/Bruno/ **/Bruno/
**/logs/

View file

@ -0,0 +1,6 @@
# Node.js
node_modules/
# Stream Deck files
*.sdPlugin/bin
*.sdPlugin/logs

View file

@ -0,0 +1,20 @@
{
// 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 Plugin",
"type": "node",
"request": "attach",
"processId": "${command:PickProcess}",
"outFiles": [
"${workspaceFolder}/bin/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**"
]
}
]
}

View file

@ -0,0 +1,17 @@
{
/* JSON schemas */
"json.schemas": [
{
"fileMatch": [
"**/manifest.json"
],
"url": "https://schemas.elgato.com/streamdeck/plugins/manifest.json"
},
{
"fileMatch": [
"**/layouts/*.json"
],
"url": "https://schemas.elgato.com/streamdeck/plugins/layout.json"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View file

@ -0,0 +1,113 @@
{
"Name": "iGoX BusyLight",
"Version": "0.1.0.0",
"Author": "iGoX",
"$schema": "https://schemas.elgato.com/streamdeck/plugins/manifest.json",
"Actions": [
{
"Name": "Set status as 'Available'",
"UUID": "org.igox.busylight.status.available",
"Icon": "imgs/actions/status/available/icon",
"Tooltip": "Set status as 'Available'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/available/icon",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Away'",
"UUID": "org.igox.busylight.status.away",
"Icon": "imgs/actions/status/away/icon",
"Tooltip": "Set status as 'Away'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/away/icon",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set status as 'Busy'",
"UUID": "org.igox.busylight.status.busy",
"Icon": "imgs/actions/status/busy/icon",
"Tooltip": "Set status as 'Busy'",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/busy/icon",
"TitleAlignment": "bottom"
}
]
}
,
{
"Name": "Turn off the BusyLight",
"UUID": "org.igox.busylight.status.off",
"Icon": "imgs/actions/status/off/icon",
"Tooltip": "Turn off the BusyLight",
"PropertyInspectorPath": "ui/status-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/status/off/icon",
"TitleAlignment": "bottom"
}
]
},
{
"Name": "Set brightness",
"UUID": "org.igox.busylight.brigthness.set",
"Icon": "imgs/actions/brightness/icon",
"Tooltip": "Set brightness",
"PropertyInspectorPath": "ui/brightness-config.html",
"Controllers": [
"Keypad"
],
"States": [
{
"Image": "imgs/actions/brightness/icon",
"TitleAlignment": "bottom"
}
]
}
],
"Category": "BusyLight",
"CategoryIcon": "imgs/plugin/marketplace",
"CodePath": "bin/plugin.js",
"Description": "Control your DIY BusyLight (https://github.com/igox/busylight) from your Stream Deck",
"Icon": "imgs/plugin/marketplace",
"SDKVersion": 2,
"Software": {
"MinimumVersion": "6.4"
},
"OS": [
{
"Platform": "mac",
"MinimumVersion": "10.15"
},
{
"Platform": "windows",
"MinimumVersion": "10"
}
],
"Nodejs": {
"Version": "20",
"Debug": "enabled"
},
"UUID": "org.igox.busylight"
}

View file

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head lang="en">
<title>Configure your BusyLight</title>
<meta charset="utf-8" />
<script src="https://sdpi-components.dev/releases/v3/sdpi-components.js"></script>
<script>
function getGlobalSettings() {
const { streamDeckClient } = SDPIComponents;
const settings = streamDeckClient.getGlobalSettings();
return settings.url || 'http://busylight-esp32.local';
}
</script>
</head>
<body>
<script>
</script>
<!--
Learn more about property inspector components at https://sdpi-components.dev/docs/components
-->
<sdpi-item label="URL or IP">
<sdpi-textfield
setting="url"
placeholder="http://busylight-esp32.local"
global="true"
value="getGlobalSettings()">
</sdpi-textfield>
</sdpi-item>
<sdpi-item label="Brightness">
<sdpi-range
setting="brightness"
min="10"
max="100"
default="40"
value="40"
step="5"
showlabels="true">
<span slot="min">10%</span>
<span slot="max">100%</span>
</sdpi-range>
</sdpi-item>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head lang="en">
<title>Configure your BusyLight</title>
<meta charset="utf-8" />
<script src="https://sdpi-components.dev/releases/v3/sdpi-components.js"></script>
<script>
function getGlobalSettings() {
const { streamDeckClient } = SDPIComponents;
const settings = streamDeckClient.getGlobalSettings();
return settings.url || 'http://busylight-esp32.local';
}
</script>
</head>
<body>
<script>
</script>
<!--
Learn more about property inspector components at https://sdpi-components.dev/docs/components
-->
<sdpi-item label="URL or IP">
<sdpi-textfield
setting="url"
placeholder="http://busylight-esp32.local"
global="true"
value="getGlobalSettings()">
</sdpi-textfield>
</sdpi-item>
</body>
</html>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,22 @@
{
"scripts": {
"build": "rollup -c",
"watch": "rollup -c -w --watch.onEnd=\"streamdeck restart org.igox.busylight\""
},
"type": "module",
"devDependencies": {
"@elgato/cli": "^1.1.0",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.2.2",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@tsconfig/node20": "^20.1.2",
"@types/node": "~20.15.0",
"rollup": "^4.0.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},
"dependencies": {
"@elgato/streamdeck": "^1.0.0"
}
}

View file

@ -0,0 +1,49 @@
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import path from "node:path";
import url from "node:url";
const isWatching = !!process.env.ROLLUP_WATCH;
const sdPlugin = "org.igox.busylight.sdPlugin";
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: "src/plugin.ts",
output: {
file: `${sdPlugin}/bin/plugin.js`,
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
}
},
plugins: [
{
name: "watch-externals",
buildStart: function () {
this.addWatchFile(`${sdPlugin}/manifest.json`);
},
},
typescript({
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve({
browser: false,
exportConditions: ["node"],
preferBuiltins: true
}),
commonjs(),
!isWatching && terser(),
{
name: "emit-module-package-file",
generateBundle() {
this.emitFile({ fileName: "package.json", source: `{ "type": "module" }`, type: "asset" });
}
}
]
};
export default config;

View file

@ -0,0 +1,52 @@
import streamDeck, { action, DidReceiveSettingsEvent, WillAppearEvent, KeyDownEvent, SingletonAction } from "@elgato/streamdeck";
@action({ UUID: "org.igox.busylight.brigthness.set" })
export class SetBrightness extends SingletonAction<BrightnessSettings> {
override async onKeyDown(ev: KeyDownEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.trace(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
settings.brightness ??= 40;
setBrightness(settings.brightness);
}
override onWillAppear(ev: WillAppearEvent<BrightnessSettings>): void | Promise<void> {
streamDeck.logger.trace(`>>> Received WillAppearEvent. Settings: ${JSON.stringify(ev.payload.set)} <<<`);
return ev.action.setTitle(`${ev.payload.settings.brightness ?? 40}%`);
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.trace(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
await ev.action.setSettings(settings);
await ev.action.setTitle(`${settings.brightness} %`);
}
}
async function setBrightness(brightness: number) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.trace(`>>> Sending brightness: ${brightness} to ${url} <<<`);
fetch(`${url}/api/brightness`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"brightness": brightness/100})
})
.then(response => response.json())
.then(data => streamDeck.logger.trace(data));
}
type BrightnessSettings = {
brightness?: number;
};

View file

@ -0,0 +1,46 @@
import streamDeck, { action, KeyDownEvent, SingletonAction } from "@elgato/streamdeck";
@action({ UUID: "org.igox.busylight.status.available" })
export class SetStatusAvailable extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent): Promise<void> {
setStatus('available');
}
}
@action({ UUID: "org.igox.busylight.status.busy" })
export class SetStatusBusy extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent): Promise<void> {
setStatus('busy');
}
}
@action({ UUID: "org.igox.busylight.status.away" })
export class SetStatusAway extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent): Promise<void> {
setStatus('away');
}
}
@action({ UUID: "org.igox.busylight.status.off" })
export class SetStatusOff extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent): Promise<void> {
setStatus('off');
}
}
async function setStatus(status: string) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.trace(`>>> Sending status: ${status} to ${url} <<<`);
fetch(`${url}/api/status/${status}`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => streamDeck.logger.trace(data));
}

View file

@ -0,0 +1,18 @@
import streamDeck, { LogLevel, SingletonAction, action, type DidReceiveSettingsEvent } from "@elgato/streamdeck";
//import { IncrementCounter } from "./actions/increment-counter";
import { SetStatusAvailable, SetStatusBusy, SetStatusAway, SetStatusOff } from "./actions/set-status";
import { SetBrightness } from "./actions/set-brightness";
// We can enable "trace" logging so that all messages between the Stream Deck, and the plugin are recorded. When storing sensitive information
streamDeck.logger.setLevel(LogLevel.INFO);
// Register the actions.
streamDeck.actions.registerAction(new SetStatusAvailable());
streamDeck.actions.registerAction(new SetStatusBusy());
streamDeck.actions.registerAction(new SetStatusAway());
streamDeck.actions.registerAction(new SetStatusOff());
streamDeck.actions.registerAction(new SetBrightness());
// Finally, connect to the Stream Deck.
streamDeck.connect();

View file

@ -0,0 +1,17 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"customConditions": [
"node"
],
"module": "ES2022",
"moduleResolution": "Bundler",
"noImplicitOverride": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}