Skip to content

Commit ddd9bc8

Browse files
committed
Fix
1 parent c22b1a6 commit ddd9bc8

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

Main.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class AppUpgrader : IAsyncPlugin, ISettingProvider
1717
{
1818
private SettingsPage settingsPage;
1919
internal PluginInitContext Context;
20-
private ConcurrentBag<UpgradableApp> upgradableApps;
20+
private ConcurrentBag<UpgradableApp> allUpgradableApps;
21+
private ConcurrentBag<UpgradableApp> upgradableApps;
2122
private ConcurrentDictionary<string, string> appIconPaths;
2223
private readonly SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(1, 1);
2324
private DateTime _lastRefreshTime = DateTime.MinValue;
@@ -44,7 +45,7 @@ public async Task InitAsync(PluginInitContext context)
4445
settingsPage = new SettingsPage(Context);
4546
settingsPage.SettingLoaded += async (s, e) =>
4647
{
47-
settingsPage.ExcludedApps.CollectionChanged += ExcludedApps_CollectionChanged;
48+
settingsPage.ExcludedApps.CollectionChanged += (s,e)=> ApplyExclusionFilter();
4849
RemoveExcludedAppsFromUpgradableList();
4950
};
5051
});
@@ -331,25 +332,48 @@ private async Task RefreshUpgradableAppsAsync()
331332
if (!ShouldRefreshCache())
332333
return;
333334

334-
var apps = await GetUpgradableAppsAsync();
335-
upgradableApps = new ConcurrentBag<UpgradableApp>(apps);
336-
RemoveExcludedAppsFromUpgradableList();
337-
338-
_lastRefreshTime = DateTime.UtcNow;
335+
var apps = await GetUpgradableAppsAsync();
336+
allUpgradableApps = new ConcurrentBag<UpgradableApp>(apps);
337+
ApplyExclusionFilter();
338+
_lastRefreshTime = DateTime.UtcNow;
339339
}
340-
catch (Exception ex){}
341340
finally
342341
{
343-
_refreshSemaphore.Release();
342+
_refreshSemaphore.Release();
344343
}
345344
}
345+
private void ApplyExclusionFilter()
346+
{
347+
var excludedApps = settingsPage.ExcludedApps;
348+
349+
if (excludedApps == null || !excludedApps.Any())
350+
{
351+
upgradableApps = new ConcurrentBag<UpgradableApp>(allUpgradableApps);
352+
return;
353+
}
354+
355+
var filteredApps = allUpgradableApps
356+
.Where(app => !excludedApps.Any(excludedApp =>
357+
app.Name.Contains(excludedApp, StringComparison.OrdinalIgnoreCase) ||
358+
app.Id.Contains(excludedApp, StringComparison.OrdinalIgnoreCase)))
359+
.ToList();
360+
361+
upgradableApps = new ConcurrentBag<UpgradableApp>(filteredApps);
362+
}
363+
346364

347365
private async Task PerformUpgradeAsync(UpgradableApp app)
348366
{
349367
Context.API.ShowMsg($"Preparing to update {app.Name}... This may take a moment.");
350368
await ExecuteWingetCommandAsync($"winget upgrade --id {app.Id} -i");
351369

352-
if (upgradableApps != null)
370+
if (allUpgradableApps != null)
371+
{
372+
var updatedAllApps = allUpgradableApps.Where(a => a.Id != app.Id).ToList();
373+
allUpgradableApps = new ConcurrentBag<UpgradableApp>(updatedAllApps);
374+
}
375+
376+
if (upgradableApps != null)
353377
{
354378
var updatedApps = upgradableApps.Where(a => a.Id != app.Id).ToList();
355379
upgradableApps = new ConcurrentBag<UpgradableApp>(updatedApps);

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "AppUpgrader",
55
"Description": "Allows you to keep your applications up using winget",
66
"Author": "Exarilo",
7-
"Version": "1.1.2",
7+
"Version": "1.1.3",
88
"Language": "csharp",
99
"Website": "https://github.com/Exarilo/Flow.Launcher.Plugin.AppUpgrader",
1010
"IcoPath": "Images\\app.png",

0 commit comments

Comments
 (0)