Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically delete 'stale'/old widgets from database #2702

Merged
merged 1 commit into from Jul 29, 2022

Conversation

jpelgrom
Copy link
Member

Summary

Automatically deletes widgets from the database that are no longer bound to the widget provider but that are still in the database when asked to update all widgets. This will remove unnecessary updates (and websocket connections!) due to 'stale'/old widgets that aren't exposed to the user. The PR also removes the "Delete widget" button on the widget configuration screen as it is no longer required.

No issue to link here, but "remove unused widgets from Settings > Companion app > Manage Widgets" has been a 'solution' for multiple issues in the past.

Screenshots

The "Delete widget" button has been removed when updating a widget:

Light Dark
Settings for a template widget, with the only button being 'Update Widget' and no longer also including 'Delete Widget', light mode Settings for a template widget, with the only button being 'Update Widget' and no longer also including 'Delete Widget', dark mode

Link to pull request in Documentation repository

n/a, the documentation didn't mention the delete functionality

Any other notes

Testing to make sure widgets aren't accidentally deleted: I've been running this code for a few hours now and tried several things to imitate running it for a longer period of time (manually triggering doze, killing the launcher, rebooting a few times).

 - Automatically removes widgets that are no longer bound to the widget provider but that are still in the database -> 'stale'/old widgets will no longer cause unnecessary updates
@dshokouhi
Copy link
Member

This is awesome, I believe the only time we have seen widgets get removed from the home screen but still exist in the database when we refactored widgets. So if you test by renaming any widget folder you should be able to reproduce that :) (Assuming you haven't already done that test lol)

@jpelgrom
Copy link
Member Author

I hadn't tested that scenario! Can confirm that when you rename the class or package Android removes the widgets but doesn't notify the app. On the next screen on intent when all widgets are updated this is correctly detected and the widgets are removed from the database 👍

@JBassett JBassett merged commit 1cf3506 into home-assistant:master Jul 29, 2022
@jpelgrom jpelgrom deleted the auto-remove-widgets branch July 29, 2022 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants