Skip to content

Commit

Permalink
feat(config): support custom configuration directory via YASB_CONFIG_…
Browse files Browse the repository at this point in the history
…HOME
  • Loading branch information
amnweb committed Feb 21, 2025
1 parent 8f84e75 commit cfee1c8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Union
from core.validation.config import CONFIG_SCHEMA
from core.utils.alert_dialog import raise_info_alert
#from cssutils import CSSParser
from cerberus import Validator, schema
from yaml.parser import ParserError
from yaml import safe_load, dump
Expand Down
3 changes: 2 additions & 1 deletion src/core/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def parse_arguments():
sys.exit(0)

elif args.command == 'log':
log_file = os.path.join(os.path.expanduser("~"), ".config", "yasb", "yasb.log")
config_home = os.getenv('YASB_CONFIG_HOME') if os.getenv('YASB_CONFIG_HOME') else os.path.join(os.path.expanduser("~"), ".config", "yasb")
log_file = os.path.join(config_home, "yasb.log")
if not os.path.exists(log_file):
print("Log file does not exist. Please restart YASB to generate logs.")
sys.exit(1)
Expand Down
16 changes: 8 additions & 8 deletions src/core/utils/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,15 @@ 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)
subprocess.run(["yasbc", "stop"], creationflags=subprocess.CREATE_NO_WINDOW, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# 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"
styles_url = f"{base_url}/styles.css"

# Define the destination paths
home_dir = os.path.expanduser("~")
config_path = os.path.join(home_dir, ".config", "yasb", "config.yaml")
styles_path = os.path.join(home_dir, ".config", "yasb", "styles.css")
config_home = os.getenv('YASB_CONFIG_HOME') if os.getenv('YASB_CONFIG_HOME') else os.path.join(os.path.expanduser("~"), ".config", "yasb")
config_path = os.path.join(config_home, "config.yaml")
styles_path = os.path.join(config_home, "styles.css")

# Create the directory if it doesn't exist
os.makedirs(os.path.dirname(config_path), exist_ok=True)
Expand All @@ -307,13 +306,13 @@ def install_theme(self):
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)
subprocess.run(["yasbc", "start"], creationflags=subprocess.CREATE_NO_WINDOW, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except Exception as e:
QMessageBox.critical(self, 'Error', f"Failed to install theme: {str(e)}")

Expand Down Expand Up @@ -349,7 +348,8 @@ def init_ui(self):
self.placeholder_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(self.placeholder_label)

self.backup_info = QLabel("Backup your current theme before installing a new one. You can do this by copying the <b>config.yaml</b> and <b>styles.css</b> files from the <b><i>.config/yasb</i></b> directory to a safe location.")
config_home = os.getenv('YASB_CONFIG_HOME') if os.getenv('YASB_CONFIG_HOME') else os.path.join(os.path.expanduser("~"), ".config", "yasb")
self.backup_info = QLabel(f"Backup your current theme before installing a new one. You can do this by copying the <b>config.yaml</b> and <b>styles.css</b> files from the <b><i>{config_home}</i></b> directory to a safe location.")
self.backup_info.setWordWrap(True)
self.backup_info.setStyleSheet("color:#fff; background-color: rgba(166, 16, 48, 0.3);border-radius:6px;border:1px solid rgba(166, 16, 48, 0.5);padding:4px 8px;font-size:11px;font-family:'Segoe UI';margin:14px 20px 0 14px")
self.backup_info.hide()
Expand Down
4 changes: 0 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import asyncio
import logging
import sys
Expand All @@ -16,9 +15,6 @@
import ctypes.wintypes
from core.utils.win32.windows import WindowsTaskbar

# Set font engine to GDI as DirectWrite causes issues with some fonts in PyQt6.8
os.environ["QT_QPA_PLATFORM"] = "windows:fontengine=gdi"

logging.getLogger('asyncio').setLevel(logging.WARNING)

def main():
Expand Down
6 changes: 3 additions & 3 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
GITHUB_URL = "https://github.com/amnweb/yasb"
GITHUB_THEME_URL = "https://github.com/amnweb/yasb-themes"
BUILD_VERSION = "1.6.3"
BUILD_VERSION = "1.6.4"
# Development Settings
DEBUG = False
# Configuration Settings
DEFAULT_CONFIG_DIRECTORY = ".config\\yasb"
DEFAULT_CONFIG_DIRECTORY = os.getenv('YASB_CONFIG_HOME', ".config\\yasb")
DEFAULT_STYLES_FILENAME = "styles.css"
DEFAULT_CONFIG_FILENAME = "config.yaml"
DEFAULT_LOG_FILENAME = "yasb.log"
DEFAULT_LOG_FILENAME = "yasb.log"

0 comments on commit cfee1c8

Please sign in to comment.