Skip to content

Commit

Permalink
Merge pull request #8 from rasitayaz/dev
Browse files Browse the repository at this point in the history
fix qam reload and listener issues
  • Loading branch information
rasitayaz authored Jun 20, 2024
2 parents 5305b48 + f1f54f4 commit 3bc1854
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.2

- Fixed bar stops working after entering and leaving the game controller settings page.
- Fixed reload button in quick access menu.

## 1.0.1

- Fixed bar showing up when brightness automatically changes just when QAM or Steam button is pressed.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "decky-brightness-bar",
"version": "1.0.1",
"version": "1.0.2",
"description": "A plugin for Decky that displays a brightness bar when the brightness is changed.",
"scripts": {
"build": "shx rm -rf dist && rollup -c",
Expand Down
61 changes: 47 additions & 14 deletions src/lib/components/brightness_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const UICompositionProxy: VFC = () => {
};

let triggeredAt = 0;
let qamOrSteamPressedAt = 0;
let controllingBrightness = false;
let brightnessLock = false;

Expand Down Expand Up @@ -79,35 +80,67 @@ export const BrightnessBar: VFC = () => {
};
}, []);

useEffect(() => {}, []);

useEffect(() => {
const registration =
window.SteamClient.Input.RegisterForControllerStateChanges(
(changes: any[]) => {
for (const inputs of changes) {
const qamOrSteamPressed =
isPressed(ULUpperButtons.QAM, inputs.ulUpperButtons) ||
isPressed(ULButtons.Steam, inputs.ulButtons);
const controllerStateListener = (changes: any[]) => {
for (const inputs of changes) {
const qamOrSteamPressed =
isPressed(ULUpperButtons.QAM, inputs.ulUpperButtons) ||
isPressed(ULButtons.Steam, inputs.ulButtons);

if (qamOrSteamPressed) qamOrSteamPressedAt = Date.now();

const threshold = 10000;
const threshold = 10000;

const up = inputs.sLeftStickY > threshold;
const down = inputs.sLeftStickY < -threshold;

controllingBrightness = qamOrSteamPressed && (up || down);
}
};

const up = inputs.sLeftStickY > threshold;
const down = inputs.sLeftStickY < -threshold;
let controllerStateRegistration =
window.SteamClient.Input.RegisterForControllerStateChanges(
controllerStateListener
);

controllingBrightness = qamOrSteamPressed && (up || down);
const controllerCommandRegistration =
window.SteamClient.Input.RegisterForControllerCommandMessages(
(message: any) => {
if (
message.eAction !== 53 ||
Date.now() - qamOrSteamPressedAt < 1000
) {
return;
}

qamOrSteamPressedAt = Date.now();

/**
* QAM or Steam button was pressed, but controller state listener did not detect it.
* We need to re-register the controller state listener.
*/

controllerStateRegistration.unregister();
controllerStateRegistration =
window.SteamClient.Input.RegisterForControllerStateChanges(
controllerStateListener
);
}
);

return () => {
registration.unregister();
controllerStateRegistration.unregister();
controllerCommandRegistration.unregister();
};
}, []);

const [brightnessPercentage, setBrightnessPercentage] = useState(0);
const [visible, setVisible] = useState(false);

useEffect(() => {
const registration =
const brightnessRegistration =
window.SteamClient.System.Display.RegisterForBrightnessChanges(
async (data: { flBrightness: number }) => {
triggeredAt = Date.now();
Expand All @@ -134,7 +167,7 @@ export const BrightnessBar: VFC = () => {
);

return () => {
registration.unregister();
brightnessRegistration.unregister();
};
}, []);

Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/qam_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export const QAMContent: VFC = () => {
<PanelSectionRow>
<ButtonItem
bottomSeparator="none"
onClick={() => {
onClick={async () => {
serverAPI.routerHook.removeGlobalComponent("BrightnessBar");
await new Promise((resolve) => setTimeout(resolve, 1000));
serverAPI.routerHook.addGlobalComponent(
"BrightnessBar",
BrightnessBar
Expand Down

0 comments on commit 3bc1854

Please sign in to comment.