55import webbrowser
66import os
77import random
8- import subprocess
98import random
109import 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
1413ACTION_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
0 commit comments