From a2d73b585f5a0888c04365c623b36cdc2428a73f Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Thu, 16 Jan 2025 13:27:42 +1100
Subject: requests: brightness syntax change

Same as wpctl
---
 app.tsx | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

(limited to 'app.tsx')

diff --git a/app.tsx b/app.tsx
index ee2c549..287361f 100644
--- a/app.tsx
+++ b/app.tsx
@@ -35,9 +35,14 @@ App.start({
         else if (request === "media next") Players.get_default().lastPlayer?.next();
         else if (request === "media previous") Players.get_default().lastPlayer?.previous();
         else if (request === "media stop") Players.get_default().lastPlayer?.stop();
-        else if (request === "brightness up") Monitors.get_default().active.brightness += 0.1;
-        else if (request === "brightness down") Monitors.get_default().active.brightness -= 0.1;
-        else return res("Unknown command: " + request);
+        else if (request.startsWith("brightness")) {
+            const value = request.split(" ")[1];
+            const num = parseFloat(value) / (value.includes("%") ? 100 : 1);
+            if (isNaN(num)) return res("Syntax: brightness <value>[%][+ | -]");
+            if (value.includes("+")) Monitors.get_default().active.brightness += num;
+            else if (value.includes("-")) Monitors.get_default().active.brightness -= num;
+            else Monitors.get_default().active.brightness = num;
+        } else return res("Unknown command: " + request);
 
         console.log(`Request handled: ${request}`);
         res("OK");
-- 
cgit v1.2.3-freya

