spicetify-dynamic-theme icon indicating copy to clipboard operation
spicetify-dynamic-theme copied to clipboard

FYI: Hex editing the spotify binary on linux works to disable forced dark mode.

Open Covkie opened this issue 1 year ago • 1 comments

replacing the string force-dark-mode with an array of null(00) bytes to fill the space works to disable forced dark mode on Linux.

I am assuming the same applies to MacOS.

IMO this should really be an option within spicetify cli. I might pr if I feel bothered :p

Covkie avatar Aug 28 '24 14:08 Covkie

Great finding! Do you think you could write a bash script that does that automatically? Ie find the address and overwrite a few bytes?

JulienMaille avatar Aug 28 '24 15:08 JulienMaille

@JulienMaille Heres a small script to do it:

#!/bin/bash

check_exists() { # Check if required tools are installed/accessible
    if ! command -v "$1" &> /dev/null; then
        echo "Error: $1 not found. Ensure it is installed to your PATH."
        exit 1
    fi
}

check_exists perl
check_exists spicetify

# find where the spotify binary is located
spotify_path=$(spicetify config spotify_path)

# Check if spicetify errors
if [[ $spotify_path == error* ]]; then
    echo $spotify_path
    exit 1
fi

path="${spotify_path}/spotify"

#patch binary
perl -p -i -e "s/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/g" "$path"
echo "Patched! you may now restart Spotify"

Covkie avatar Aug 29 '24 11:08 Covkie

Would sed work the same to avoid requiring Perl on the system? sed -i 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path" I've opened a PR with this option

JulienMaille avatar Aug 29 '24 12:08 JulienMaille

iirc sed can't do binary patching. I'll see in a moment

Also fwiw you can add me as a coauthor on the script commit in that pr

Covkie avatar Aug 29 '24 16:08 Covkie

Sure, let me know how you would like to be mentioned as a coauthor?

JulienMaille avatar Aug 29 '24 16:08 JulienMaille

Okay sed correctly patches & the binary works, awesome!

macos in place sed needs an extra param so use something like this to detect the difference:

    if [[ "$OSTYPE" ==  "darwin"* ]]; then
        sed -i '' 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path"
    else
        sed -i 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path"
    fi

Sure, let me know how you would like to be mentioned as a coauthor?

If you amend the commits with Co-authored-by: Kylie C <[email protected]> It should work iirc

Covkie avatar Aug 29 '24 16:08 Covkie

Here you go, looks good to you?

JulienMaille avatar Aug 29 '24 16:08 JulienMaille

eh good enough :P Oh a mac user should prob double check that it works

Edit: speaking to a mac using friend rn I think $path needs to be platform specific I'll update in a bit

Covkie avatar Aug 29 '24 16:08 Covkie

@JulienMaille Why are you creating that backup? rerunning the script will simply overwrite it with the patched file. Besides the sed is correct and should not result in a corrupt binary. Same for the windows script as well.

Could also be condensed to the sed command as it has a param to edit in place AND create a backup.

Here are the changes for the bak (seems useless imo) & mac path fixes(dirname & sed are installed on macos by default):

#!/bin/bash

# Ensure Spicetify is in PATH
if ! command -v spicetify &> /dev/null; then
    echo "Error: spicetify not found. Ensure it is installed and available in your PATH."
    exit 1
fi

# Find where the Spotify binary is located
spotify_path=$(spicetify config spotify_path)

# Check for spicetify errors
if [[ $spotify_path == error* ]]; then
    echo "Failed to patch the file. $spotify_path"
    exit 1
fi

# Assemble the binary's path
if [[ "$OSTYPE" ==  "darwin"* ]]; then
    _spotify_path=$(dirname "$spotify_path")
    path="${_spotify_path}/MacOS/Spotify"
else
    path="${spotify_path}/spotify"
fi

# Patch binary
sed -i.bak 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path"

echo "The patch is complete. You may now restart Spotify."

Should prob also add some validation to make sure $path is real in case there's an edge case.

Covkie avatar Aug 29 '24 17:08 Covkie

I agree the backup is kinda useless. Do you want to submit your own PR?

JulienMaille avatar Aug 29 '24 18:08 JulienMaille

eh, the pr u made is already open idrc. make the changes u want.

Covkie avatar Aug 29 '24 18:08 Covkie