Checking-in code base

This commit is contained in:
2026-03-26 10:04:12 +01:00
parent be93d24eae
commit 74e1eecfea
42 changed files with 2902 additions and 2 deletions
+58
View File
@@ -0,0 +1,58 @@
import streamDeck, { action, DidReceiveSettingsEvent, WillAppearEvent, KeyDownEvent, PropertyInspectorDidAppearEvent, 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.debug(`>>> 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.debug(`>>> Received WillAppearEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
return ev.action.setTitle(`${ev.payload.settings.brightness ?? 40}%`);
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
await ev.action.setSettings(settings);
await ev.action.setTitle(`${settings.brightness}%`);
}
override async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<BrightnessSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received onPropertyInspectorDidAppear. Setting action icon <<<`);
await ev.action.setImage(`imgs/actions/buttons/brigthness/brigthness.png`);
}
}
async function setBrightness(brightness: number) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.debug(`>>> 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.debug(data));
}
type BrightnessSettings = {
brightness?: number;
};
+57
View File
@@ -0,0 +1,57 @@
import streamDeck, { action, JsonObject, KeyDownEvent, DidReceiveSettingsEvent, PropertyInspectorDidAppearEvent, SingletonAction } from "@elgato/streamdeck";
@action({ UUID: "org.igox.busylight.color.set" })
export class SetColor extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent<ColorSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received KeyDownEvent. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
settings.color ??= '#FFFFFF';
setColor(hexToRgb(settings.color));
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<ColorSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Received onDidReceiveSettings. Settings: ${JSON.stringify(ev.payload.settings)} <<<`);
const { settings } = ev.payload;
await ev.action.setSettings(settings);
}
override async onPropertyInspectorDidAppear(ev: PropertyInspectorDidAppearEvent<ColorSettings>): Promise<void> {
streamDeck.logger.debug(`>>> Color button property inspector diplayed! <<<`);
await ev.action.setImage(`imgs/actions/buttons/colored/colored.png`);
}
}
function hexToRgb(hex: string): { r: number, g: number, b: number } {
const hexNumber = parseInt(hex.replace('#', ''), 16);
const r = (hexNumber >> 16) & 255;
const g = (hexNumber >> 8) & 255;
const b = hexNumber & 255;
return { r, g, b };
}
async function setColor(color: JsonObject) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.debug(`>>> Sending color: ${JSON.stringify({"r": color.r, "g": color.g, "b": color.b})} to ${url} <<<`);
fetch(`${url}/api/color`,
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"r": color.r, "g": color.g, "b": color.b})
})
.then(response => response.json())
.then(data => streamDeck.logger.debug(data));
}
type ColorSettings = {
color?: string;
};
+40
View File
@@ -0,0 +1,40 @@
import streamDeck, { action, KeyDownEvent, SingletonAction, DidReceiveSettingsEvent } from "@elgato/streamdeck";
@action({ UUID: "org.igox.busylight.status.set" })
export class SetStatus extends SingletonAction {
override async onKeyDown(ev: KeyDownEvent<statusSettings>): Promise<void> {
const { settings } = ev.payload;
settings.status ??= 'available';
setStatus(settings.status);
}
override async onDidReceiveSettings(ev: DidReceiveSettingsEvent<statusSettings>): Promise<void> {
const { settings } = ev.payload;
let status = settings.status;
streamDeck.logger.debug(`>>> Config status changed to: ${status} <<<`);
await ev.action.setImage(`imgs/actions/buttons/${status}/${status}.png`);
}
}
async function setStatus(status: string) {
const settings = await streamDeck.settings.getGlobalSettings();
const url = settings.url;
streamDeck.logger.debug(`>>> 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.debug(data));
}
type statusSettings = {
status?: string;
};
+16
View File
@@ -0,0 +1,16 @@
import streamDeck, { LogLevel, SingletonAction, action, type DidReceiveSettingsEvent } from "@elgato/streamdeck";
import { SetStatus} from "./actions/set-status";
import { SetBrightness } from "./actions/set-brightness";
import { SetColor } from "./actions/set-color";
// 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 SetStatus());
streamDeck.actions.registerAction(new SetBrightness());
streamDeck.actions.registerAction(new SetColor());
// Finally, connect to the Stream Deck.
streamDeck.connect();