Skip to content

Commit a2f64bb

Browse files
committed
feat(linux): ability to specify custom path to linux icon set
Close #1176
1 parent 55e2f0d commit a2f64bb

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

docs/Auto Update.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ Simplified auto-update is not supported for Squirrel.Windows.
1010

1111
2. [Configure publish](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#PublishConfiguration).
1212

13-
3. Use `autoUpdater` from `electron-updater` instead of `electron`, e.g. (ES 6):
13+
3. Use `autoUpdater` from `electron-updater` instead of `electron`:
1414

1515
```js
16-
import {autoUpdater} from "electron-updater"
17-
```
16+
import { autoUpdater } from "electron-updater"
17+
```
18+
19+
Or if you don't use ES6: `const autoUpdater = require("electron-updater").autoUpdater`
1820
1921
4. Do not call `setFeedURL`. electron-builder automatically creates `app-update.yml` file for you on build in the `resources` (this file is internal, you don't need to be aware of it).
2022

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ On Windows works only if [nsis.perMachine](https://github.com/electron-userland/
133133
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
134134
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]` for `deb`.
135135
| executableName | <a name="LinuxBuildOptions-executableName"></a><p>The executable name. Defaults to <code>productName</code>.</p> <p>Cannot be specified per target, allowed only in the <code>linux</code>.</p>
136+
| icon | <a name="LinuxBuildOptions-icon"></a><p>The path to icon set directory, relative to <code>build</code> (build resources directory). The icon filename must contain the size (e.g. 32x32.png) of the icon. By default will be generated automatically based on the macOS icns file.</p>
136137

137138
<a name="MacOptions"></a>
138139
### `mac` macOS Specific Options

packages/electron-builder/src/options/linuxOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
6868
Cannot be specified per target, allowed only in the `linux`.
6969
*/
7070
readonly executableName?: string | null
71+
72+
/*
73+
The path to icon set directory, relative to `build` (build resources directory). The icon filename must contain the size (e.g. 32x32.png) of the icon.
74+
By default will be generated automatically based on the macOS icns file.
75+
*/
76+
readonly icon?: string
7177
}
7278

7379
/*

packages/electron-builder/src/targets/LinuxTargetHelper.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ export class LinuxTargetHelper {
1818

1919
// must be name without spaces and other special characters, but not product name used
2020
private async computeDesktopIcons(): Promise<Array<Array<string>>> {
21+
if (this.packager.platformSpecificBuildOptions.icon != null) {
22+
const iconDir = path.resolve(this.packager.buildResourcesDir, this.packager.platformSpecificBuildOptions.icon)
23+
try {
24+
return await this.iconsFromDir(iconDir)
25+
}
26+
catch (e) {
27+
if (e.code === "ENOENT") {
28+
throw new Error(`Icon set directory ${iconDir} doesn't exist`)
29+
}
30+
else {
31+
throw e
32+
}
33+
}
34+
}
35+
2136
const resourceList = await this.packager.resourceList
2237
if (resourceList.includes("icons")) {
2338
return await this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
@@ -29,17 +44,17 @@ export class LinuxTargetHelper {
2944
}
3045
}
3146

32-
private async iconsFromDir(iconsDir: string) {
47+
private async iconsFromDir(iconDir: string) {
3348
const mappings: Array<Array<string>> = []
3449
let maxSize = 0
35-
for (const file of (await readdir(iconsDir))) {
50+
for (const file of (await readdir(iconDir))) {
3651
if (file.endsWith(".png") || file.endsWith(".PNG")) {
3752
// If parseInt encounters a character that is not a numeral in the specified radix,
3853
// it returns the integer value parsed up to that point
3954
try {
4055
const size = parseInt(file!, 10)
4156
if (size > 0) {
42-
const iconPath = `${iconsDir}/${file}`
57+
const iconPath = `${iconDir}/${file}`
4358
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.executableName}.png`])
4459

4560
if (size > maxSize) {
@@ -53,6 +68,11 @@ export class LinuxTargetHelper {
5368
}
5469
}
5570
}
71+
72+
if (mappings.length === 0) {
73+
throw new Error(`Icon set directory ${iconDir} doesn't contain icons`)
74+
}
75+
5676
return mappings
5777
}
5878

0 commit comments

Comments
 (0)