Skip to content

Commit

Permalink
Use dirEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
kubo39 authored and yatima1460 committed Feb 7, 2020
1 parent b3b7c16 commit bc91539
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Core/Utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ import std.process : executeShell;
import std.array : split;
import std.conv : to;

version(linux) @system string[] getDesktopFiles()
version(linux) @system string[] getDesktopFiles()
{
synchronized
{
// TODO: replace executeShell with a system call to get the list of files, executeShell is SLOW
immutable auto ls = executeShell("ls /usr/share/applications/*.desktop | grep -v _");
if (ls.status == 0)
{
import std.algorithm : filter;
import std.array : array;
return ls.output.split("\n").filter!(x => x.length > 0).array;
import std.algorithm : map;
import std.array : array;
import std.file : dirEntries, SpanMode;
try
{
return dirEntries("/usr/share/applications", "*.desktop", SpanMode.depth)
.map!(a => a.name)
.array;
}
catch (Exception _)
{
error("Can't retrieve applications, will return an empty list");
return [];
}
error("Can't retrieve applications, will return an empty list");
return [];
}
}

Expand Down

0 comments on commit bc91539

Please sign in to comment.