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Q,YAAY,IAAZ,CAAd;AACA,gBAAQ,KAAK,IAAI,IAAI,KAAK,EAA1B;AACD;;AACD,cAAQ,IAAR;AACA,aAAO,IAAP;AAjE4H;AAkE7H;;AAjHG;;;AAoHN,MAAM,qBAA0B;AAC9B,yCAAuC,UADT;AAE9B,yCAAuC,aAFT;AAG9B,mCAAiC,WAHH;AAI9B,+BAA6B,MAJC;AAK9B,+BAA6B,kBALC;AAM9B,mCAAiC,SANH;AAO9B,2CAAyC,MAPX;AAQ9B,iCAA+B;AARD,CAAhC,C","sourcesContent":["import { asArray, isEmptyOrSpaces, log } from \"builder-util\"\nimport { outputFile } from \"fs-extra-p\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { LinuxTargetSpecificOptions } from \"..\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport { IconInfo } from \"../platformPackager\"\nimport { getTemplatePath } from \"../util/pathManager\"\n\nexport const installPrefix = \"/opt\"\n\nexport class LinuxTargetHelper {\n private readonly iconPromise = new Lazy(() => this.computeDesktopIcons())\n\n maxIconPath: string | null = null\n\n constructor(private packager: LinuxPackager) {\n }\n\n get icons(): Promise<Array<IconInfo>> {\n return this.iconPromise.value\n }\n\n // must be name without spaces and other special characters, but not product name used\n private async computeDesktopIcons(): Promise<Array<IconInfo>> {\n const packager = this.packager\n const iconDir = packager.platformSpecificBuildOptions.icon\n const sources = [iconDir == null ? \"icons\" : iconDir]\n\n const commonConfiguration = packager.config\n let icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon\n if (icnsPath != null) {\n if (!icnsPath.endsWith(\".icns\")) {\n icnsPath += \".icns\"\n }\n sources.push(icnsPath)\n }\n\n sources.push(\"icon.icns\")\n\n sources.push(path.join(getTemplatePath(\"linux\"), \"electron-icons\"))\n\n const result = await packager.resolveIcon(sources, \"set\")\n this.maxIconPath = result[result.length - 1].file\n return result\n }\n\n getDescription(options: LinuxTargetSpecificOptions) {\n return options.description || this.packager.appInfo.description\n }\n\n async writeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, destination?: string | null, extra?: { [key: string]: string; }): Promise<string> {\n const data = await this.computeDesktopEntry(targetSpecificOptions, exec, extra)\n const file = destination || await this.packager.getTempFile(`${this.packager.appInfo.productFilename}.desktop`)\n await outputFile(file, data)\n return file\n }\n\n async computeDesktopEntry(targetSpecificOptions: LinuxTargetSpecificOptions, exec?: string, extra?: { [key: string]: string; }): Promise<string> {\n if (exec != null && exec.length === 0) {\n throw new Error(\"Specified exec is empty\")\n }\n\n const packager = this.packager\n const appInfo = packager.appInfo\n\n const productFilename = appInfo.productFilename\n\n const desktopMeta: any = {\n Name: appInfo.productName,\n Comment: this.getDescription(targetSpecificOptions),\n Exec: exec == null ? `\"${installPrefix}/${productFilename}/${packager.executableName}\" %U` : exec,\n Terminal: \"false\",\n Type: \"Application\",\n Icon: packager.executableName,\n ...extra,\n ...targetSpecificOptions.desktop,\n }\n\n const mimeTypes: Array<string> = asArray(targetSpecificOptions.mimeTypes)\n for (const fileAssociation of packager.fileAssociations) {\n if (fileAssociation.mimeType != null) {\n mimeTypes.push(fileAssociation.mimeType)\n }\n }\n\n for (const protocol of asArray(packager.config.protocols).concat(asArray(packager.platformSpecificBuildOptions.protocols))) {\n for (const scheme of asArray(protocol.schemes)) {\n mimeTypes.push(`x-scheme-handler/${scheme}`)\n }\n }\n\n if (mimeTypes.length !== 0) {\n desktopMeta.MimeType = mimeTypes.join(\";\") + \";\"\n }\n\n let category = targetSpecificOptions.category\n if (isEmptyOrSpaces(category)) {\n const macCategory = (packager.config.mac || {}).category\n if (macCategory != null) {\n category = macToLinuxCategory[macCategory]\n }\n\n if (category == null) {\n // https://github.com/develar/onshape-desktop-shell/issues/48\n if (macCategory != null) {\n log.warn({macCategory}, \"cannot map macOS category to Linux. If possible mapping is known for you, please file issue to add it.\")\n }\n log.warn({\n reason: \"linux.category is not set and cannot map from macOS\",\n docs: \"https://electron.build/configuration/configuration#LinuxBuildOptions-category\",\n }, \"application Linux category is set to default \\\"Utility\\\"\")\n category = \"Utility\"\n }\n }\n desktopMeta.Categories = `${category}${category.endsWith(\";\") ? \"\" : \";\"}`\n\n let data = `[Desktop Entry]`\n for (const name of Object.keys(desktopMeta)) {\n const value = desktopMeta[name]\n data += `\\n${name}=${value}`\n }\n data += \"\\n\"\n return data\n }\n}\n\nconst macToLinuxCategory: any = {\n \"public.app-category.graphics-design\": \"Graphics\",\n \"public.app-category.developer-tools\": \"Development\",\n \"public.app-category.education\": \"Education\",\n \"public.app-category.games\": \"Game\",\n \"public.app-category.video\": \"Video;AudioVideo\",\n \"public.app-category.utilities\": \"Utility\",\n \"public.app-category.social-networking\": \"Chat\",\n \"public.app-category.finance\": \"Finance\",\n}"],"sourceRoot":""}
|