Skip to content

Commit 6655d83

Browse files
Merge pull request #2123 from VictoriousRaptor/BoostProgramInit
Reduce CPU and disk usage during Program plugin init
2 parents a35b001 + 4debacd commit 6655d83

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,42 @@ public async Task InitAsync(PluginInitContext context)
8888

8989
bool cacheEmpty = !_win32s.Any() && !_uwps.Any();
9090

91-
var a = Task.Run(() =>
91+
if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
9292
{
93-
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
94-
});
95-
96-
var b = Task.Run(() =>
93+
_ = Task.Run(async () =>
94+
{
95+
await IndexProgramsAsync().ConfigureAwait(false);
96+
WatchProgramUpdate();
97+
});
98+
}
99+
else
97100
{
98-
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPPRogram index cost", IndexUwpPrograms);
99-
});
100-
101-
if (cacheEmpty)
102-
await Task.WhenAll(a, b);
101+
WatchProgramUpdate();
102+
}
103103

104-
Win32.WatchProgramUpdate(_settings);
105-
_ = UWP.WatchPackageChange();
104+
static void WatchProgramUpdate()
105+
{
106+
Win32.WatchProgramUpdate(_settings);
107+
_ = UWP.WatchPackageChange();
108+
}
106109
}
107110

108111
public static void IndexWin32Programs()
109112
{
110113
var win32S = Win32.All(_settings);
111114
_win32s = win32S;
112115
ResetCache();
116+
_win32Storage.Save(_win32s);
117+
_settings.LastIndexTime = DateTime.Now;
113118
}
114119

115120
public static void IndexUwpPrograms()
116121
{
117122
var applications = UWP.All(_settings);
118123
_uwps = applications;
119124
ResetCache();
125+
_uwpStorage.Save(_uwps);
126+
_settings.LastIndexTime = DateTime.Now;
120127
}
121128

122129
public static async Task IndexProgramsAsync()
@@ -131,7 +138,6 @@ public static async Task IndexProgramsAsync()
131138
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpPrograms);
132139
});
133140
await Task.WhenAll(a, b).ConfigureAwait(false);
134-
_settings.LastIndexTime = DateTime.Today;
135141
}
136142

137143
internal static void ResetCache()
@@ -199,7 +205,6 @@ private static void DisableProgram(IProgram programToDelete)
199205
_ = Task.Run(() =>
200206
{
201207
IndexUwpPrograms();
202-
_settings.LastIndexTime = DateTime.Today;
203208
});
204209
}
205210
else if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
@@ -210,7 +215,6 @@ private static void DisableProgram(IProgram programToDelete)
210215
_ = Task.Run(() =>
211216
{
212217
IndexWin32Programs();
213-
_settings.LastIndexTime = DateTime.Today;
214218
});
215219
}
216220
}

Plugins/Flow.Launcher.Plugin.Program/Settings.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ private void RemoveRedundantSuffixes()
121121
public bool EnablePathSource { get; set; } = false;
122122
public bool EnableUWP { get; set; } = true;
123123

124-
public string CustomizedExplorer { get; set; } = Explorer;
125-
public string CustomizedArgs { get; set; } = ExplorerArgs;
126-
127124
internal const char SuffixSeparator = ';';
128-
129-
internal const string Explorer = "explorer";
130-
131-
internal const string ExplorerArgs = "%s";
132125
}
133126
}

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ public bool EnableUWP
8787
}
8888
}
8989

90-
public string CustomizedExplorerPath
91-
{
92-
get => _settings.CustomizedExplorer;
93-
set => _settings.CustomizedExplorer = value;
94-
}
95-
96-
public string CustomizedExplorerArg
97-
{
98-
get => _settings.CustomizedArgs;
99-
set => _settings.CustomizedArgs = value;
100-
}
101-
10290
public bool ShowUWPCheckbox => UWP.SupportUWP();
10391

10492
public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win32s, UWP.Application[] uwps)

0 commit comments

Comments
 (0)