mirror of
https://github.com/Snigdha-OS/snigdhaos-welcome.git
synced 2025-09-21 06:24:56 +02:00
🧹 chore: add better error handling
This commit is contained in:
@@ -598,17 +598,35 @@ class Main(Gtk.Window):
|
||||
|
||||
|
||||
def run_app(self, app_cmd):
|
||||
try:
|
||||
# Run the application command with subprocess.run() and capture stdout and stderr
|
||||
process = subprocess.run(
|
||||
app_cmd,
|
||||
shell=False,
|
||||
shell=False, # Avoid shell injection
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
stderr=subprocess.PIPE, # Capture stderr separately
|
||||
universal_newlines=True, # Ensure output is decoded as text
|
||||
check=True # Raise CalledProcessError if command returns non-zero exit code
|
||||
)
|
||||
# for debugging print stdout to console
|
||||
if GUI.debug is True:
|
||||
|
||||
# Debugging: Print stdout to console if debugging is enabled
|
||||
if GUI.debug:
|
||||
print(process.stdout)
|
||||
|
||||
return process.stdout # Return the output
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
# Handle errors in case the command fails (non-zero exit code)
|
||||
if GUI.debug:
|
||||
print(f"Error executing command: {e}")
|
||||
return None # Return None on failure
|
||||
|
||||
except Exception as e:
|
||||
# Catch any other exceptions
|
||||
if GUI.debug:
|
||||
print(f"Unexpected error: {e}")
|
||||
return None
|
||||
|
||||
def startup_toggle(self, widget):
|
||||
if widget.get_active() is True:
|
||||
if os.path.isfile(GUI.dot_desktop):
|
||||
|
Reference in New Issue
Block a user