1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.LinuxTargetHelper = exports.installPrefix = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = require("bluebird-lst");
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _builderUtil() {
|
19 | const data = require("builder-util");
|
20 |
|
21 | _builderUtil = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fsExtraP() {
|
29 | const data = require("fs-extra-p");
|
30 |
|
31 | _fsExtraP = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _lazyVal() {
|
39 | const data = require("lazy-val");
|
40 |
|
41 | _lazyVal = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | var path = _interopRequireWildcard(require("path"));
|
49 |
|
50 | function _pathManager() {
|
51 | const data = require("../util/pathManager");
|
52 |
|
53 | _pathManager = function () {
|
54 | return data;
|
55 | };
|
56 |
|
57 | return data;
|
58 | }
|
59 |
|
60 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
61 |
|
62 | const installPrefix = "/opt";
|
63 | exports.installPrefix = installPrefix;
|
64 |
|
65 | class LinuxTargetHelper {
|
66 | constructor(packager) {
|
67 | this.packager = packager;
|
68 | this.iconPromise = new (_lazyVal().Lazy)(() => this.computeDesktopIcons());
|
69 | this.maxIconPath = null;
|
70 | }
|
71 |
|
72 | get icons() {
|
73 | return this.iconPromise.value;
|
74 | }
|
75 |
|
76 |
|
77 | computeDesktopIcons() {
|
78 | var _this = this;
|
79 |
|
80 | return (0, _bluebirdLst().coroutine)(function* () {
|
81 | const packager = _this.packager;
|
82 | const iconDir = packager.platformSpecificBuildOptions.icon;
|
83 | const sources = [iconDir == null ? "icons" : iconDir];
|
84 | const commonConfiguration = packager.config;
|
85 | let icnsPath = (commonConfiguration.mac || {}).icon || commonConfiguration.icon;
|
86 |
|
87 | if (icnsPath != null) {
|
88 | if (!icnsPath.endsWith(".icns")) {
|
89 | icnsPath += ".icns";
|
90 | }
|
91 |
|
92 | sources.push(icnsPath);
|
93 | }
|
94 |
|
95 | sources.push("icon.icns");
|
96 | sources.push(path.join((0, _pathManager().getTemplatePath)("linux"), "electron-icons"));
|
97 | const result = yield packager.resolveIcon(sources, "set");
|
98 | _this.maxIconPath = result[result.length - 1].file;
|
99 | return result;
|
100 | })();
|
101 | }
|
102 |
|
103 | getDescription(options) {
|
104 | return options.description || this.packager.appInfo.description;
|
105 | }
|
106 |
|
107 | writeDesktopEntry(targetSpecificOptions, exec, destination, extra) {
|
108 | var _this2 = this;
|
109 |
|
110 | return (0, _bluebirdLst().coroutine)(function* () {
|
111 | const data = yield _this2.computeDesktopEntry(targetSpecificOptions, exec, extra);
|
112 | const file = destination || (yield _this2.packager.getTempFile(`${_this2.packager.appInfo.productFilename}.desktop`));
|
113 | yield (0, _fsExtraP().outputFile)(file, data);
|
114 | return file;
|
115 | })();
|
116 | }
|
117 |
|
118 | computeDesktopEntry(targetSpecificOptions, exec, extra) {
|
119 | var _this3 = this;
|
120 |
|
121 | return (0, _bluebirdLst().coroutine)(function* () {
|
122 | if (exec != null && exec.length === 0) {
|
123 | throw new Error("Specified exec is empty");
|
124 | }
|
125 |
|
126 | const packager = _this3.packager;
|
127 | const appInfo = packager.appInfo;
|
128 | const productFilename = appInfo.productFilename;
|
129 | const desktopMeta = Object.assign({
|
130 | Name: appInfo.productName,
|
131 | Comment: _this3.getDescription(targetSpecificOptions),
|
132 | Exec: exec == null ? `"${installPrefix}/${productFilename}/${packager.executableName}" %U` : exec,
|
133 | Terminal: "false",
|
134 | Type: "Application",
|
135 | Icon: packager.executableName
|
136 | }, extra, targetSpecificOptions.desktop);
|
137 | const mimeTypes = (0, _builderUtil().asArray)(targetSpecificOptions.mimeTypes);
|
138 |
|
139 | for (const fileAssociation of packager.fileAssociations) {
|
140 | if (fileAssociation.mimeType != null) {
|
141 | mimeTypes.push(fileAssociation.mimeType);
|
142 | }
|
143 | }
|
144 |
|
145 | for (const protocol of (0, _builderUtil().asArray)(packager.config.protocols).concat((0, _builderUtil().asArray)(packager.platformSpecificBuildOptions.protocols))) {
|
146 | for (const scheme of (0, _builderUtil().asArray)(protocol.schemes)) {
|
147 | mimeTypes.push(`x-scheme-handler/${scheme}`);
|
148 | }
|
149 | }
|
150 |
|
151 | if (mimeTypes.length !== 0) {
|
152 | desktopMeta.MimeType = mimeTypes.join(";") + ";";
|
153 | }
|
154 |
|
155 | let category = targetSpecificOptions.category;
|
156 |
|
157 | if ((0, _builderUtil().isEmptyOrSpaces)(category)) {
|
158 | const macCategory = (packager.config.mac || {}).category;
|
159 |
|
160 | if (macCategory != null) {
|
161 | category = macToLinuxCategory[macCategory];
|
162 | }
|
163 |
|
164 | if (category == null) {
|
165 |
|
166 | if (macCategory != null) {
|
167 | _builderUtil().log.warn({
|
168 | macCategory
|
169 | }, "cannot map macOS category to Linux. If possible mapping is known for you, please file issue to add it.");
|
170 | }
|
171 |
|
172 | _builderUtil().log.warn({
|
173 | reason: "linux.category is not set and cannot map from macOS",
|
174 | docs: "https://electron.build/configuration/configuration#LinuxBuildOptions-category"
|
175 | }, "application Linux category is set to default \"Utility\"");
|
176 |
|
177 | category = "Utility";
|
178 | }
|
179 | }
|
180 |
|
181 | desktopMeta.Categories = `${category}${category.endsWith(";") ? "" : ";"}`;
|
182 | let data = `[Desktop Entry]`;
|
183 |
|
184 | for (const name of Object.keys(desktopMeta)) {
|
185 | const value = desktopMeta[name];
|
186 | data += `\n${name}=${value}`;
|
187 | }
|
188 |
|
189 | data += "\n";
|
190 | return data;
|
191 | })();
|
192 | }
|
193 |
|
194 | }
|
195 |
|
196 | exports.LinuxTargetHelper = LinuxTargetHelper;
|
197 | const macToLinuxCategory = {
|
198 | "public.app-category.graphics-design": "Graphics",
|
199 | "public.app-category.developer-tools": "Development",
|
200 | "public.app-category.education": "Education",
|
201 | "public.app-category.games": "Game",
|
202 | "public.app-category.video": "Video;AudioVideo",
|
203 | "public.app-category.utilities": "Utility",
|
204 | "public.app-category.social-networking": "Chat",
|
205 | "public.app-category.finance": "Finance"
|
206 | };
|
207 |
|
\ | No newline at end of file |