From 46e9a0e494ca7d14221139296d66c2c64c222430 Mon Sep 17 00:00:00 2001 From: Yury Shvedov Date: Tue, 30 Jan 2024 20:59:19 +0300 Subject: [PATCH 1/5] Add some style fixes for shell scripts * use `mktemp -d` for temporary files * use trap to remove temporary files * fix some shellcheck warnings Change-Id: Ib73f5a52d7bcd21232e7ef31a815c28a06dcd857 --- generate_packages.sh | 22 ++++++++------ nix/default.nix | 3 +- repack.sh | 72 ++++++++++++++++++++------------------------ 3 files changed, 46 insertions(+), 51 deletions(-) diff --git a/generate_packages.sh b/generate_packages.sh index cd7f573..0bad55a 100644 --- a/generate_packages.sh +++ b/generate_packages.sh @@ -1,21 +1,27 @@ #!/bin/bash -mkdir -p ./tmp +set -e + +clear() { + rm -rf "$TEMPDIR" +} +TEMPDIR="$(mktemp -d)" +trap clear EXIT # loading json from file https://music-desktop-application.s3.yandex.net/stable/download.json -curl -s https://music-desktop-application.s3.yandex.net/stable/download.json > ./tmp/download.json +curl -s https://music-desktop-application.s3.yandex.net/stable/download.json > "$TEMPDIR"/download.json -exe_link=$(jq -r '.windows' ./tmp/download.json) -version=$(echo $exe_link | grep -oP '(?<=x64_).*(?=.exe)') -exe_name=$(basename $exe_link) +exe_link=$(jq -r '.windows' "$TEMPDIR"/download.json) +version="$(echo "$exe_link" | grep -oP '(?<=x64_).*(?=.exe)')" +exe_name="$(basename "$exe_link")" echo "Windows url: $exe_link" echo "Version: $version" echo "Exe name: $exe_name" -curl $exe_link > ./tmp/$exe_name +curl "$exe_link" > "$TEMPDIR/$exe_name" -exe_sha256=$(sha256sum ./tmp/$exe_name | awk '{print $1}') +exe_sha256="$(sha256sum "$TEMPDIR/$exe_name" | awk '{print $1}')" echo "Exe sha256: $exe_sha256" @@ -36,5 +42,3 @@ sed -i "s#%release%#1#g" ./PKGBUILD sed -i "s#%exe_name%#$exe_name#g" ./PKGBUILD sed -i "s#%exe_link%#$exe_link#g" ./PKGBUILD sed -i "s#%exe_sha256%#$exe_sha256#g" ./PKGBUILD - -rm -rf ./tmp \ No newline at end of file diff --git a/nix/default.nix b/nix/default.nix index 06eee8d..97784c3 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -18,8 +18,7 @@ let repack = ./../repack.sh; src = ymExe; } '' - bash "$repack" -x "$src" - mv ./app "$out" + bash "$repack" -x -o "$out" "$src" ''; launcher = writeShellApplication { name = "yandex-music"; diff --git a/repack.sh b/repack.sh index ef3a92e..14c7ca1 100755 --- a/repack.sh +++ b/repack.sh @@ -1,38 +1,22 @@ #!/bin/bash set -e -prompt_yes_no() { - local question="$1" - local response - while true; do - read -rp "$question (y/n): " response - case $response in - [Yy]*) - return 0 # Returning success status code - ;; - [Nn]*) - return 1 # Returning failure status code - ;; - *) - echo "Please enter 'y' (yes) or 'n' (no)." - ;; - esac - done -} usage() { - echo "Usage: $(basename "$0") [-xh] YANDEX_MUSIC_EXE" + echo "Usage: $(basename "$0") [-xh] [ -o DIR] YANDEX_MUSIC_EXE" echo echo " Options:" - echo " -x Extract and fix only to ./app folder" + echo " -o DIR Path to destination folder" + echo " -x Extract and fix only to destination folder" echo " -h Show this help and exit" } -extract_only= exe_location= -while getopts :xh name; do +dst="$PWD/app" +while getopts :xo:h name; do case $name in x) extract_only=1 ;; + o) dst="$OPTARG" ;; h) usage exit 0 @@ -56,18 +40,27 @@ if [ -z "$exe_location" ]; then exit 1 fi -# unpacking -7z x "$exe_location" -oExtracted -cp "./Extracted/\$PLUGINSDIR/app-64.7z" "./app-64.7z" -rm -rf ./Extracted -7z x "./app-64.7z" -oExtracted -cp "./Extracted/resources/app.asar" "./app.asar" -rm -rf ./Extracted -rm ./app-64.7z -asar extract "./app.asar" "./app" -rm "./app.asar" +clear() { + rm -rf "$TEMPDIR" +} +TEMPDIR="$(mktemp -d)" +trap clear EXIT -cd ./app + +EXTRACTED="$TEMPDIR/Extracted" +# unpacking +7z x "$exe_location" -o"$EXTRACTED" +mv "$EXTRACTED/\$PLUGINSDIR/app-64.7z" "$TEMPDIR/app-64.7z" +rm -rf "$EXTRACTED" +7z x "$TEMPDIR/app-64.7z" -o"$EXTRACTED" +mv "$EXTRACTED/resources/app.asar" "$TEMPDIR/app.asar" +rm -rf "$EXTRACTED" +rm "$TEMPDIR/app-64.7z" +asar extract "$TEMPDIR/app.asar" "$TEMPDIR/app" +rm "$TEMPDIR/app.asar" + +curdir="$PWD" +cd "$TEMPDIR/app" # fixing secretKey issue echo "Fixing SecretKey" @@ -97,22 +90,21 @@ fi jq --arg license "UNLICENSED" '. + {license: $license}' package.json > tmp_package.json mv tmp_package.json package.json echo "Updated license field in package.json" -version=$(jq -r .version package.json) jq '. + {icon: {"48x48": "build/next-desktop/favicon.png", "scalable": "build/next-desktop/favicon.svg"}}' package.json > tmp_package.json mv tmp_package.json package.json echo "Updated icon field in package.json" if [ -n "$extract_only" ]; then + mkdir -p "$(dirname "$dst")" + mv "$TEMPDIR/app" "$dst" exit 0 fi -cd ../ -mkdir -p out +mkdir -p "$dst" echo "Packing" -asar pack "./app" "./out/yandexmusic.asar" +cd "$curdir" +asar pack "$TEMPDIR/app" "$dst/yandexmusic.asar" -rm -rf ./app - -echo "Done" \ No newline at end of file +echo "Done" From 209cedb1aee9545ddfeca1dc7289f96eaed66de4 Mon Sep 17 00:00:00 2001 From: Yury Shvedov Date: Tue, 30 Jan 2024 21:21:59 +0300 Subject: [PATCH 2/5] Reuse icon from sources Change-Id: I5fb61daa29b4a2f1fb0074fc4ac9d4a9bf4a550b --- repack.sh | 3 +++ templates/PKGBUILD | 4 ++-- templates/icon.png | Bin 544 -> 0 bytes 3 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 templates/icon.png diff --git a/repack.sh b/repack.sh index 14c7ca1..eddff1b 100755 --- a/repack.sh +++ b/repack.sh @@ -106,5 +106,8 @@ mkdir -p "$dst" echo "Packing" cd "$curdir" asar pack "$TEMPDIR/app" "$dst/yandexmusic.asar" +for ext in png svg; do + mv "$TEMPDIR/app/build/next-desktop/favicon.$ext" "$dst" +done echo "Done" diff --git a/templates/PKGBUILD b/templates/PKGBUILD index d61bc9e..911b10d 100644 --- a/templates/PKGBUILD +++ b/templates/PKGBUILD @@ -27,12 +27,12 @@ package() { mkdir -p "$pkgdir/usr/bin" install -Dm644 "$srcdir/out/yandexmusic.asar" "$pkgdir/usr/lib/yandexmusic/yandexmusic.asar" + install -Dm644 "$srcdir/out/favicon.png" "$pkgdir/usr/share/pixmaps/yandexmusic.png" install -Dm644 "$srcdir/yandex-music-linux/templates/desktop" "$pkgdir/usr/share/applications/yandexmusic.desktop" install -Dm644 "$srcdir/yandex-music-linux/LICENSE.md" "$pkgdir/usr/share/licenses/$pkgname/LICENSE" - install -Dm644 "$srcdir/yandex-music-linux/templates/icon.png" "$pkgdir/usr/share/pixmaps/yandexmusic.png" # Create a script to launch the app with Electron echo "#!/bin/sh" > "$pkgdir/usr/bin/yandexmusic" - echo "electron /usr/lib/yandexmusic/yandexmusic.asar" >> "$pkgdir/usr/bin/yandexmusic" + echo 'exec electron /usr/lib/yandexmusic/yandexmusic.asar "$@"' >> "$pkgdir/usr/bin/yandexmusic" chmod 755 "$pkgdir/usr/bin/yandexmusic" } diff --git a/templates/icon.png b/templates/icon.png deleted file mode 100644 index 09c94c6384e553a281aa50afc8e27645c9ca8017..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 544 zcmV+*0^j|KP)U(P5Dfxdrt#N>-G8 zO}}U*-Qo05lkO{}MVBO&#(*5sOApbOP*CZ`niPCYcqFH^(d&k%KrbN$2jfu#^tEjc z2ePo>A`X_%sZ|jY`zJF4P*et6w*gg@w*+>>#O#H60gE8Kh(V%qp2Rf+!-N0Vj2PG&L@*OaRq zN0T)m!ZVY<>g!is6pHs7nbxjF=Gc5^n*!4@`WO0^K&qUWh6eutnGc&A0vqz&n}}SR iX}ea}{ZG){_v#mqUkgmP0!kqO0000 Date: Tue, 30 Jan 2024 21:22:30 +0300 Subject: [PATCH 3/5] [nix] Switch to asar package Change-Id: I9ebb37518ae9db6d6c838f9445dacefa66c2935a --- nix/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 97784c3..aa9927d 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -18,13 +18,13 @@ let repack = ./../repack.sh; src = ymExe; } '' - bash "$repack" -x -o "$out" "$src" + bash "$repack" -o "$out" "$src" ''; launcher = writeShellApplication { name = "yandex-music"; runtimeInputs = [ electron ]; text = '' - electron ${app} "$@" + electron ${app}/yandexmusic.asar "$@" ''; }; desktopItem = makeDesktopItem { @@ -33,7 +33,7 @@ let comment = "Yandex Music - we collect music for you"; exec = "${launcher}/bin/yandex-music"; terminal = false; - icon = "${app}/build/next-desktop/favicon.svg"; + icon = "${app}/favicon.svg"; categories = [ "Audio" "Music" "Player" "AudioVideo" ]; extraConfig = { "Name[ru]" = "Яндекс Музыка"; From a75f59cd800e05f682d5b721f016c63e87deba94 Mon Sep 17 00:00:00 2001 From: Yury Shvedov Date: Tue, 30 Jan 2024 21:32:35 +0300 Subject: [PATCH 4/5] Add do not fix quit flag Electron is quite unoptimised technology and running YM window in foreground requires a lot of cpu usage. So hiding window to background is more feature, then bug =) Change-Id: Id4e00303379004b6353a88efd7232e180f80fe6d --- flake.nix | 3 +++ nix/default.nix | 3 ++- repack.sh | 14 ++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 3368976..24f4a8a 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,9 @@ { packages = rec { yandex-music = yandex-music-with pkgs; + yandex-music-backgroud = yandex-music.override { + fixQuit = false; + }; default = yandex-music; }; } diff --git a/nix/default.nix b/nix/default.nix index aa9927d..47b1a5d 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -10,6 +10,7 @@ , jq , ymExe +, fixQuit ? true }: let app = runCommand "yandex-music-app" @@ -18,7 +19,7 @@ let repack = ./../repack.sh; src = ymExe; } '' - bash "$repack" -o "$out" "$src" + bash "$repack" ${if !fixQuit then "-q" else ""} -o "$out" "$src" ''; launcher = writeShellApplication { name = "yandex-music"; diff --git a/repack.sh b/repack.sh index eddff1b..16dd3b3 100755 --- a/repack.sh +++ b/repack.sh @@ -3,20 +3,23 @@ set -e usage() { - echo "Usage: $(basename "$0") [-xh] [ -o DIR] YANDEX_MUSIC_EXE" + echo "Usage: $(basename "$0") [-xqh] [ -o DIR] YANDEX_MUSIC_EXE" echo echo " Options:" echo " -o DIR Path to destination folder" echo " -x Extract and fix only to destination folder" + echo " -q Do not apply application quit fix" echo " -h Show this help and exit" } exe_location= dst="$PWD/app" -while getopts :xo:h name; do +fix_quit=1 +while getopts :xo:qh name; do case $name in x) extract_only=1 ;; o) dst="$OPTARG" ;; + q) fix_quit=0 ;; h) usage exit 0 @@ -79,8 +82,11 @@ find "./" -type f -name "*.html" -print0 | while IFS= read -r -d $'\0' file; do done echo "Title Fixed" -echo "Fixing App Quiting" -sed -i "s/window.on('close', (event) => {/window.on('close', (event) => {electron_1.app.quit();/g" "./main/lib/handlers/handleWindowLifecycleEvents.js" +if [ "$fix_quit" == "1" ]; then + echo "Fixing App Quiting" + sed -i "s/window.on('close', (event) => {/window.on('close', (event) => {electron_1.app.quit();/g" \ + "./main/lib/handlers/handleWindowLifecycleEvents.js" +fi if ! command -v jq &>/dev/null; then echo "Error: jq is not installed. Please install jq to proceed." >&2 From 93364eb2f536f317dfb3bd5208c97de638dfb9c5 Mon Sep 17 00:00:00 2001 From: Yury Shvedov Date: Tue, 30 Jan 2024 21:49:43 +0300 Subject: [PATCH 5/5] [nix] Bump to 5.0.8 Change-Id: I0a02b2cb0d3ccf75f0c6cd6c267f10e38f0f43a3 --- flake.lock | 6 +++--- flake.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index b0240ef..65b45f8 100644 --- a/flake.lock +++ b/flake.lock @@ -56,13 +56,13 @@ "ymExe": { "flake": false, "locked": { - "narHash": "sha256-JEtqtRkBhbUN7+rcVzTrf2DjaIgr4MwSpunQPDV9/O0=", + "narHash": "sha256-HeqFJ+hY/8TjViz6SjfklMoVpX6+54pL0Vl1cI1Qlkw=", "type": "file", - "url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.7.exe" + "url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.8.exe" }, "original": { "type": "file", - "url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.7.exe" + "url": "https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.8.exe" } } }, diff --git a/flake.nix b/flake.nix index 24f4a8a..c16f73a 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Native Yandex Music desktop client"; inputs = { ymExe = { - url = https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.7.exe; + url = https://music-desktop-application.s3.yandex.net/stable/Yandex_Music_x64_5.0.8.exe; flake = false; }; };