/ src / settings-ui / QuickAccess.UI / ViewModels / LauncherViewModel.cs
LauncherViewModel.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.Collections.ObjectModel;
 6  using global::PowerToys.GPOWrapper;
 7  using ManagedCommon;
 8  using Microsoft.PowerToys.QuickAccess.Services;
 9  using Microsoft.PowerToys.Settings.UI.Controls;
10  using Microsoft.PowerToys.Settings.UI.Library;
11  using Microsoft.PowerToys.Settings.UI.Library.Helpers;
12  using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
13  using Microsoft.UI.Dispatching;
14  using Microsoft.Windows.ApplicationModel.Resources;
15  
16  namespace Microsoft.PowerToys.QuickAccess.ViewModels;
17  
18  public sealed class LauncherViewModel : Observable
19  {
20      private readonly IQuickAccessCoordinator _coordinator;
21      private readonly ISettingsRepository<GeneralSettings> _settingsRepository;
22      private readonly ResourceLoader _resourceLoader;
23      private readonly DispatcherQueue _dispatcherQueue;
24      private readonly QuickAccessViewModel _quickAccessViewModel;
25  
26      public ObservableCollection<QuickAccessItem> FlyoutMenuItems => _quickAccessViewModel.Items;
27  
28      public bool IsUpdateAvailable { get; private set; }
29  
30      public LauncherViewModel(IQuickAccessCoordinator coordinator)
31      {
32          _coordinator = coordinator;
33          _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
34          var settingsUtils = SettingsUtils.Default;
35          _settingsRepository = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils);
36  
37          _resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
38  
39          _quickAccessViewModel = new QuickAccessViewModel(
40              _settingsRepository,
41              new Microsoft.PowerToys.QuickAccess.Services.QuickAccessLauncher(_coordinator),
42              moduleType => Helpers.ModuleGpoHelper.GetModuleGpoConfiguration(moduleType) == GpoRuleConfigured.Disabled,
43              _resourceLoader);
44          var updatingSettings = UpdatingSettings.LoadSettings() ?? new UpdatingSettings();
45          IsUpdateAvailable = updatingSettings.State is UpdatingSettings.UpdatingState.ReadyToInstall or UpdatingSettings.UpdatingState.ReadyToDownload;
46      }
47  }