Skip to content

Commit ec0bda5

Browse files
committed
feat(Linux): app icon is not required
Close #593
1 parent 150b942 commit ec0bda5

File tree

14 files changed

+95
-32
lines changed

14 files changed

+95
-32
lines changed

src/platformPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
384384
return `${deployment ? this.appInfo.name : this.appInfo.productFilename}-${this.appInfo.version}${classifier == null ? "" : `-${classifier}`}${dotExt}`
385385
}
386386

387-
protected async getDefaultIcon(ext: string) {
387+
async getDefaultIcon(ext: string) {
388388
const resourceList = await this.resourceList
389389
const name = `icon.${ext}`
390390
if (resourceList.includes(name)) {

src/targets/LinuxTargetHelper.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,49 @@ export class LinuxTargetHelper {
3030

3131
// must be name without spaces and other special characters, but not product name used
3232
private async computeDesktopIcons(): Promise<Array<Array<string>>> {
33-
const tempDir = await this.tempDirPromise
34-
try {
35-
const mappings: Array<Array<string>> = []
36-
const pngIconsDir = path.join(this.packager.buildResourcesDir, "icons")
37-
let maxSize = 0
38-
for (let file of (await readdir(pngIconsDir))) {
39-
if (file.endsWith(".png") || file.endsWith(".PNG")) {
40-
// If parseInt encounters a character that is not a numeral in the specified radix,
41-
// it returns the integer value parsed up to that point
42-
try {
43-
const size = parseInt(file!, 10)
44-
if (size > 0) {
45-
const iconPath = `${pngIconsDir}/${file}`
46-
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.appInfo.name}.png`])
47-
48-
if (size > maxSize) {
49-
maxSize = size
50-
this.maxIconPath = iconPath
51-
}
33+
const resourceList = await this.packager.resourceList
34+
if (resourceList.includes("icons")) {
35+
return this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
36+
}
37+
else {
38+
return this.createFromIcns(await this.tempDirPromise)
39+
}
40+
}
41+
42+
private async iconsFromDir(iconsDir: string) {
43+
const mappings: Array<Array<string>> = []
44+
let maxSize = 0
45+
for (let file of (await readdir(iconsDir))) {
46+
if (file.endsWith(".png") || file.endsWith(".PNG")) {
47+
// If parseInt encounters a character that is not a numeral in the specified radix,
48+
// it returns the integer value parsed up to that point
49+
try {
50+
const size = parseInt(file!, 10)
51+
if (size > 0) {
52+
const iconPath = `${iconsDir}/${file}`
53+
mappings.push([iconPath, `${size}x${size}/apps/${this.packager.appInfo.name}.png`])
54+
55+
if (size > maxSize) {
56+
maxSize = size
57+
this.maxIconPath = iconPath
5258
}
5359
}
54-
catch (e) {
55-
console.error(e)
56-
}
60+
}
61+
catch (e) {
62+
console.error(e)
5763
}
5864
}
59-
60-
return mappings
6165
}
62-
catch (e) {
63-
return this.createFromIcns(tempDir)
66+
return mappings
67+
}
68+
69+
private async getIcns(): Promise<string | null> {
70+
const build = this.packager.devMetadata.build
71+
let iconPath = (build.mac || {}).icon || build.icon
72+
if (iconPath != null && !iconPath.endsWith(".icns")) {
73+
iconPath += ".icns"
6474
}
75+
return iconPath == null ? await this.packager.getDefaultIcon("icns") : path.resolve(this.packager.projectDir, iconPath)
6576
}
6677

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

8899
private async createFromIcns(tempDir: string): Promise<Array<Array<string>>> {
89-
const output = await exec("icns2png", ["-x", "-o", tempDir, path.join(this.packager.buildResourcesDir, "icon.icns")])
100+
const iconPath = await this.getIcns()
101+
if (iconPath == null) {
102+
return this.iconsFromDir(path.join(__dirname, "..", "..", "templates", "linux", "electron-icons"))
103+
}
104+
105+
const output = await exec("icns2png", ["-x", "-o", tempDir, iconPath])
90106
debug(output)
91107

92108
//noinspection UnnecessaryLocalVariableJS

src/targets/appImage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export default class AppImageTarget extends TargetEx {
2828
async build(appOutDir: string, arch: Arch): Promise<any> {
2929
const packager = this.packager
3030

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

templates/linux/AppRun.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,28 @@ if [ -z "$SKIP" ] ; then
178178
RESOURCE_NAME=$(echo "$VENDORPREFIX-$DESKTOP_FILE_NAME" | sed -e 's/.desktop//g')
179179
echo "${RESOURCE_NAME}"
180180

181-
# Install the icon files for the application; TODO: scalable
181+
# uninstall previous icons
182+
xdg-icon-resource uninstall --noupdate --size 16 "$RESOURCE_NAME"
183+
xdg-icon-resource uninstall --noupdate --size 24 "$RESOURCE_NAME"
184+
xdg-icon-resource uninstall --noupdate --size 32 "$RESOURCE_NAME"
185+
xdg-icon-resource uninstall --noupdate --size 48 "$RESOURCE_NAME"
186+
xdg-icon-resource uninstall --noupdate --size 64 "$RESOURCE_NAME"
187+
xdg-icon-resource uninstall --noupdate --size 72 "$RESOURCE_NAME"
188+
xdg-icon-resource uninstall --noupdate --size 96 "$RESOURCE_NAME"
189+
xdg-icon-resource uninstall --noupdate --size 128 "$RESOURCE_NAME"
190+
xdg-icon-resource uninstall --noupdate --size 256 "$RESOURCE_NAME"
191+
xdg-icon-resource uninstall --noupdate --size 512 "$RESOURCE_NAME"
192+
xdg-icon-resource uninstall --noupdate --size 1024 "$RESOURCE_NAME"
193+
194+
# Install the icon files for the application
182195
ICONS=$(find "$APPDIR/usr/share/icons/" -path "*/apps/$APP.png" || true)
183196
for ICON in $ICONS ; do
184197
ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
185-
xdg-icon-resource install --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME"
198+
xdg-icon-resource install --noupdate --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME"
186199
done
187200

201+
xdg-icon-resource forceupdate
202+
188203
# Install mime type
189204
find "$APPDIR/usr/share/mime/" -type f -name "*xml" -exec xdg-mime install ${SYSTEM_WIDE} --novendor {} \; || true
190205

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)