Skip to content

Commit 9afee36

Browse files
author
tom
committed
build fix Linux Paths
1 parent 22864a0 commit 9afee36

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

src/logic/actions.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import webbrowser
66
import os
77
import random
8-
import subprocess
98
import random
109
import subprocess
11-
from logic.media_utils import execute_media, play_audio_with_retry
10+
from logic.media_utils import execute_media, play_audio_with_retry, get_clean_env
1211

1312
# List of supported action types
1413
ACTION_TYPES = [
@@ -170,7 +169,7 @@ def get_current_system_volume():
170169
try:
171170
result = subprocess.run(
172171
["pactl", "get-sink-volume", "@DEFAULT_SINK@"],
173-
capture_output=True, text=True, check=True
172+
capture_output=True, text=True, check=True, env=get_clean_env()
174173
)
175174
# Parse output like "Volume: front-left: 65536 / 100% / 0.00 dB"
176175
for line in result.stdout.split('\n'):
@@ -187,7 +186,7 @@ def get_current_system_volume():
187186
try:
188187
result = subprocess.run(
189188
["amixer", "get", "Master"],
190-
capture_output=True, text=True, check=True
189+
capture_output=True, text=True, check=True, env=get_clean_env()
191190
)
192191
# Parse output like "[50%]"
193192
import re
@@ -233,7 +232,7 @@ def handle_set_system_volume(config):
233232
if method in ["auto", "amixer_pulse"]:
234233
try:
235234
# -M for mapped volume is more natural
236-
subprocess.run(["amixer", "-D", "pulse", "set", "Master", f"{volume}%"], check=True, capture_output=True)
235+
subprocess.run(["amixer", "-D", "pulse", "set", "Master", f"{volume}%"], check=True, capture_output=True, env=get_clean_env())
237236
logging.info(f"Set system volume to {volume}% (Pulse)")
238237
return True
239238
except subprocess.CalledProcessError:
@@ -242,7 +241,7 @@ def handle_set_system_volume(config):
242241

243242
if method in ["auto", "amixer_master"]:
244243
try:
245-
subprocess.run(["amixer", "set", "Master", f"{volume}%"], check=True, capture_output=True)
244+
subprocess.run(["amixer", "set", "Master", f"{volume}%"], check=True, capture_output=True, env=get_clean_env())
246245
logging.info(f"Set system volume to {volume}% (ALSA Master)")
247246
return True
248247
except subprocess.CalledProcessError:
@@ -253,7 +252,7 @@ def handle_set_system_volume(config):
253252
# Basic pactl implementation
254253
try:
255254
# sink @DEFAULT_SINK@
256-
subprocess.run(["pactl", "set-sink-volume", "@DEFAULT_SINK@", f"{volume}%"], check=True, capture_output=True)
255+
subprocess.run(["pactl", "set-sink-volume", "@DEFAULT_SINK@", f"{volume}%"], check=True, capture_output=True, env=get_clean_env())
257256
logging.info(f"Set system volume to {volume}% (pactl)")
258257
return True
259258
except (subprocess.CalledProcessError, FileNotFoundError):
@@ -291,7 +290,7 @@ def handle_set_system_volume(config):
291290
# Convert 0-100 to 0-65535
292291
nircmd_vol = int(65535 * (volume / 100.0))
293292
try:
294-
subprocess.run([nircmd_path, "setsysvolume", str(nircmd_vol)], check=True, creationflags=0x08000000)
293+
subprocess.run([nircmd_path, "setsysvolume", str(nircmd_vol)], check=True, creationflags=0x08000000, env=get_clean_env())
295294
logging.info(f"Set system volume to {volume}% (nircmd at {nircmd_path})")
296295
return True
297296
except FileNotFoundError:
@@ -390,7 +389,7 @@ def handle_monitor_control(config):
390389
nircmd_path = get_nircmd_path()
391390

392391
cmd = "monitor off" if state == "off" else "monitor on"
393-
subprocess.run(f'"{nircmd_path}" {cmd}', shell=True, check=False)
392+
subprocess.run(f'"{nircmd_path}" {cmd}', shell=True, check=False, env=get_clean_env())
394393
logging.info(f"Monitor control (Windows): {state}")
395394
return True
396395
except Exception as e:
@@ -400,9 +399,9 @@ def handle_monitor_control(config):
400399
elif sys.platform.startswith("linux"):
401400
try:
402401
if state == "off":
403-
subprocess.run(["xset", "dpms", "force", "off"], check=True)
402+
subprocess.run(["xset", "dpms", "force", "off"], check=True, env=get_clean_env())
404403
else:
405-
subprocess.run(["xset", "dpms", "force", "on"], check=True)
404+
subprocess.run(["xset", "dpms", "force", "on"], check=True, env=get_clean_env())
406405
logging.info(f"Monitor control (Linux): {state}")
407406
return True
408407
except Exception as e:
@@ -421,9 +420,9 @@ def handle_run_command(config):
421420
wait = config.get("wait", False)
422421

423422
if wait:
424-
subprocess.run(command, shell=True, check=True)
423+
subprocess.run(command, shell=True, check=True, env=get_clean_env())
425424
else:
426-
subprocess.Popen(command, shell=True)
425+
subprocess.Popen(command, shell=True, env=get_clean_env())
427426
return True
428427
except Exception as e:
429428
logging.error(f"Command execution failed: {e}")
@@ -448,7 +447,7 @@ def handle_open_journal(config):
448447
os.startfile(filepath)
449448
else:
450449
opener = "xdg-open"
451-
subprocess.call([opener, filepath])
450+
subprocess.call([opener, filepath], env=get_clean_env())
452451

453452
logging.info(f"Opened journal: {filepath}")
454453
return True

src/logic/media_utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
import time as time_module
88
import threading
99
import shutil
10+
import copy
11+
12+
def get_clean_env():
13+
"""Return a copy of the os environment with PyInstaller's library paths stripped."""
14+
env = copy.deepcopy(dict(os.environ))
15+
# PyInstaller overrides LD_LIBRARY_PATH, restore original to allow system binaries to run
16+
if "LD_LIBRARY_PATH_ORIG" in env:
17+
env["LD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH_ORIG"]
18+
del env["LD_LIBRARY_PATH_ORIG"]
19+
elif "LD_LIBRARY_PATH" in env:
20+
# If no _ORIG, just remove it so system libraries are used
21+
del env["LD_LIBRARY_PATH"]
22+
return env
23+
1024

1125

1226
def ensure_time_format(time_value):
@@ -164,7 +178,7 @@ def play_video_vlc(file_path, config=None):
164178
cmd.append(f"--mmdevice-volume={min(1.0, max(0.0, 1.0 + (float(gain) / 40.0)))}")
165179

166180
logging.info(f"Launching VLC: {cmd}")
167-
result = subprocess.run(cmd, capture_output=True, text=True)
181+
result = subprocess.run(cmd, capture_output=True, text=True, env=get_clean_env())
168182

169183
if result.returncode != 0:
170184
logging.error(f"VLC exited with code {result.returncode}")
@@ -238,7 +252,7 @@ def play_video_mpv(file_path, config=None):
238252
cmd.append(f"--af=volume={float(gain):.1f}dB")
239253

240254
logging.info(f"Launching mpv: {cmd}")
241-
result = subprocess.run(cmd, capture_output=True, text=True)
255+
result = subprocess.run(cmd, capture_output=True, text=True, env=get_clean_env())
242256

243257
if result.returncode != 0:
244258
logging.error(f"mpv exited with code {result.returncode}")
@@ -269,7 +283,7 @@ def get_video_duration_ffprobe(file_path):
269283
file_path
270284
]
271285

