Skip to content

Commit

Permalink
Disallow user from adding widgets if the WidgetService isn't started (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored and EricJohnson327 committed Aug 19, 2024
1 parent 25c1167 commit b8d6537
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task<WidgetCatalog> GetWidgetCatalogAsync()
}
catch (Exception ex)
{
_log.Error(ex, "Exception in GetWidgetDefinitionAsync:");
_log.Error(ex, "Exception in GetWidgetCatalogAsync:");
_widgetCatalog = null;
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<WidgetProviderDefinition[]> GetProviderDefinitionsAsync()
}
catch (Exception ex)
{
_log.Error(ex, "Exception in GetWidgetDefinitionAsync:");
_log.Error(ex, "Exception in GetProviderDefinitionsAsync:");
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task<WidgetDefinition[]> GetWidgetDefinitionsAsync()
}
catch (Exception ex)
{
_log.Error(ex, "Exception in GetWidgetDefinitionAsync:");
_log.Error(ex, "Exception in GetWidgetDefinitionsAsync:");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class DashboardViewModel : ObservableObject
private bool _isLoading;

[ObservableProperty]
private bool _hasWidgetService;
private bool _hasWidgetServiceInitialized;

public DashboardViewModel(
IWidgetServiceService widgetServiceService,
Expand All @@ -43,7 +43,7 @@ public DashboardViewModel(

public Visibility GetNoWidgetMessageVisibility(int widgetCount, bool isLoading)
{
return (widgetCount == 0 && !isLoading && HasWidgetService) ? Visibility.Visible : Visibility.Collapsed;
return (widgetCount == 0 && !isLoading && HasWidgetServiceInitialized) ? Visibility.Visible : Visibility.Collapsed;
}

public bool IsRunningAsAdmin()
Expand Down
2 changes: 1 addition & 1 deletion tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
x:Uid="AddWidget"
HorizontalAlignment="Right"
Command="{x:Bind AddWidgetClickCommand}"
IsEnabled="{x:Bind ViewModel.HasWidgetService, Mode=OneWay}"/>
IsEnabled="{x:Bind ViewModel.HasWidgetServiceInitialized, Mode=OneWay}"/>
</StackPanel>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private async Task<bool> SubscribeToWidgetCatalogEventsAsync()
var widgetCatalog = await ViewModel.WidgetHostingService.GetWidgetCatalogAsync();
if (widgetCatalog == null)
{
_log.Error("Error in in SubscribeToWidgetCatalogEvents, widgetCatalog == null");
return false;
}

Expand Down Expand Up @@ -194,9 +195,10 @@ private async Task InitializeDashboard()
}
else if (ViewModel.WidgetServiceService.CheckForWidgetServiceAsync())
{
ViewModel.HasWidgetService = true;
if (await SubscribeToWidgetCatalogEventsAsync())
{
ViewModel.HasWidgetServiceInitialized = true;

var isFirstDashboardRun = !(await _localSettingsService.ReadSettingAsync<bool>(WellKnownSettingsKeys.IsNotFirstDashboardRun));
_log.Information($"Is first dashboard run = {isFirstDashboardRun}");
if (isFirstDashboardRun)
Expand Down

0 comments on commit b8d6537

Please sign in to comment.