mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[PTRun][Settings][Program] Fix 100% CPU load issue (#17414)
* [PTRun][Program]Don't reload on settings change * [PTRun][Settings] Don't trigger saves on visual property changes * [PTRun][Settings] Fix manipulation of searched plugins * [PTRun][Settings] Don't reload settings if we wrote recently * fix PR comments nit
This commit is contained in:
@@ -19,7 +19,7 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
|
|||||||
|
|
||||||
namespace Microsoft.Plugin.Program
|
namespace Microsoft.Plugin.Program
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable, IDisposable
|
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable, IDisposable
|
||||||
{
|
{
|
||||||
// The order of this array is important! The Parsers will be checked in order (index 0 to index Length-1) and the first parser which is able to parse the Query will be used
|
// The order of this array is important! The Parsers will be checked in order (index 0 to index Length-1) and the first parser which is able to parse the Query will be used
|
||||||
// NoArgumentsArgumentParser does always succeed and therefor should always be last/fallback
|
// NoArgumentsArgumentParser does always succeed and therefor should always be last/fallback
|
||||||
@@ -194,11 +194,6 @@ namespace Microsoft.Plugin.Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadData()
|
|
||||||
{
|
|
||||||
IndexPrograms();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(disposing: true);
|
Dispose(disposing: true);
|
||||||
|
|||||||
@@ -104,6 +104,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
|
|
||||||
private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
|
private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (
|
||||||
|
e.PropertyName == nameof(PowerLauncherPluginViewModel.ShowNotAccessibleWarning)
|
||||||
|
|| e.PropertyName == nameof(PowerLauncherPluginViewModel.ShowNotAllowedKeywordWarning)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Don't trigger a settings update if the changed property is for visual notification.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
|
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
|
||||||
UpdateSettings();
|
UpdateSettings();
|
||||||
}
|
}
|
||||||
@@ -430,6 +439,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
|||||||
{
|
{
|
||||||
var plugins = settings.Plugins.Where(p => p.Name.StartsWith(SearchText, StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf($" {SearchText}", StringComparison.OrdinalIgnoreCase) > 0);
|
var plugins = settings.Plugins.Where(p => p.Name.StartsWith(SearchText, StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf($" {SearchText}", StringComparison.OrdinalIgnoreCase) > 0);
|
||||||
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
|
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
|
||||||
|
foreach (var plugin in _plugins)
|
||||||
|
{
|
||||||
|
plugin.PropertyChanged += OnPluginInfoChange;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,15 +19,31 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||||||
private readonly ObservableCollection<Tuple<string, string>> searchResultPreferencesOptions;
|
private readonly ObservableCollection<Tuple<string, string>> searchResultPreferencesOptions;
|
||||||
private readonly ObservableCollection<Tuple<string, string>> searchTypePreferencesOptions;
|
private readonly ObservableCollection<Tuple<string, string>> searchTypePreferencesOptions;
|
||||||
|
|
||||||
|
private int _lastIPCMessageSentTick;
|
||||||
|
|
||||||
|
// Keep track of the last IPC Message that was sent.
|
||||||
|
private int SendDefaultIPCMessageTimed(string msg)
|
||||||
|
{
|
||||||
|
_lastIPCMessageSentTick = Environment.TickCount;
|
||||||
|
return ShellPage.SendDefaultIPCMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public PowerLauncherPage()
|
public PowerLauncherPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
var settingsUtils = new SettingsUtils();
|
var settingsUtils = new SettingsUtils();
|
||||||
|
_lastIPCMessageSentTick = Environment.TickCount;
|
||||||
PowerLauncherSettings settings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
PowerLauncherSettings settings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||||
ViewModel = new PowerLauncherViewModel(settings, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, App.IsDarkTheme);
|
ViewModel = new PowerLauncherViewModel(settings, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), SendDefaultIPCMessageTimed, App.IsDarkTheme);
|
||||||
DataContext = ViewModel;
|
DataContext = ViewModel;
|
||||||
_ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () =>
|
_ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () =>
|
||||||
{
|
{
|
||||||
|
if (Environment.TickCount < _lastIPCMessageSentTick + 500)
|
||||||
|
{
|
||||||
|
// Don't try to update data from the file if we tried to write to it through IPC in the last 500 milliseconds.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PowerLauncherSettings powerLauncherSettings = null;
|
PowerLauncherSettings powerLauncherSettings = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user