Skip to content

Commit

Permalink
Deactivate widgets when Dashboard isn't displayed (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored Feb 9, 2024
1 parent bdcb52f commit 3e22d5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,9 @@ private async void HandleWidgetUpdated(Widget sender, WidgetUpdatedEventArgs arg
Log.Logger()?.ReportDebug("WidgetViewModel", $"HandleWidgetUpdated for widget {sender.Id}");
await RenderWidgetFrameworkElementAsync();
}

public void UnsubscribeFromWidgetUpdates()
{
Widget.WidgetUpdated -= HandleWidgetUpdated;
}
}
12 changes: 12 additions & 0 deletions tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.Widgets;
using Microsoft.Windows.Widgets.Hosts;
using Windows.System;
Expand Down Expand Up @@ -589,6 +590,17 @@ private async void WidgetControl_Drop(object sender, DragEventArgs e)
Log.Logger()?.ReportDebug("DashboardView", $"Drop ended");
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
Log.Logger()?.ReportDebug("DashboardView", $"Leaving Dashboard, deactivating widgets.");

// Deactivate widgets if we're not on the Dashboard.
foreach (var widget in PinnedWidgets)
{
widget.UnsubscribeFromWidgetUpdates();
}
}

#if DEBUG
private void AddResetButton(object sender, RoutedEventArgs e)
{
Expand Down

0 comments on commit 3e22d5a

Please sign in to comment.