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IAAJ,CAAS;AACP,UAAA,MAAM,EAAE,qDADD;AAEP,UAAA,IAAI,EAAE;AAFC,SAAT,EAGG,0DAHH;;AAIA,QAAA,QAAQ,GAAG,SAAX;AACD;AACF;;AACD,IAAA,WAAW,CAAC,UAAZ,GAAyB,GAAG,QAAQ,GAAG,QAAQ,CAAC,QAAT,CAAkB,GAAlB,IAAyB,EAAzB,GAA8B,GAAG,EAAxE;AAEA,QAAI,IAAI,GAAG,iBAAX;;AACA,SAAK,MAAM,IAAX,IAAmB,MAAM,CAAC,IAAP,CAAY,WAAZ,CAAnB,EAA6C;AAC3C,MAAA,IAAI,IAAI,KAAK,IAAI,IAAI,WAAW,CAAC,IAAD,CAAM,EAAtC;AACD;;AACD,IAAA,IAAI,IAAI,IAAR;AACA,WAAO,IAAP;AACD;;AA9J2B;;;AAiK9B,MAAM,kBAAkB,GAAQ;AAC9B,yCAAuC,UADT;AAE9B,yCAAuC,aAFT;AAG9B,mCAAiC,WAHH;AAI9B,+BAA6B,MAJC;AAK9B,+BAA6B,kBALC;AAM9B,mCAAiC,SANH;AAO9B,2CAAyC,cAPX;AAQ9B,iCAA+B;AARD,CAAhC,C","sourcesContent":["import { asArray, isEmptyOrSpaces, log } from \"builder-util\"\nimport { outputFile } from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport { LinuxTargetSpecificOptions } from \"..\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport { IconInfo } from \"../platformPackager\"\n\nexport const installPrefix = \"/opt\"\n\nexport class LinuxTargetHelper {\n private readonly iconPromise = new Lazy(() => this.computeDesktopIcons())\n\n private readonly mimeTypeFilesPromise = new Lazy(() => this.computeMimeTypeFiles())\n\n maxIconPath: string | null = null\n\n constructor(private packager: LinuxPackager) {\n }\n\n get icons(): Promise> {\n return this.iconPromise.value\n }\n\n get mimeTypeFiles(): Promise {\n return this.mimeTypeFilesPromise.value\n }\n\n private async computeMimeTypeFiles(): Promise {\n const items: Array = []\n for (const fileAssociation of this.packager.fileAssociations) {\n if (!fileAssociation.mimeType) {\n continue\n }\n\n const data = `\n \n ${fileAssociation.description ? `${fileAssociation.description}` : \"\"}\n \n `\n items.push(data)\n }\n\n if (items.length === 0) {\n return null\n }\n\n const file = await this.packager.getTempFile(\".xml\")\n await outputFile(file, '\\n\\n' + items.join(\"\\n\") + \"\\n\")\n return file\n }\n\n // must be name without spaces and other special characters, but not product name used\n private async computeDesktopIcons(): Promise> {\n const packager = this.packager\n const iconDir = packager.platformSpecificBuildOptions.icon\n const sources = iconDir == null ? [] : [iconDir]\n\n const commonConfiguration = packager.config\n const icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon\n if (icnsPath != null) {\n sources.push(icnsPath)\n }\n\n // need to put here and not as default because need to resolve image size\n const result = await packager.resolveIcon(sources, asArray(packager.getDefaultFrameworkIcon()), \"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 {\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 {\n if (exec != null && exec.length === 0) {\n throw new Error(\"Specified exec is empty\")\n }\n // https://github.com/electron-userland/electron-builder/issues/3418\n if (targetSpecificOptions.desktop != null && targetSpecificOptions.desktop.Exec != null) {\n throw new Error(\"Please specify executable name as linux.executableName instead of linux.desktop.Exec\")\n }\n\n const packager = this.packager\n const appInfo = packager.appInfo\n\n const productFilename = appInfo.productFilename\n\n if (exec == null) {\n exec = `${installPrefix}/${productFilename}/${packager.executableName}`\n if (!/^[/0-9A-Za-z._-]+$/.test(exec)) {\n exec = `\"${exec}\"`\n }\n exec += \" %U\"\n }\n\n const desktopMeta: any = {\n Name: appInfo.productName,\n Exec: exec,\n Terminal: \"false\",\n Type: \"Application\",\n Icon: packager.executableName,\n // https://askubuntu.com/questions/367396/what-represent-the-startupwmclass-field-of-a-desktop-file\n // must be set to package.json name (because it is Electron set WM_CLASS)\n // to get WM_CLASS of running window: xprop WM_CLASS\n // StartupWMClass doesn't work for unicode\n // https://github.com/electron/electron/blob/2-0-x/atom/browser/native_window_views.cc#L226\n StartupWMClass: appInfo.productName,\n ...extra,\n ...targetSpecificOptions.desktop,\n }\n\n const description = this.getDescription(targetSpecificOptions)\n if (!isEmptyOrSpaces(description)) {\n desktopMeta.Comment = description\n }\n\n const mimeTypes: Array = 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://www.electron.build/configuration/linux\",\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 data += `\\n${name}=${desktopMeta[name]}`\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\": \"Network;Chat\",\n \"public.app-category.finance\": \"Office;Finance\",\n}\n"],"sourceRoot":""}