Skip to content

Conversation

@jfernandez
Copy link
Owner

This PR adds low-battery notifications to Controller Tools.

This is done via a new websocket API. The frontend will create a permanent ws connection to the backend when decky initializes the plugin. But if it gets disconnected, it will reconnect after 10 secs. When the client opens the ws connection, the backend will start a background thread that checks every 60s the status of controllers and then fires an alert if we have yet to send one in the last 60m. That background thread is killed if the ws connection is closed.

I've additionally added a new settings section in the UI to disable notifications, this is primarily to silence alerts if there is a bug. Settings are powered by the new SettingsService that uses a JSON file as its backing store. We store it in /home/deck/homebrew/settings/controller-tools.json if running on the deck, or /tmp/controller-tools.json for local dev.

Finally, I added a feature to inject a fake controller for testing while running in debug mode. You need to create a JSON equivalent of the Controller struct in /tmp/fake_controller.json (use camelCase for field names), and the api::controllers() will pick it up and inject it into the response Vec. I used this to verify alerts by adding a controller with low battery and in the discharging state.

image

image

closes #10

@jfernandez jfernandez requested a review from ludokx January 20, 2023 06:16
# Asyncio-compatible long-running code, executed in a task when the plugin is loaded
async def _main(self):
# startup
# startup with my_env
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is the only change, was anything else needed in main.py?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was attempting to derive the settings file path in main.py and pass them as env vars, but bailed out on that idea. I'll clean this comment that was left behind.

The good news is that there is a PR to add this logic: SteamDeckHomebrew/decky-loader#349

@jfernandez jfernandez merged commit 929f578 into main Jan 21, 2023
@jfernandez jfernandez deleted the ws branch January 21, 2023 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: notify/toast for connected controllers with low battery

3 participants