jfernandez / ControllerTools

Game controller plugin for the Steam Deck
GNU General Public License v3.0
49 stars 3 forks source link

Add low battery alerts using a websocket connection #14

Closed jfernandez closed 1 year ago

jfernandez commented 1 year ago

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