Skip to content

Commit 864a382

Browse files
committed
Use Generic to remove duplicate query
1 parent 80a2f0d commit 864a382

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,17 @@ public List<Result> Query(Query query)
7272
Win32[] win32;
7373
UWP.Application[] uwps;
7474

75-
lock (IndexLock)
76-
{ // just take the reference inside the lock to eliminate query time issues.
77-
win32 = _win32s;
78-
uwps = _uwps;
79-
}
80-
81-
82-
var results1 = win32.AsParallel()
83-
.Where(p => p.Enabled)
84-
.Select(p => p.Result(query.Search, _context.API));
75+
win32 = _win32s;
76+
uwps = _uwps;
8577

86-
var results2 = uwps.AsParallel()
87-
.Where(p => p.Enabled)
88-
.Select(p => p.Result(query.Search, _context.API));
78+
var result = win32.Cast<IProgram>()
79+
.Concat(uwps)
80+
.AsParallel()
81+
.Where(p => p.Enabled)
82+
.Select(p => p.Result(query.Search, _context.API))
83+
.Where(r => r != null && r.Score > 0)
84+
.OrderBy(r=>r.Score).ToList();
8985

90-
var result = results1.Concat(results2).Where(r => r != null && r.Score > 0).ToList();
9186
return result;
9287
}
9388

@@ -99,10 +94,9 @@ public void Init(PluginInitContext context)
9994
public static void IndexWin32Programs()
10095
{
10196
var win32S = Win32.All(_settings);
102-
lock (IndexLock)
103-
{
104-
_win32s = win32S;
105-
}
97+
98+
_win32s = win32S;
99+
106100
}
107101

108102
public static void IndexUWPPrograms()
@@ -111,10 +105,9 @@ public static void IndexUWPPrograms()
111105
var support = Environment.OSVersion.Version.Major >= windows10.Major;
112106

113107
var applications = support ? UWP.All() : new UWP.Application[] { };
114-
lock (IndexLock)
115-
{
116-
_uwps = applications;
117-
}
108+
109+
_uwps = applications;
110+
118111
}
119112

120113
public static void IndexPrograms()

Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface IProgram
99
string UniqueIdentifier { get; set; }
1010
string Name { get; }
1111
string Location { get; }
12+
bool Enabled { get; }
1213
}
1314
}

0 commit comments

Comments
 (0)