From 99f387e462b16d38069168750e5dfbfa1211df55 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 10 Mar 2022 13:36:30 +0100 Subject: [PATCH 1/9] desktopToDarwinBundle: Fixup Exec The "Exec" key in desktop items sometimes has one of the `%f`, `%F`, `%u` and `%U` suffixes, which specify whether the command takes a file, multiple files or a generalized URL or URLs. Darwin application bundles do no understand this syntax so we do the next best thing, which is simply dropping it. --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index d54af90b6888..b4d1b7a6bc05 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -176,7 +176,7 @@ convertDesktopFile() { local -r file=$1 local -r sharePath=$(dirname "$(dirname "$file")") local -r name=$(getDesktopParam "${file}" "^Name") - local -r exec=$(getDesktopParam "${file}" "Exec") + local -r exec=$(getDesktopParam "${file}" "Exec" | sed -e 's/ %[fFuU]$//') local -r iconName=$(getDesktopParam "${file}" "^Icon") local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon") From b52a9621412ab6b2b12885f3875a7a956d4ab46a Mon Sep 17 00:00:00 2001 From: toonn Date: Fri, 11 Mar 2022 20:56:44 +0100 Subject: [PATCH 2/9] desktopToDarwinBundle: Complete field code removal Checked the desktop entry spec, there's other field codes than `%[fFuU]` and those can in fact occur more than once, hence dropping '$' and adding `/g`. --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index b4d1b7a6bc05..0bc454ecc909 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -176,7 +176,8 @@ convertDesktopFile() { local -r file=$1 local -r sharePath=$(dirname "$(dirname "$file")") local -r name=$(getDesktopParam "${file}" "^Name") - local -r exec=$(getDesktopParam "${file}" "Exec" | sed -e 's/ %[fFuU]$//') + local -r exec=$(getDesktopParam "${file}" "Exec" \ + | sed -e 's/ %[fFuUick]//g') local -r iconName=$(getDesktopParam "${file}" "^Icon") local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon") From 7ef15c96dc6180295d46efb0a0a4f1dd5b0b687a Mon Sep 17 00:00:00 2001 From: toonn Date: Fri, 11 Mar 2022 21:52:28 +0100 Subject: [PATCH 3/9] desktopToDarwinBundle: Add X-macOS-Exec and log editing Exec Co-authored-by: milahu --- .../setup-hooks/desktop-to-darwin-bundle.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index 0bc454ecc909..5bd71764c617 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -176,8 +176,16 @@ convertDesktopFile() { local -r file=$1 local -r sharePath=$(dirname "$(dirname "$file")") local -r name=$(getDesktopParam "${file}" "^Name") - local -r exec=$(getDesktopParam "${file}" "Exec" \ - | sed -e 's/ %[fFuUick]//g') + local -r macOSExec=$(getDesktopParam "${file}" "X-macOS-Exec") + if [[ "$macOSExec" ]]; then + local -r exec="$macOSExec" + else + local -r execRaw=$(getDesktopParam "${file}" "Exec") + local -r exec="${execRaw// %[fFuUick]}" + if [[ "$exec" != "$execRaw" ]]; then + echo "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." + fi + fi local -r iconName=$(getDesktopParam "${file}" "^Icon") local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon") From 30e8e0a9a3b11e06f0aed76e25ae5fdd73f833de Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 31 Mar 2022 12:45:33 +0200 Subject: [PATCH 4/9] desktopToDarwinBundle: Change empty directory test `ls -1 "$iconsdir/"*` listed the source directory for me when the glob had no matches. Switching to `-A` circumvents this problem and has the added advantage that it cannot run into argument list length limits. --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index 5bd71764c617..b1364db06107 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -163,7 +163,7 @@ convertIconTheme() { } iconsdir=$(getIcons "$sharePath" "apps/${iconName}" "$theme") - if [[ -n "$(ls -1 "$iconsdir/"*)" ]]; then + if [[ -n "$(ls -A1 "$iconsdir")" ]]; then icnsutil compose --toc "$out/${iconName}.icns" "$iconsdir/"* else echo "Warning: no icons were found. Creating an empty icon for ${iconName}.icns." From 4a749a89c453551e107567cdf5d80165383b537f Mon Sep 17 00:00:00 2001 From: toonn Date: Wed, 30 Mar 2022 20:36:23 +0200 Subject: [PATCH 5/9] desktopToDarwinBundle: Implement %k Exec field code --- .../setup-hooks/desktop-to-darwin-bundle.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index b1364db06107..7ce6c5c82b73 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -171,6 +171,17 @@ convertIconTheme() { fi } +processExecFieldCodes() { + local -r file=$1 + local -r execRaw=$(getDesktopParam "${file}" "Exec") + local -r execNoK="${execRaw/\%k/${file}}" + local -r exec="${execNoK// %[fFuUic]}" + if [[ "$exec" != "$execRaw" ]]; then + echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." + fi + echo "$exec" +} + # For a given .desktop file, generate a darwin '.app' bundle for it. convertDesktopFile() { local -r file=$1 @@ -180,11 +191,7 @@ convertDesktopFile() { if [[ "$macOSExec" ]]; then local -r exec="$macOSExec" else - local -r execRaw=$(getDesktopParam "${file}" "Exec") - local -r exec="${execRaw// %[fFuUick]}" - if [[ "$exec" != "$execRaw" ]]; then - echo "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." - fi + local -r exec=$(processExecFieldCodes "${file}") fi local -r iconName=$(getDesktopParam "${file}" "^Icon") local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon") From 4dc94e1489fd7045e4b898996cecfbf28ed87ab3 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 31 Mar 2022 13:00:11 +0200 Subject: [PATCH 6/9] desktopToDarwinBundle: Implement %c Exec field code --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index 7ce6c5c82b73..5b8a4d0e90fb 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -175,7 +175,8 @@ processExecFieldCodes() { local -r file=$1 local -r execRaw=$(getDesktopParam "${file}" "Exec") local -r execNoK="${execRaw/\%k/${file}}" - local -r exec="${execNoK// %[fFuUic]}" + local -r execNoKC="${execNoK/\%c/$(getDesktopParam "${file}" "Name")}" + local -r exec="${execNoKC// %[fFuUi]}" if [[ "$exec" != "$execRaw" ]]; then echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." fi From 196f989ae88a13210720cb08d53a57c5c05481a0 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 31 Mar 2022 13:44:15 +0200 Subject: [PATCH 7/9] desktopToDarwinBundle: Implement %i Exec field code --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index 5b8a4d0e90fb..92c790e9907f 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -176,7 +176,9 @@ processExecFieldCodes() { local -r execRaw=$(getDesktopParam "${file}" "Exec") local -r execNoK="${execRaw/\%k/${file}}" local -r execNoKC="${execNoK/\%c/$(getDesktopParam "${file}" "Name")}" - local -r exec="${execNoKC// %[fFuUi]}" + local -r icon=$(getDesktopParam "${file}" "Icon") + local -r execNoKCI="${execNoKC/\%i/${icon:+--icon }${icon}}" + local -r exec="${execNoKCI// %[fFuU]}" if [[ "$exec" != "$execRaw" ]]; then echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." fi From f31d9457551315abad6174c08646e39e09f8db70 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 31 Mar 2022 14:04:52 +0200 Subject: [PATCH 8/9] desktopToDarwinBundle: Implement %f and %u Exec field codes `%f` and `%u` are used to signal the program only accepts a single file or URI argument. I do not believe there's a way to signal this information to macOS but it is possible the program really won't work if multiple files are passed and it's possible the relative position of `%i`, `%c` or `%k` matters. So we replace `%f` or `%u` with `$1`. That way we only pass one file in the (possibly significant) position of the field code. --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index 92c790e9907f..b181ec1dc63e 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -178,7 +178,8 @@ processExecFieldCodes() { local -r execNoKC="${execNoK/\%c/$(getDesktopParam "${file}" "Name")}" local -r icon=$(getDesktopParam "${file}" "Icon") local -r execNoKCI="${execNoKC/\%i/${icon:+--icon }${icon}}" - local -r exec="${execNoKCI// %[fFuU]}" + local -r execNoKCIfu="${execNoKCI/\%[fu]/\$1}" + local -r exec="${execNoKCIfu// %[FU]}" if [[ "$exec" != "$execRaw" ]]; then echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." fi From 261b73652131421cd562873191060b02b56db1fe Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 31 Mar 2022 15:27:39 +0200 Subject: [PATCH 9/9] desktopToDarwinBundle: Implement %F and %U Exec field codes Similar to the implementation of the `%f` and `%u` field codes. In this case the amount of arguments passed poses no problem but the position could, at least in theory. This finishes the implementation of all the non-deprecated field codes. As a part of that, repetitions of field codes are left alone. Originally all field codes were removed. Now we replace only the first occurence. This is correct for at least `%f`, `%u`, `%F` and `%U` because at most one of them is permitted. Shortcomings: 1. We replace `%[cfFikuU]` patterns one at a time. This means if the right field code appears as part of the rest of the `Exec` field or in a field code that was substituted earlier. 2. If any field code is repeated, only the first occurence is substituted. --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index b181ec1dc63e..72c1b973666e 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -179,7 +179,7 @@ processExecFieldCodes() { local -r icon=$(getDesktopParam "${file}" "Icon") local -r execNoKCI="${execNoKC/\%i/${icon:+--icon }${icon}}" local -r execNoKCIfu="${execNoKCI/\%[fu]/\$1}" - local -r exec="${execNoKCIfu// %[FU]}" + local -r exec="${execNoKCIfu/\%[FU]/\$@}" if [[ "$exec" != "$execRaw" ]]; then echo 1>&2 "desktopToDarwinBundle: Application bundles do not understand desktop entry field codes. Changed '$execRaw' to '$exec'." fi