From 380e2dbb1abe36d782ba9de4cdb8a49c82123d8f Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 22 Jun 2025 20:05:10 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20config,=20data,=20settings:=20us?= =?UTF-8?q?e=20user-specific=20config=20paths=20instead=20of=20hardcoded?= =?UTF-8?q?=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ config/config.py | 16 ++++++++-------- config/data.py | 4 +++- config/settings/constants.py | 2 +- config/settings/gui.py | 12 ++++++++---- config/settings/utils.py | 28 ++++++++++++++++------------ main.py | 2 +- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ab4d8bd..54f5f10 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ Modus Logo **A modular and extensible shell for Hyprland, powered by Fabric** + + diff --git a/config/config.py b/config/config.py index f86acbd..fa97473 100644 --- a/config/config.py +++ b/config/config.py @@ -1,3 +1,5 @@ +from fabric import Application +import shutil import os import sys from pathlib import Path @@ -16,13 +18,11 @@ def _configure_sys_path_for_direct_execution(): if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) + _configure_sys_path_for_direct_execution() -import shutil -from fabric import Application - -if __name__ == "__main__" and (__package__ is None or __package__ == ''): +if __name__ == "__main__" and (__package__ is None or __package__ == ""): from config.data import APP_NAME, APP_NAME_CAP from config.settings.gui import HyprConfGUI from config.settings.utils import load_bind_vars @@ -40,12 +40,12 @@ def open_config(): show_lock_checkbox = True dest_lock = os.path.expanduser("~/.config/hypr/hyprlock.conf") - src_lock = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hyprlock.conf") + src_lock = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/config/hypr/hyprlock.conf") if not os.path.exists(dest_lock) and os.path.exists(src_lock): try: os.makedirs(os.path.dirname(dest_lock), exist_ok=True) shutil.copy(src_lock, dest_lock) - show_lock_checkbox = False + show_lock_checkbox = False print(f"Copied default hyprlock config to {dest_lock}") except Exception as e: print(f"Error copying default hyprlock config: {e}") @@ -53,7 +53,7 @@ def open_config(): show_idle_checkbox = True dest_idle = os.path.expanduser("~/.config/hypr/hypridle.conf") - src_idle = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hypridle.conf") + src_idle = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/config/hypr/hypridle.conf") if not os.path.exists(dest_idle) and os.path.exists(src_idle): try: os.makedirs(os.path.dirname(dest_idle), exist_ok=True) @@ -69,7 +69,7 @@ def open_config(): show_lock_checkbox=show_lock_checkbox, show_idle_checkbox=show_idle_checkbox, application=app, - on_destroy=lambda *_: app.quit() + on_destroy=lambda *_: app.quit(), ) app.add_window(window) diff --git a/config/data.py b/config/data.py index dbe70f0..68d4d89 100644 --- a/config/data.py +++ b/config/data.py @@ -40,7 +40,9 @@ DOCK_THEME = "Pills" def load_config(): """Load the configuration from config.json""" - config_path = os.path.expanduser(f"~/{APP_NAME_CAP}/config/json/config.json") + config_path = os.path.expanduser( + f"~/.config/{APP_NAME_CAP}/config/json/config.json" + ) config = {} if os.path.exists(config_path): diff --git a/config/settings/constants.py b/config/settings/constants.py index ce210cb..1abe5bb 100644 --- a/config/settings/constants.py +++ b/config/settings/constants.py @@ -8,7 +8,7 @@ from config.data import ( SOURCE_STRING = f""" # {APP_NAME_CAP} -source = ~/{APP_NAME_CAP}/config/hypr/{APP_NAME}.conf +source = ~/.config/{APP_NAME_CAP}/config/hypr/{APP_NAME}.conf """ DEFAULTS = { diff --git a/config/settings/gui.py b/config/settings/gui.py index 9b7800a..53429c4 100644 --- a/config/settings/gui.py +++ b/config/settings/gui.py @@ -907,7 +907,7 @@ class HyprConfGUI(Window): print(f"{start_time:.4f}: Background task started.") config_json = os.path.expanduser( - f"~/{APP_NAME_CAP}/config/json/config.json" + f"~/.config/{APP_NAME_CAP}/config/json/config.json" ) os.makedirs(os.path.dirname(config_json), exist_ok=True) try: @@ -935,7 +935,9 @@ class HyprConfGUI(Window): if replace_lock: print(f"{time.time():.4f}: Replacing hyprlock config...") - src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hyprlock.conf") + src = os.path.expanduser( + f"~/.config/{APP_NAME_CAP}/config/hypr/hyprlock.conf" + ) dest = os.path.expanduser("~/.config/hypr/hyprlock.conf") if os.path.exists(src): backup_and_replace(src, dest, "Hyprlock") @@ -945,7 +947,9 @@ class HyprConfGUI(Window): if replace_idle: print(f"{time.time():.4f}: Replacing hypridle config...") - src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hypridle.conf") + src = os.path.expanduser( + f"~/.config/{APP_NAME_CAP}/config/hypr/hypridle.conf" + ) dest = os.path.expanduser("~/.config/hypr/hypridle.conf") if os.path.exists(src): backup_and_replace(src, dest, "Hypridle") @@ -983,7 +987,7 @@ class HyprConfGUI(Window): print(f"{time.time():.4f}: Finished start_config().") print(f"{time.time():.4f}: Initiating Modus restart using Popen...") - main_py = os.path.expanduser(f"~/{APP_NAME_CAP}/main.py") + main_py = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/main.py") kill_cmd = f"killall {APP_NAME}" start_cmd = ["uwsm", "app", "--", "python", main_py] try: diff --git a/config/settings/utils.py b/config/settings/utils.py index 4096f64..b23b9d6 100644 --- a/config/settings/utils.py +++ b/config/settings/utils.py @@ -76,12 +76,12 @@ def ensure_matugen_config(): }, "templates": { "hyprland": { - "input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf", - "output_path": f"~/{APP_NAME_CAP}/config/hypr/colors.conf", + "input_path": f"~/.config/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf", + "output_path": f"~/.config/{APP_NAME_CAP}/config/hypr/colors.conf", }, f"{APP_NAME}": { - "input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css", - "output_path": f"~/{APP_NAME_CAP}/styles/colors.css", + "input_path": f"~/.config/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css", + "output_path": f"~/.config/{APP_NAME_CAP}/styles/colors.css", "post_hook": f"fabric-cli exec {APP_NAME} 'app.set_css()' &", }, }, @@ -124,8 +124,10 @@ def ensure_matugen_config(): print(f"Error writing matugen config to {config_path}: {e}") current_wall = os.path.expanduser("~/.current.wall") - hypr_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/colors.conf") - css_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/styles/colors.css") + hypr_colors = os.path.expanduser( + f"~/.config/{APP_NAME_CAP}/config/hypr/colors.conf" + ) + css_colors = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/styles/colors.css") if ( not os.path.exists(current_wall) @@ -138,7 +140,7 @@ def ensure_matugen_config(): image_path = "" if not os.path.exists(current_wall): example_wallpaper_path = os.path.expanduser( - f"~/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg" + f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg" ) if os.path.exists(example_wallpaper_path): try: @@ -192,7 +194,9 @@ def load_bind_vars(): # Usar .copy() para no modificar DEFAULTS accidentalmente bind_vars.update(settings_constants.DEFAULTS.copy()) - config_json = os.path.expanduser(f"~/{APP_NAME_CAP}/config/json/config.json") + config_json = os.path.expanduser( + f"~/.config/{APP_NAME_CAP}/config/json/config.json" + ) if os.path.exists(config_json): try: with open(config_json, "r") as f: @@ -246,17 +250,17 @@ def generate_hyprconf() -> str: is_vertical = bar_position in ["Left", "Right"] animation_type = "slidefadevert" if is_vertical else "slidefade" - return f"""exec-once = uwsm-app $(python {home}/{APP_NAME_CAP}/main.py) + return f"""exec-once = uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py) exec = pgrep -x "hypridle" > /dev/null || uwsm app -- hypridle exec = uwsm app -- swww-daemon exec-once = wl-paste --type text --watch cliphist store exec-once = wl-paste --type image --watch cliphist store $fabricSend = fabric-cli exec {APP_NAME} -$axMessage = notify-send "Modus" "FIRE IN THE HOLE‼️🗣️🔥🕳️" -i "{home}/{APP_NAME_CAP}/assets/modus.png" -A "🗣️" -A "🔥" -A "🕳️" -a "Source Code" +$axMessage = notify-send "Modus" "FIRE IN THE HOLE‼️🗣️🔥🕳️" -i "{home}/{AP.config / P_NAME_CAP}/assets/modus.png" -A "🗣️" -A "🔥" -A "🕳️" -a "Source Code" # Reload {APP_NAME_CAP} -bind = {bind_vars.get("prefix_restart", "ALT SHIFT")}, {bind_vars.get("suffix_restart", "R")}, exec, killall {APP_NAME}; uwsm-app $(python {home}/{APP_NAME_CAP}/main.py) +bind = {bind_vars.get("prefix_restart", "ALT SHIFT")}, {bind_vars.get("suffix_restart", "R")}, exec, killall {APP_NAME}; uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py) # Message bind = {bind_vars.get("prefix_msg", "SUPER")}, {bind_vars.get("suffix_msg", "A")}, exec, $Message # Application Switcher @@ -279,7 +283,7 @@ bind = {bind_vars.get("prefix_power", "SUPER")}, {bind_vars.get("suffix_power", # Toggle Caffeine bind = {bind_vars.get("prefix_caffeine", "SUPER SHIFT")}, {bind_vars.get("suffix_caffeine", "M")}, exec, $fabricSend "launcher.show_launcher('caffeine on', external=True)" # Settings -bind = {bind_vars.get("prefix_settings", "SUPER")}, {bind_vars.get("suffix_settings", "I")}, exec, uwsm-app $(python {home}/{APP_NAME_CAP}/config/config.py) # Settings +bind = {bind_vars.get("prefix_settings", "SUPER")}, {bind_vars.get("suffix_settings", "I")}, exec, uwsm-app $(python {home}/.config/{APP_NAME_CAP}/config/config.py) # Settings # Restart Modus bind = {bind_vars.get("prefix_restart_inspector", "SUPER CTRL ALT")}, {bind_vars.get("suffix_restart_inspector", "B")}, exec, killall {APP_NAME}; uwsm-app $(GTK_DEBUG=interactive python {home}/.config/{APP_NAME_CAP}/main.py) # Restart with inspector diff --git a/main.py b/main.py index 52dfa6a..621878b 100644 --- a/main.py +++ b/main.py @@ -35,7 +35,7 @@ if __name__ == "__main__": current_wallpaper = os.path.expanduser("~/.current.wall") if not os.path.exists(current_wallpaper): example_wallpaper = os.path.expanduser( - f"~/{APP_NAME_CAP}/assets/wallpapers_example/example-1.png" + f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.png" ) os.symlink(example_wallpaper, current_wallpaper)