Skip to content

Commit

Permalink
feat(linux): compute app category by mac category
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 12, 2017
1 parent dd80685 commit 022d542
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
9 changes: 4 additions & 5 deletions packages/electron-builder/src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*
Expand Down Expand Up @@ -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

/**
Expand Down
31 changes: 27 additions & 4 deletions packages/electron-builder/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 022d542

Please sign in to comment.