Skip to content

Commit

Permalink
feat(linux): ability to specify custom path to linux icon set
Browse files Browse the repository at this point in the history
Close #1176
  • Loading branch information
develar committed Jan 31, 2017
1 parent 55e2f0d commit a2f64bb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
8 changes: 5 additions & 3 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ Simplified auto-update is not supported for Squirrel.Windows.

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

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

```js
import {autoUpdater} from "electron-updater"
```
import { autoUpdater } from "electron-updater"
```

Or if you don't use ES6: `const autoUpdater = require("electron-updater").autoUpdater`
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).

Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ On Windows works only if [nsis.perMachine](https://github.com/electron-userland/
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]` for `deb`.
| 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>
| 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>

<a name="MacOptions"></a>
### `mac` macOS Specific Options
Expand Down
6 changes: 6 additions & 0 deletions packages/electron-builder/src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
Cannot be specified per target, allowed only in the `linux`.
*/
readonly executableName?: string | null

/*
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.
By default will be generated automatically based on the macOS icns file.
*/
readonly icon?: string
}

/*
Expand Down
26 changes: 23 additions & 3 deletions packages/electron-builder/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export class LinuxTargetHelper {

// must be name without spaces and other special characters, but not product name used
private async computeDesktopIcons(): Promise<Array<Array<string>>> {
if (this.packager.platformSpecificBuildOptions.icon != null) {
const iconDir = path.resolve(this.packager.buildResourcesDir, this.packager.platformSpecificBuildOptions.icon)
try {
return await this.iconsFromDir(iconDir)
}
catch (e) {
if (e.code === "ENOENT") {
throw new Error(`Icon set directory ${iconDir} doesn't exist`)
}
else {
throw e
}
}
}

const resourceList = await this.packager.resourceList
if (resourceList.includes("icons")) {
return await this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
Expand All @@ -29,17 +44,17 @@ export class LinuxTargetHelper {
}
}

private async iconsFromDir(iconsDir: string) {
private async iconsFromDir(iconDir: string) {
const mappings: Array<Array<string>> = []
let maxSize = 0
for (const file of (await readdir(iconsDir))) {
for (const file of (await readdir(iconDir))) {
if (file.endsWith(".png") || file.endsWith(".PNG")) {
// If parseInt encounters a character that is not a numeral in the specified radix,
// it returns the integer value parsed up to that point
try {
const size = parseInt(file!, 10)
if (size > 0) {
const iconPath = `${iconsDir}/${file}`
const iconPath = `${iconDir}/${file}`
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.executableName}.png`])

if (size > maxSize) {
Expand All @@ -53,6 +68,11 @@ export class LinuxTargetHelper {
}
}
}

if (mappings.length === 0) {
throw new Error(`Icon set directory ${iconDir} doesn't contain icons`)
}

return mappings
}

Expand Down

0 comments on commit a2f64bb

Please sign in to comment.