Merge pull request #2123 from VictoriousRaptor/BoostProgramInit

Reduce CPU and disk usage during Program plugin init
This commit is contained in:
VictoriousRaptor 2023-06-11 17:40:45 +08:00 committed by GitHub
commit 6655d837c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 34 deletions

View file

@ -88,21 +88,24 @@ namespace Flow.Launcher.Plugin.Program
bool cacheEmpty = !_win32s.Any() && !_uwps.Any();
var a = Task.Run(() =>
if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
{
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
});
var b = Task.Run(() =>
_ = Task.Run(async () =>
{
await IndexProgramsAsync().ConfigureAwait(false);
WatchProgramUpdate();
});
}
else
{
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPPRogram index cost", IndexUwpPrograms);
});
WatchProgramUpdate();
}
if (cacheEmpty)
await Task.WhenAll(a, b);
Win32.WatchProgramUpdate(_settings);
_ = UWP.WatchPackageChange();
static void WatchProgramUpdate()
{
Win32.WatchProgramUpdate(_settings);
_ = UWP.WatchPackageChange();
}
}
public static void IndexWin32Programs()
@ -110,6 +113,8 @@ namespace Flow.Launcher.Plugin.Program
var win32S = Win32.All(_settings);
_win32s = win32S;
ResetCache();
_win32Storage.Save(_win32s);
_settings.LastIndexTime = DateTime.Now;
}
public static void IndexUwpPrograms()
@ -117,6 +122,8 @@ namespace Flow.Launcher.Plugin.Program
var applications = UWP.All(_settings);
_uwps = applications;
ResetCache();
_uwpStorage.Save(_uwps);
_settings.LastIndexTime = DateTime.Now;
}
public static async Task IndexProgramsAsync()
@ -131,7 +138,6 @@ namespace Flow.Launcher.Plugin.Program
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpPrograms);
});
await Task.WhenAll(a, b).ConfigureAwait(false);
_settings.LastIndexTime = DateTime.Today;
}
internal static void ResetCache()
@ -199,7 +205,6 @@ namespace Flow.Launcher.Plugin.Program
_ = Task.Run(() =>
{
IndexUwpPrograms();
_settings.LastIndexTime = DateTime.Today;
});
}
else if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
@ -210,7 +215,6 @@ namespace Flow.Launcher.Plugin.Program
_ = Task.Run(() =>
{
IndexWin32Programs();
_settings.LastIndexTime = DateTime.Today;
});
}
}

View file

@ -121,13 +121,6 @@ namespace Flow.Launcher.Plugin.Program
public bool EnablePathSource { get; set; } = false;
public bool EnableUWP { get; set; } = true;
public string CustomizedExplorer { get; set; } = Explorer;
public string CustomizedArgs { get; set; } = ExplorerArgs;
internal const char SuffixSeparator = ';';
internal const string Explorer = "explorer";
internal const string ExplorerArgs = "%s";
}
}

View file

@ -87,18 +87,6 @@ namespace Flow.Launcher.Plugin.Program.Views
}
}
public string CustomizedExplorerPath
{
get => _settings.CustomizedExplorer;
set => _settings.CustomizedExplorer = value;
}
public string CustomizedExplorerArg
{
get => _settings.CustomizedArgs;
set => _settings.CustomizedArgs = value;
}
public bool ShowUWPCheckbox => UWP.SupportUWP();
public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win32s, UWP.Application[] uwps)