mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08: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:
parent
172c63f1e2
commit
04588bc7e0
@ -19,7 +19,7 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
|
||||
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
|
||||
// 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()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
|
@ -104,6 +104,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
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));
|
||||
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);
|
||||
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
|
||||
foreach (var plugin in _plugins)
|
||||
{
|
||||
plugin.PropertyChanged += OnPluginInfoChange;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -19,15 +19,31 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
private readonly ObservableCollection<Tuple<string, string>> searchResultPreferencesOptions;
|
||||
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()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils();
|
||||
_lastIPCMessageSentTick = Environment.TickCount;
|
||||
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;
|
||||
_ = 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;
|
||||
try
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user