guillaumeboehm / wal-telegram

A bash script that generates themes for Telegram based on an arbitrary 16-colors palette or by sourcing the colors generated by pywal/wal.
MIT License
48 stars 9 forks source link

Automate the process whenever a new wallpaper is set #14

Closed los2pollos closed 2 years ago

los2pollos commented 2 years ago

Hi, I'm using Cinnamon. I'd like to automate the process. The workflow should be something like this:

  1. A new wallpaper is set (either manually or with an automatic slideshow)
  2. wal-telegram creates a new palette and config file
  3. The config file is automatically loaded in the Telegram client

I was trying to explore the solution provided in #11 but I could not understand it. In particular, I was not able to understand if it addresses the issue I'm bringing right now, or if it is even possible.

P.S. Nice project! It needs to be better documented since it is directly referenced in a much larger one

guillaumeboehm commented 2 years ago

Hi, so to address your points one by one but not in order :

I don't know anything about cinnamon and it's inner workings. You could try to find out if there is a setting somewhere to run a command when the wallpaper changes, you could install a different wallpaper program (although that's not ideal I know). Or you could have a cron job running every couple minutes to run wal-telegram with the current background. apparently it is available with gsettings : https://unix.stackexchange.com/questions/59653/change-desktop-wallpaper-from-terminal

The program is really meant to work with wal, and the way wal sets the background. So event though I try to put some options on it, I feel like it's somewhat expected to have to tinker a bit to get it to work with something else.

I hope that helps you a little, I'd be glad to help you further with the tinkering if you need any help or feel free to close this issue.

los2pollos commented 2 years ago

Hi there, thank you so much for your reply! I'm just not an expert of different DE, I only know about my current Cinnamon setup (see my repos for more info). For the first point, I'm currently using Variety for setting wallpapers automatically. A script should do something like this (taken from my .bashrc):

#---PyWal---#
# load previous theme: this allows for persistence over rebooting
(cat ~/.cache/wal/sequences &)
# get picture path
picturepath=$(gsettings get org.gnome.desktop.background picture-uri) 
# remove prefix & suffix
prefix="'file://"
suffix="'"
picturepath=${picturepath#"$prefix"} 
picturepath=${picturepath%"$suffix"}
# set colors
wal -n -q -i "$picturepath"

#---PyWal End---#

wal-telegram

I suppose that in this specific case, since Cinnamon is based on GNOME, the block with the $picturepath variable should be the core of a script for automating other elements, such as wal-telegram. I guess that variable addresses your 2nd point.

However, since I implemented this scripting in the .bashrc file, the easiest case occurs when the user log in. The sequence in which the changes occur is important. The point is to maybe, as you were suggesting, run a cronjob that runs wal-telegram every now and then and if something changes, it kills the client: not elegant but may do the trick.

Ideas?

guillaumeboehm commented 2 years ago

Yep that is pretty much exactly what I have on my setup, a script that sets a random background and runs wal and all wal related software. It runs on startup, and whenever I change the wallpaper manually I do it through this script. From what I found variety uses some configs, and it appears you can modify the script used when variety runs (in ~/.config/variety). Chances are you can probably make your wal script run from there ? https://peterlevi.com/variety/comment-page-13/#comment-93835 and comments around that gave the idea.

los2pollos commented 2 years ago

Yes! I've edited the following file: ~/.config/variety/scripts/set_wallpaper

gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
if [ "$(gsettings get org.gnome.desktop.background picture-options)" == "'none'" ]; then
    gsettings set org.gnome.desktop.background picture-options 'zoom'

    # Import colorscheme from 'wal' asynchronously
    # &   # Run the process in the background.
    # ( ) # Hide shell job control messages.
    # Not supported in the "fish" shell.
    (cat ~/.cache/wal/sequences &)

    # Alternative (blocks terminal for 0-3ms)
    cat ~/.cache/wal/sequences

    # To add support for TTYs this line can be optionally added.
    source ~/.cache/wal/colors-tty.sh

    wal -n -q -i "$1"
    pywalfox update 
    wal-telegram -w
    pkill telegram-desktop
    telegram-desktop
fi

As explained at the beginning of the file: "$1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper". Terminals and firefox update instantly, whereas telegram is a bit inconsistent. First of all, I have to manually kill the process EVERY single time, killing from the bash does not work. Also, it seems that the theme file in ~/.cache/wal-telegram sometimes does not get generated correctly.

I need more help in troubleshooting.

guillaumeboehm commented 2 years ago

Do you mean the pkill doesn't work in the script ? That's odd. I guess a restart option in wal-telegram seems reasonable so I might do that. As for the theme not generating I'd need a little bit more info, ideally a reproducible context or something. You could also make sure the theme was indeed not regenerated by doing a cmp on the previous and the new file, or comparing their md5sum if you don't want to copy the previous theme.

los2pollos commented 2 years ago

I'm checking md5sums with 'md5sum -b wal.tdesktop-theme' and the file gets actually generated by the terminal. It get also generated by the .bashrc

The problem seems to be in the Variety script 'set_wallpaper'. I've isolated single functions, and none of them work in the set wallpaper script. It is not working but I don't know why. In fact, all the changes that I experienced so far are coming straight from .bashrc, not from the Variety script.

Retr0astic commented 2 years ago

I'm checking md5sums with 'md5sum -b wal.tdesktop-theme' and the file gets actually generated by the terminal. It get also generated by the .bashrc

The problem seems to be in the Variety script 'set_wallpaper'. I've isolated single functions, and none of them work in the set wallpaper script. It is not working but I don't know why. In fact, all the changes that I experienced so far are coming straight from .bashrc, not from the Variety script.

I think the problem is the killing telegram with "pkill telegram-desktop" for me only "pkill telegram-deskto" works, without the 'p'.Must be a typo by tg devs. I'm on arch btw,

guillaumeboehm commented 2 years ago

You could try to make sure that the set_wallpaper script in .config is indeed called on the variety runs, like jamming an output to a tmp file in or something. I guess it is possible that some other script somewhere else is getting called instead. If the script is not being called I'd suggest you to turn to the variety team, if it is being called however maybe check that your piece of code is correct, for example I doubt (shot in the dark) that you'd have to use the if clause with the picture options. To me this would make your code run at most only once on first call of set_wallpaper and never afterwards. I'd also recommend to put all your code related to wal in a little script so that it is more convenient to make modifications. Oh hello good timing ^^

guillaumeboehm commented 2 years ago

I think the problem is the killing telegram with "pkill telegram-desktop" for me only "pkill telegram-deskto" works, without the 'p'.Must be a typo by tg devs. I'm on arch btw,

Oh you're not OP xD I think executable names get cropped after some length you'd have to use pkill -f to match the full command line I believe.

los2pollos commented 2 years ago

You could try to make sure that the set_wallpaper script in .config is indeed called on the variety runs, like jamming an output to a tmp file in or something. I guess it is possible that some other script somewhere else is getting called instead. If the script is not being called I'd suggest you to turn to the variety team, if it is being called however maybe check that your piece of code is correct, for example I doubt (shot in the dark) that you'd have to use the if clause with the picture options. To me this would make your code run at most only once on first call of set_wallpaper and never afterwards. I'd also recommend to put all your code related to wal in a little script so that it is more convenient to make modifications. Oh hello good timing ^^

Thank you for the help, very good suggestions. What do you mean with "jamming an output to a tmp file"? I'm not an expert in bash

I think executable names get cropped after some length you'd have to use pkill -f to match the full command line I believe. I indeed already explored this and I confirm your assumptions

Lastly, another point to consider is that there are the same folders and files both in ~/.config/variety and in /usr/share/variety. What do you think is the difference? I tried to edit both, but nothing changed

guillaumeboehm commented 2 years ago

What do you mean with "jamming an output to a tmp file"? I'm not an expert in bash

You can put something like echo "running" >> /tmp/variety.log anywhere in the set_wallpaper script, or well outside any clauses I suppose, so before the gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null line should do for example. Then check the /tmp/variety.log file if it exists and has as many running as the number of times variety ran it means the script is called.

Lastly, another point to consider is that there are the same folders and files both in ~/.config/variety and in /usr/share/variety. What do you think is the difference? I tried to edit both, but nothing changed

Yeah so that could be part of the problem, usually configs in /usr/share/ are default configs in case no config is set in ~/.config/, at least from my understanding ^^ I hope I'm not saying crap. But it should use ~/.config in priority. You can try the test I just mentioned in the config of /usr/share if the one in ~/.config doesn't seem to run.

los2pollos commented 2 years ago

Thank you so much for your help so far. I'm getting closer and closer. Basically it is indeed enough to tinker with those two script files and make them execute a third sh script (I called it custom.sh) Anyway, regarding wal-telegram, I keep getting this from the telegram client:

(telegram-desktop:160058): Gtk-WARNING **: 21:13:34.504: Locale not supported by C library.
Using the fallback 'C' locale.
[E] pw.loop [loop.c:86 pw_loop_new()] 0x7f62c3565870: can't make support.system handle: No such file or directory
[ALSOFT] (EE) Failed to create PipeWire event thread loop (errno: 2)
/usr/share/libdrm/amdgpu.ids: No such file or directory
error: : cannot open
error: : cannot open
error: : cannot open
qt.svg: Error while inflating gzip file: SVG format check failed

What is this? The theme is not getting applied

guillaumeboehm commented 2 years ago

Thank you so much for your help so far. I'm getting closer and closer. Basically it is indeed enough to tinker with those two script files and make them execute a third sh script (I called it custom.sh)

I really don't think it is necessary to modify both of them, only one should do it I just don't know which one. This would avoid you to have duplication that can become a bit of a headache.

Anyway, regarding wal-telegram, I keep getting this from the telegram client:

I am not too sure, I hope it isn't some problem with pipewire because I have no idea how it works. I see there is some output about svg though, is your wallpaper an svg ? Because I am pretty sure this is not supported, if it is the case try with a png background to see if it works. I am actually going to make the program convert any wallpaper to png for the theme so this won't be a problem.

EDIT: SVG should work on the newer version and I added the -r option for restarting telegram

guillaumeboehm commented 2 years ago

Also I opened an issue on tdesktop for the interface reload problem: https://github.com/telegramdesktop/tdesktop/issues/24675 You can go react to it if you want, it might slightly push up the priority.

los2pollos commented 2 years ago

Hey, for anyone out there looking for the same answer: in order to seamlessly automate the adjusting of colors, only a few files must be edited.

  1. Create your custom script under ~/.config/variety/scripts/. Make sure it is an executable bash file with chmod +x
  2. Reference your custom script in get_wallpaper. This will make sure that the first time that variety is launched, the custom script will be launched as well.
  3. Edit /usr/lib/python3/dist-packages/variety/VarietyWindow.py at line 1466. Put some os.system('bash ~/.config/variety/scripts/custom.sh'). This will run your custom script whenever a new wallpaper is set. Basically there are two functions: set_wallpaper() and do_set_wp(). The first one just calls the script set_wallpaper in the script folder, but it is actually the second one that effectively applies the changes. Unfortunately, the set_wallpaper script only applies AFTER the wallpaper is set. I haven't really figured out its purpose, but referencing the custom script in this file will only get delayed effects and the palette generated by wal is based on the previous wallpaper changed.
los2pollos commented 2 years ago

SVG should work on the newer version and I added the -r option for restarting telegram

Great! I'll test it out right away.

Also I opened an issue on tdesktop for the interface reload problem: telegramdesktop/tdesktop#24675 You can go react to it if you want, it might slightly push up the priority.

Sounds good!

los2pollos commented 2 years ago

We can close the issue as soon as the new telegram-desktop snap package is released. Thx

guillaumeboehm commented 2 years ago

The autoreload feature made it to https://github.com/telegramdesktop/tdesktop/releases/tag/v4.0.1, closing the issue.