Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/local-open-targets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ function parseDesktopEntryValue(line: string): [string, string] | null {
];
}

const LINUX_WORKSPACE_APPLICATION_CATEGORIES = new Set([
"FileManager",
"TerminalEmulator",
"TextEditor",
]);

function parseDesktopEntryList(value: string | undefined): string[] {
return value?.split(";").filter(Boolean) ?? [];
}

function parseLinuxDesktopApplication(
desktopFilePath: string,
content: string,
Expand Down Expand Up @@ -403,7 +413,14 @@ function parseLinuxDesktopApplication(

const label = fields.get("Name");
const exec = fields.get("Exec");
if (!label || !exec) {
const categories = parseDesktopEntryList(fields.get("Categories"));
if (
!label ||
!exec ||
!categories.some((category) =>
LINUX_WORKSPACE_APPLICATION_CATEGORIES.has(category),
)
) {
return null;
}

Expand Down
49 changes: 43 additions & 6 deletions packages/local-open-targets/test/workspace-open-targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ describe("workspace open targets", () => {
"[Desktop Entry]",
"Type=Application",
"Name=Mock Edit",
"Categories=Utility;TextEditor;",
"Exec=mockedit --open %f",
"",
].join("\n"),
Expand All @@ -245,10 +246,41 @@ describe("workspace open targets", () => {
"Type=Application",
"Name=Hidden App",
"NoDisplay=true",
"Categories=TextEditor;",
"Exec=hidden %f",
"",
].join("\n"),
);
await Promise.all(
[
["files", "Files", "FileManager"],
["terminal", "Terminal", "TerminalEmulator"],
].map(async ([id, name, category]) =>
writeFile(
path.join(desktopDirectory, `${id}.desktop`),
[
"[Desktop Entry]",
"Type=Application",
`Name=${name}`,
`Categories=System;${category};`,
`Exec=${id} %f`,
"",
].join("\n"),
),
),
);
await writeFile(
path.join(desktopDirectory, "unrelated.desktop"),
[
"[Desktop Entry]",
"Type=Application",
"Name=Music Player",
"Categories=AudioVideo;Player;",
"MimeType=audio/mpeg;inode/directory;",
"Exec=music-player %f",
"",
].join("\n"),
);

try {
const targets = await listWorkspaceOpenTargetsWithRuntime(
Expand All @@ -258,20 +290,24 @@ describe("workspace open targets", () => {
}),
);

expect(targets).toEqual([
{
expect(targets).toEqual(
[
["desktop-app:files", "Files"],
["desktop-app:mockedit", "Mock Edit"],
["desktop-app:terminal", "Terminal"],
].map(([id, label]) => ({
capabilities: {
openDirectory: true,
openFile: true,
openFileAtColumn: false,
openFileAtLine: false,
},
icon: { kind: "symbol", name: "app" },
id: "desktop-app:mockedit",
id,
kind: "native-app",
label: "Mock Edit",
},
]);
label,
})),
);
} finally {
await rm(root, { force: true, recursive: true });
}
Expand Down Expand Up @@ -472,6 +508,7 @@ describe("workspace open targets", () => {
"[Desktop Entry]",
"Type=Application",
"Name=Mock Edit",
"Categories=TextEditor;",
"Exec=mockedit --open %f",
"",
].join("\n"),
Expand Down