diff --git a/packages/electron-builder/src/options/linuxOptions.ts b/packages/electron-builder/src/options/linuxOptions.ts index bb28d838024..044405d682c 100644 --- a/packages/electron-builder/src/options/linuxOptions.ts +++ b/packages/electron-builder/src/options/linuxOptions.ts @@ -2,11 +2,6 @@ import { TargetConfigType, TargetSpecificOptions } from "../core" import { PlatformSpecificBuildOptions } from "../metadata" export interface LinuxBuildOptions extends CommonLinuxOptions, PlatformSpecificBuildOptions { - /** - * The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage. - */ - readonly packageCategory?: string | null - /** * Target package type: list of `AppImage`, `snap`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. * @@ -61,6 +56,10 @@ export interface CommonLinuxOptions { * The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry). */ readonly category?: string | null + + /** + * The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section). Not applicable for AppImage. + */ readonly packageCategory?: string | null /** diff --git a/packages/electron-builder/src/targets/LinuxTargetHelper.ts b/packages/electron-builder/src/targets/LinuxTargetHelper.ts index 31e394ecdbd..68f19b53919 100644 --- a/packages/electron-builder/src/targets/LinuxTargetHelper.ts +++ b/packages/electron-builder/src/targets/LinuxTargetHelper.ts @@ -1,5 +1,5 @@ import BluebirdPromise from "bluebird-lst" -import { debug, exec, isEmptyOrSpaces } from "electron-builder-util" +import { debug, exec, isEmptyOrSpaces, warn } from "electron-builder-util" import { statOrNull } from "electron-builder-util/out/fs" import { ensureDir, outputFile, readdir } from "fs-extra-p" import * as path from "path" @@ -115,10 +115,24 @@ export class LinuxTargetHelper { Icon: this.packager.executableName, ...extra, ...targetSpecificOptions.desktop } - const category = targetSpecificOptions.category - if (!isEmptyOrSpaces(category)) { - desktopMeta.Categories = `${category}${category.endsWith(";") ? "" : ";"}` + let category = targetSpecificOptions.category + if (isEmptyOrSpaces(category)) { + const macCategory = (this.packager.config.mac || {}).category + if (macCategory != null) { + category = macToLinuxCategory[macCategory] + } + + if (category == null) { + // https://github.com/develar/onshape-desktop-shell/issues/48 + let message = "Application category is not set for Linux (linux.category).\nPlease see https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-category" + if (macCategory != null) { + message += `\n Cannot map mac category "${macCategory}" to Linux. If possible mapping is known for you, please file issue to add it.` + } + warn(message) + category = "Utility" + } } + desktopMeta.Categories = `${category}${category.endsWith(";") ? "" : ";"}` let data = `[Desktop Entry]` for (const name of Object.keys(desktopMeta)) { @@ -213,6 +227,15 @@ export class LinuxTargetHelper { } } +const macToLinuxCategory: any = { + "public.app-category.graphics-design": "Graphics", + "public.app-category.developer-tools": "Development", + "public.app-category.education": "Education", + "public.app-category.games": "Game", + "public.app-category.video": "Video;AudioVideo", + "public.app-category.utilities": "Utility", +} + function resizeImage(imagePath: string, result: string, w: number, h: number) { if (process.platform === "darwin") { return exec("sips", ["--resampleHeightWidth", h.toString(10), w.toString(10), imagePath, "--out", result])