mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[Settings][runner]Quick access system tray launcher (#22408)
* Init * Fix running settings * UI design * Left click trigger Wire up colorpicker and pt run * Wire up others * Update FlyoutWindow.xaml.cs * Removed comments * Update FlyoutWindow.xaml * More work * Open Settings page * More UI work * Resolve conflicts * [General] SystemTray Flyout: Add update on tray items' visibility when module gets enabled/disabled Also remove context menu opening on tray icon. * Adding app list * Adding more buttons, resolving conflicts * [General] Flyout: improving opening, closing flyout/settings window. Implementing basic bahaviour on enabling/disabling modules. * [General] FlyoutWindow: proceed with implementation. GPO works. Main functionallity works (launching and enabling apps). * [general] flyout: fix exit button * [general] flyout: implement double click handling * Localization * [Generel] Flyout: Re-implement flyout launching, add workaround: disable flyout hiding in case the user switches on modules on the all apps page + minor changes * [general] flyout: restore the context menu when right clicking on system tray icon * Fix spellchecker * [installer] fixing missing dll files + suppress error on not signed script * Fix spell checker * Fix flyout not focusing when activated * Refresh Settings UI enabled state when flyout changes * fix spellcheck * Remove VCM from the list * [General] flyout: fix settings window opening. Switch to general page only if there is no page opened * [general] flyout: add launching hosts app * Fix CI build * adding check on elevation when launching hosts * Use localization strings that already exist * Remove dll not present in arm64 build * Adding GPO policy check for the launcher page items * fix hosts launching * Add telemetry * Also hide from all apps list when gpo is force enabling * fix spellchecker * Improve focus issues * Fix flickering Bitmap Icons * Fix telemetry error * Fix telemetry call * Fix wrong comment --------- Co-authored-by: Stefan Markovic <stefan@janeasystems.com> Co-authored-by: Laszlo Nemeth <laszlo.nemeth.hu@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using global::PowerToys.GPOWrapper;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
public class LauncherViewModel : Observable
|
||||
{
|
||||
public bool IsUpdateAvailable { get; set; }
|
||||
|
||||
public ObservableCollection<FlyoutMenuItem> FlyoutMenuItems { get; set; }
|
||||
|
||||
private GeneralSettings generalSettingsConfig;
|
||||
private UpdatingSettings updatingSettingsConfig;
|
||||
private ISettingsRepository<GeneralSettings> _settingsRepository;
|
||||
|
||||
private Func<string, int> SendIPCMessage { get; }
|
||||
|
||||
public LauncherViewModel(ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
_settingsRepository = settingsRepository;
|
||||
generalSettingsConfig = settingsRepository.SettingsConfig;
|
||||
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendIPCMessage = ipcMSGCallBackFunc;
|
||||
ResourceLoader resourceLoader = ResourceLoader.GetForViewIndependentUse();
|
||||
FlyoutMenuItems = new ObservableCollection<FlyoutMenuItem>();
|
||||
if (GPOWrapper.GetConfiguredColorPickerEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("ColorPicker/ModuleTitle"),
|
||||
Tag = "ColorPicker",
|
||||
Visible = generalSettingsConfig.Enabled.ColorPicker,
|
||||
ToolTip = SettingsRepository<ColorPickerSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsColorPicker.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredFancyZonesEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("FZEditorString"),
|
||||
Tag = "FancyZones",
|
||||
Visible = generalSettingsConfig.Enabled.FancyZones,
|
||||
ToolTip = SettingsRepository<FancyZonesSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.FancyzonesEditorHotkey.Value.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsFancyZones.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("Hosts/ModuleTitle"),
|
||||
Tag = "Hosts",
|
||||
Visible = generalSettingsConfig.Enabled.Hosts,
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsHosts.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredPowerLauncherEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("PowerLauncher/ModuleTitle"),
|
||||
Tag = "PowerLauncher",
|
||||
Visible = generalSettingsConfig.Enabled.PowerLauncher,
|
||||
ToolTip = SettingsRepository<PowerLauncherSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.OpenPowerLauncher.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsPowerToysRun.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredTextExtractorEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("TextExtractor/ModuleTitle"),
|
||||
Tag = "PowerOCR",
|
||||
Visible = generalSettingsConfig.Enabled.PowerOCR,
|
||||
ToolTip = SettingsRepository<PowerOcrSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsPowerOcr.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredScreenRulerEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("MeasureTool/ModuleTitle"),
|
||||
Tag = "MeasureTool",
|
||||
Visible = generalSettingsConfig.Enabled.MeasureTool,
|
||||
ToolTip = SettingsRepository<MeasureToolSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsScreenRuler.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (GPOWrapper.GetConfiguredShortcutGuideEnabledValue() != GpoRuleConfigured.Disabled)
|
||||
{
|
||||
FlyoutMenuItems.Add(new FlyoutMenuItem()
|
||||
{
|
||||
Label = resourceLoader.GetString("ShortcutGuide/ModuleTitle"),
|
||||
Tag = "ShortcutGuide",
|
||||
Visible = generalSettingsConfig.Enabled.ShortcutGuide,
|
||||
ToolTip = SettingsRepository<ShortcutGuideSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.OpenShortcutGuide.ToString(),
|
||||
Icon = "ms-appx:///Assets/FluentIcons/FluentIconsShortcutGuide.png",
|
||||
});
|
||||
}
|
||||
|
||||
if (updatingSettingsConfig == null)
|
||||
{
|
||||
updatingSettingsConfig = new UpdatingSettings();
|
||||
}
|
||||
|
||||
updatingSettingsConfig = UpdatingSettings.LoadSettings();
|
||||
|
||||
if (updatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToInstall || updatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToDownload)
|
||||
{
|
||||
IsUpdateAvailable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IsUpdateAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ModuleEnabledChanged()
|
||||
{
|
||||
generalSettingsConfig = _settingsRepository.SettingsConfig;
|
||||
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
||||
foreach (FlyoutMenuItem item in FlyoutMenuItems)
|
||||
{
|
||||
switch (item.Tag)
|
||||
{
|
||||
case "ColorPicker": item.Visible = generalSettingsConfig.Enabled.ColorPicker; break;
|
||||
case "FancyZones": item.Visible = generalSettingsConfig.Enabled.FancyZones; break;
|
||||
case "Hosts": item.Visible = generalSettingsConfig.Enabled.Hosts; break;
|
||||
case "PowerLauncher": item.Visible = generalSettingsConfig.Enabled.PowerLauncher; break;
|
||||
case "PowerOCR": item.Visible = generalSettingsConfig.Enabled.PowerOCR; break;
|
||||
case "MeasureTool": item.Visible = generalSettingsConfig.Enabled.MeasureTool; break;
|
||||
case "ShortcutGuide": item.Visible = generalSettingsConfig.Enabled.ShortcutGuide; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void StartBugReport()
|
||||
{
|
||||
SendIPCMessage("{\"bugreport\": 0 }");
|
||||
}
|
||||
|
||||
internal void KillRunner()
|
||||
{
|
||||
SendIPCMessage("{\"killrunner\": 0 }");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user