Skip to content

Commit

Permalink
feat(Linux): app icon is not required
Browse files Browse the repository at this point in the history
Close #593
  • Loading branch information
develar committed Jul 21, 2016
1 parent 150b942 commit ec0bda5
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return `${deployment ? this.appInfo.name : this.appInfo.productFilename}-${this.appInfo.version}${classifier == null ? "" : `-${classifier}`}${dotExt}`
}

protected async getDefaultIcon(ext: string) {
async getDefaultIcon(ext: string) {
const resourceList = await this.resourceList
const name = `icon.${ext}`
if (resourceList.includes(name)) {
Expand Down
70 changes: 43 additions & 27 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,49 @@ export class LinuxTargetHelper {

// must be name without spaces and other special characters, but not product name used
private async computeDesktopIcons(): Promise<Array<Array<string>>> {
const tempDir = await this.tempDirPromise
try {
const mappings: Array<Array<string>> = []
const pngIconsDir = path.join(this.packager.buildResourcesDir, "icons")
let maxSize = 0
for (let file of (await readdir(pngIconsDir))) {
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 = `${pngIconsDir}/${file}`
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.appInfo.name}.png`])

if (size > maxSize) {
maxSize = size
this.maxIconPath = iconPath
}
const resourceList = await this.packager.resourceList
if (resourceList.includes("icons")) {
return this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
}
else {
return this.createFromIcns(await this.tempDirPromise)
}
}

private async iconsFromDir(iconsDir: string) {
const mappings: Array<Array<string>> = []
let maxSize = 0
for (let file of (await readdir(iconsDir))) {
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}`
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.appInfo.name}.png`])

if (size > maxSize) {
maxSize = size
this.maxIconPath = iconPath
}
}
catch (e) {
console.error(e)
}
}
catch (e) {
console.error(e)
}
}

return mappings
}
catch (e) {
return this.createFromIcns(tempDir)
return mappings
}

private async getIcns(): Promise<string | null> {
const build = this.packager.devMetadata.build
let iconPath = (build.mac || {}).icon || build.icon
if (iconPath != null && !iconPath.endsWith(".icns")) {
iconPath += ".icns"
}
return iconPath == null ? await this.packager.getDefaultIcon("icns") : path.resolve(this.packager.projectDir, iconPath)
}

async computeDesktopEntry(exec?: string, extra?: string): Promise<string> {
Expand All @@ -86,7 +97,12 @@ ${extra == null ? "" : `${extra}\n`}`)
}

private async createFromIcns(tempDir: string): Promise<Array<Array<string>>> {
const output = await exec("icns2png", ["-x", "-o", tempDir, path.join(this.packager.buildResourcesDir, "icon.icns")])
const iconPath = await this.getIcns()
if (iconPath == null) {
return this.iconsFromDir(path.join(__dirname, "..", "..", "templates", "linux", "electron-icons"))
}

const output = await exec("icns2png", ["-x", "-o", tempDir, iconPath])
debug(output)

//noinspection UnnecessaryLocalVariableJS
Expand Down
3 changes: 2 additions & 1 deletion src/targets/appImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default class AppImageTarget extends TargetEx {
async build(appOutDir: string, arch: Arch): Promise<any> {
const packager = this.packager

const image = path.join(this.outDir, packager.generateName("AppImage", arch, false))
// avoid spaces in the file name
const image = path.join(this.outDir, packager.generateName("AppImage", arch, true))
const appInfo = packager.appInfo
await unlinkIfExists(image)

Expand Down
19 changes: 17 additions & 2 deletions templates/linux/AppRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,28 @@ if [ -z "$SKIP" ] ; then
RESOURCE_NAME=$(echo "$VENDORPREFIX-$DESKTOP_FILE_NAME" | sed -e 's/.desktop//g')
echo "${RESOURCE_NAME}"

# Install the icon files for the application; TODO: scalable
# uninstall previous icons
xdg-icon-resource uninstall --noupdate --size 16 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 24 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 32 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 48 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 64 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 72 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 96 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 128 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 256 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 512 "$RESOURCE_NAME"
xdg-icon-resource uninstall --noupdate --size 1024 "$RESOURCE_NAME"

# Install the icon files for the application
ICONS=$(find "$APPDIR/usr/share/icons/" -path "*/apps/$APP.png" || true)
for ICON in $ICONS ; do
ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
xdg-icon-resource install --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME"
xdg-icon-resource install --noupdate --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME"
done

xdg-icon-resource forceupdate

# Install mime type
find "$APPDIR/usr/share/mime/" -type f -name "*xml" -exec xdg-mime install ${SYSTEM_WIDE} --novendor {} \; || true

Expand Down
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates/linux/electron-icons/96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function checkLinuxResult(projectDir: string, packager: Packager, checkOpt
const result: Array<string> = []
for (let target of nameToTarget.keys()) {
if (target === "appimage") {
result.push(`${appInfo.productFilename}-${appInfo.version}-${arch === Arch.x64 ? "x86_64" : Arch[arch]}.AppImage`)
result.push(`${appInfo.name}-${appInfo.version}-${arch === Arch.x64 ? "x86_64" : Arch[arch]}.AppImage`)
}
else {
result.push(`TestApp-${appInfo.version}.${target}`)
Expand Down
7 changes: 7 additions & 0 deletions test/src/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ test.ifDevOrLinuxCi("AppImage", () => assertPack("test-app-one", {
}
))

test.ifDevOrLinuxCi("AppImage - default icon", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget("appimage"),
}, {
tempDirCreated: projectDir => remove(path.join(projectDir, "build"))
},
))

// "apk" is very slow, don't test for now
test.ifDevOrLinuxCi("targets", () => assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(["sh", "freebsd", "pacman", "zip", "7z"]),
Expand Down

0 comments on commit ec0bda5

Please sign in to comment.