mirror of
https://github.com/anufrievroman/waypaper.git
synced 2024-07-14 19:30:31 +03:00
Reworking how killing backends works
Instead of killing processes, we now first check if they are running with pgrep. This makes the terminal output cleaner, without constant errors about not running backends.
This commit is contained in:
parent
fdbbe205b5
commit
0028234011
@ -12,12 +12,16 @@ def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|Eng
|
||||
try:
|
||||
# swaybg backend:
|
||||
if cf.backend == "swaybg":
|
||||
fill = cf.fill_option.lower()
|
||||
|
||||
# Kill previous swaybg instances:
|
||||
try:
|
||||
subprocess.check_output(["pgrep", "swaybg"], encoding='utf-8')
|
||||
subprocess.Popen(["killall", "swaybg"])
|
||||
time.sleep(0.005)
|
||||
except Exception as e:
|
||||
print(f"{txt.err_kill} {e}")
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
fill = cf.fill_option.lower()
|
||||
command = ["swaybg"]
|
||||
# if monitor != "All":
|
||||
# command.extend(["-o", monitor])
|
||||
@ -28,6 +32,22 @@ def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|Eng
|
||||
|
||||
# swww backend:
|
||||
elif cf.backend == "swww":
|
||||
|
||||
# Check with pgrep if other backends they are running, and kill them
|
||||
# Because swaybg and hyprpaper are known to conflict with swww
|
||||
try:
|
||||
subprocess.check_output(["pgrep", "swaybg"], encoding='utf-8')
|
||||
subprocess.Popen(["killall", "swaybg"])
|
||||
time.sleep(0.005)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
try:
|
||||
subprocess.check_output(["pgrep", "hyprpaper"], encoding='utf-8')
|
||||
subprocess.Popen(["killall", "hyprpaper"])
|
||||
time.sleep(0.005)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
fill_types = {
|
||||
"fill": "crop",
|
||||
"fit": "fit",
|
||||
@ -36,16 +56,13 @@ def change_wallpaper(image_path: str, cf: Config, monitor: str, txt: Chinese|Eng
|
||||
"tile": "no",
|
||||
}
|
||||
fill = fill_types[cf.fill_option.lower()]
|
||||
|
||||
# Check if swww-deamon is already running. If not, launch it:
|
||||
try:
|
||||
if "swaybg" in cf.installed_backends:
|
||||
subprocess.Popen(["killall", "swaybg"])
|
||||
time.sleep(0.005)
|
||||
if "hyprpaper" in cf.installed_backends:
|
||||
subprocess.Popen(["killall", "hyprpaper"])
|
||||
time.sleep(0.005)
|
||||
except Exception as e:
|
||||
print(f"{txt.err_kill} {e}")
|
||||
subprocess.Popen(["swww-daemon"])
|
||||
subprocess.check_output(["pgrep", "swww-daemon"], encoding='utf-8')
|
||||
except subprocess.CalledProcessError:
|
||||
subprocess.Popen(["swww-daemon"])
|
||||
|
||||
command = ["swww", "img", image_path]
|
||||
command.extend(["--resize", fill])
|
||||
command.extend(["--fill-color", cf.color])
|
||||
|
@ -39,7 +39,6 @@ class English:
|
||||
self.err_wall = "Error changing wallpaper:"
|
||||
self.err_notsup = "The backend is not supported:"
|
||||
self.err_disp = "Error determining monitor names:"
|
||||
self.err_kill = "Warning related to killall:"
|
||||
|
||||
self.tip_refresh = "Recache the folder of images"
|
||||
self.tip_fill = "Choose fill type"
|
||||
@ -89,7 +88,6 @@ class German:
|
||||
self.err_wall = "Fehler beim Ändern des Hintergrundbildes:"
|
||||
self.err_notsup = "Das folgende Backend wird nicht unterstützt:"
|
||||
self.err_disp = "Fehler beim Ermitteln der Monitor-Namen:"
|
||||
self.err_kill = "Warnung im Zusammenhang mit dem Befehl killall:"
|
||||
|
||||
self.tip_refresh = "Erneutes einlesen des Hintergrundbild-Ordners"
|
||||
self.tip_fill = "Skalierungsart auswählen"
|
||||
@ -139,7 +137,6 @@ class French:
|
||||
self.err_wall = "Erreur lors du changement de papier peint :"
|
||||
self.err_notsup = "Le backend n'est pas pris en charge :"
|
||||
self.err_disp = "Erreur lors de la détermination des noms des moniteurs :"
|
||||
self.err_kill = "Avertissement lié à killall :"
|
||||
|
||||
self.tip_refresh = "Recréer le dossier d'images"
|
||||
self.tip_fill = "Choisir le type de remplissage"
|
||||
@ -189,7 +186,6 @@ class Polish:
|
||||
self.err_wall = "Błąd podczas zmiany tapety:"
|
||||
self.err_notsup = "Backend nie jest obsługiwany:"
|
||||
self.err_disp = "Błąd podczas określania nazw monitorów:"
|
||||
self.err_kill = "Ostrzeżenie związane z poleceniem killall:"
|
||||
|
||||
self.tip_refresh = "Odśwież folder z obrazami"
|
||||
self.tip_fill = "Wybierz typ wypełnienia"
|
||||
@ -239,7 +235,6 @@ class Russian:
|
||||
self.err_wall = "Ошибка при смене обоев:"
|
||||
self.err_notsup = "Бэкенд не поддерживается:"
|
||||
self.err_disp = "Ошибка определения названий мониторов:"
|
||||
self.err_kill = "Предупреждение связанное с killall:"
|
||||
|
||||
self.tip_refresh = "Обновить папку с изображениями"
|
||||
self.tip_fill = "Выбрать тип заполнения"
|
||||
@ -289,7 +284,6 @@ class Chinese:
|
||||
self.err_wall = "更改壁纸时出错:"
|
||||
self.err_notsup = "不支持后端:"
|
||||
self.err_disp = "确定监视器名称时出错:"
|
||||
self.err_kill = "与killall相关的警告:"
|
||||
|
||||
self.tip_refresh = "重新缓存图像文件夹"
|
||||
self.tip_fill = "选择填充类型"
|
||||
|
Loading…
Reference in New Issue
Block a user