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

Fix widgets not disappearing when removed #3384

Merged
merged 2 commits into from
Jul 9, 2024
Merged

Conversation

krschau
Copy link
Collaborator

@krschau krschau commented Jul 9, 2024

Summary of the pull request

Fixes a bug where removing a widget did delete the underlying COM widget, but did not remove it from the list, resulting in the removed widget staying on the screen. This was caused by #3297 where the DashboardViewModel became a Transient service. As such, when the WidgetControl got a new DashboardViewModel, it didn't contain the "real" list of widgets". The fix is to change the DashboardViewModel to be Singleton again. We clear the list of PinnedWidgets when the DashboardView is unloaded, so we don't have to worry about adding the same widgets to the list multiple times if the Dashboard is nagivated to multiple times.

Validation steps performed

Validated locally.

PR checklist

@@ -177,7 +177,10 @@ private async void OnRemoveWidgetClick(object sender, RoutedEventArgs e)
_log.Debug($"User removed widget, delete widget {widgetIdToDelete}");
var stringResource = new StringResource("DevHome.Dashboard.pri", "DevHome.Dashboard/Resources");
Application.Current.GetService<IScreenReaderService>().Announce(stringResource.GetLocalized("WidgetRemoved"));
Application.Current.GetService<DashboardViewModel>().PinnedWidgets.Remove(widgetViewModel);
await Application.Current.GetService<DispatcherQueue>().EnqueueAsync(() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the DispatcherQueue only have an async enqueue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops, no. Will fix.

@krschau krschau force-pushed the user/krschau/remove-widget branch from a3507c2 to 77f9410 Compare July 9, 2024 19:46
@krschau krschau merged commit 440fe6a into main Jul 9, 2024
4 checks passed
@krschau krschau deleted the user/krschau/remove-widget branch July 9, 2024 21:39
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.

Dashboard not refreshing when removing widgets
5 participants