Skip to content

Commit

Permalink
feat(theme): implement theme installation with subprocess control
Browse files Browse the repository at this point in the history
Added subprocess calls to stop and start the theme service during the theme installation process. This ensures that the theme is properly applied after downloading the necessary configuration and style files.
  • Loading branch information
amnweb committed Jan 12, 2025
1 parent 1493011 commit d7a6239
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/utils/themes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
import sys
import requests
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
Expand Down Expand Up @@ -285,6 +286,7 @@ def install_theme(self):
# Show the dialog and check the user's response
if dialog.exec() == QDialog.DialogCode.Accepted:
try:
subprocess.run(["yasbc", "stop"], creationflags=subprocess.CREATE_NO_WINDOW)
# Define the URLs for the files
base_url = f"https://raw.githubusercontent.com/amnweb/yasb-themes/main/themes/{self.theme_data['id']}"
config_url = f"{base_url}/config.yaml"
Expand All @@ -298,17 +300,18 @@ def install_theme(self):
# Create the directory if it doesn't exist
os.makedirs(os.path.dirname(config_path), exist_ok=True)

# Download and save the config.yaml file
config_response = requests.get(config_url)
config_response.raise_for_status()
with open(config_path, 'wb') as config_file:
config_file.write(config_response.content)

# Download and save the styles.css file
styles_response = requests.get(styles_url)
styles_response.raise_for_status()
with open(styles_path, 'wb') as styles_file:
styles_file.write(styles_response.content)

# Download and save the config.yaml file
config_response = requests.get(config_url)
config_response.raise_for_status()
with open(config_path, 'wb') as config_file:
config_file.write(config_response.content)
subprocess.run(["yasbc", "start"], creationflags=subprocess.CREATE_NO_WINDOW)
except Exception as e:
QMessageBox.critical(self, 'Error', f"Failed to install theme: {str(e)}")

Expand Down

0 comments on commit d7a6239

Please sign in to comment.