272-
result = subprocess.run(cmd, capture_output=True, text=True)
286+
result = subprocess.run(cmd, capture_output=True, text=True, env=get_clean_env())
273287
if result.returncode == 0:
274288
try:
275289
val = float(result.stdout.strip())

src/platforms/linux/power.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import time
55
from core.interfaces import PowerManager
6+
from logic.media_utils import get_clean_env
67

78
class LinuxPowerManager(PowerManager):
89
"""Linux power manager with multi-strategy sleep inhibition.
@@ -44,7 +45,7 @@ def inhibit_sleep(self, reason: str = "Video Alarm Active") -> bool:
4445
['systemd-inhibit', '--what=idle:sleep:handle-lid-switch',
4546
f'--why={reason}', '--who=PyCronVideoAlarm',
4647
'sleep', 'infinity'],
47-
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
48+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=get_clean_env()
4849
)
4950
logging.info("Inhibited sleep via systemd-inhibit CLI")
5051
self._inhibit_method = 'systemd-inhibit'
@@ -59,8 +60,8 @@ def inhibit_sleep(self, reason: str = "Video Alarm Active") -> bool:
5960
try:
6061
display = os.environ.get('DISPLAY')
6162
if display:
62-
subprocess.run(['xset', '-dpms'], check=False, capture_output=True)
63-
subprocess.run(['xset', 's', 'off'], check=False, capture_output=True)
63+
subprocess.run(['xset', '-dpms'], check=False, capture_output=True, env=get_clean_env())
64+
subprocess.run(['xset', 's', 'off'], check=False, capture_output=True, env=get_clean_env())
6465
logging.info("Disabled DPMS and screensaver via xset")
6566
self._restored_screensaver = True
6667
success = True
@@ -165,8 +166,8 @@ def uninhibit_sleep(self) -> bool:
165166
# Restore xset DPMS/screensaver
166167
if self._restored_screensaver:
167168
try:
168-
subprocess.run(['xset', '+dpms'], check=False, capture_output=True)
169-
subprocess.run(['xset', 's', 'on'], check=False, capture_output=True)
169+
subprocess.run(['xset', '+dpms'], check=False, capture_output=True, env=get_clean_env())
170+
subprocess.run(['xset', 's', 'on'], check=False, capture_output=True, env=get_clean_env())
170171
logging.info("Re-enabled DPMS and screensaver via xset")
171172
self._restored_screensaver = False
172173
except Exception as e:

0 commit comments

Comments
 (0)