mirror of
https://github.com/nwg-piotr/nwg-displays.git
synced 2026-03-11 17:33:57 -05:00
feat: implement toggle profile wallpapers script
This commit is contained in:
@@ -19,7 +19,7 @@ done
|
||||
[ -d "./dist" ] && rm -rf ./dist
|
||||
|
||||
# Remove launcher scripts
|
||||
filenames=("/usr/bin/nwg-displays" "/usr/bin/nwg-displays-apply")
|
||||
filenames=("/usr/bin/nwg-displays" "/usr/bin/nwg-displays-apply" "/usr/bin/nwg-displays-toggle-wallpapers")
|
||||
|
||||
for filename in "${filenames[@]}"; do
|
||||
if [ -f "$filename" ]; then
|
||||
|
||||
@@ -1132,6 +1132,10 @@ def main():
|
||||
if config_keys_missing(config, config_file):
|
||||
config = load_json(config_file)
|
||||
|
||||
if "profile-bound-wallpapers" not in config:
|
||||
config["profile-bound-wallpapers"] = True
|
||||
save_json(config, config_file)
|
||||
|
||||
eprint("Settings: {}".format(config))
|
||||
|
||||
# Initialize the profile manager
|
||||
|
||||
Binary file not shown.
Binary file not shown.
23
nwg_displays/scripts/toggle_profile_wallpapers.py
Normal file
23
nwg_displays/scripts/toggle_profile_wallpapers.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import sys
|
||||
from nwg_displays.tools import save_json
|
||||
from nwg_displays.utils.get_config import get_config
|
||||
|
||||
|
||||
def main():
|
||||
config, config_file = get_config()
|
||||
|
||||
# Toggle the value, defaulting to True if not present
|
||||
current_value = config.get("profile-bound-wallpapers", True)
|
||||
new_value = not current_value
|
||||
config["profile-bound-wallpapers"] = new_value
|
||||
|
||||
save_json(config, config_file)
|
||||
print(f"Saved configuration to {config_file}")
|
||||
|
||||
status = "enabled" if new_value else "disabled"
|
||||
print(f"Profile-bound wallpapers {status}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -2,8 +2,6 @@ import os
|
||||
import datetime
|
||||
import json
|
||||
import time
|
||||
|
||||
# Assuming these tools exist based on original code structure
|
||||
from nwg_displays.tools import (
|
||||
hyprctl,
|
||||
save_list_to_text_file,
|
||||
@@ -11,11 +9,7 @@ from nwg_displays.tools import (
|
||||
inactive_output_description,
|
||||
)
|
||||
from nwg_displays.wallpaper_manager import WallpaperManager
|
||||
|
||||
# If create_confirm_win is in main or ui, you might need to pass it as a callback
|
||||
# or import it if circular imports aren't an issue.
|
||||
# from nwg_displays.main import create_confirm_win
|
||||
|
||||
from nwg_displays.utils.get_config import get_config
|
||||
|
||||
class SettingsApplier:
|
||||
@staticmethod
|
||||
@@ -93,7 +87,9 @@ class SettingsApplier:
|
||||
save_list_to_text_file(lines, outputs_path)
|
||||
hyprctl("reload")
|
||||
|
||||
if "wallpapers" in profile_data and profile_data.get("config", {}).get(
|
||||
config, config_file = get_config()
|
||||
|
||||
if "wallpapers" in profile_data and config.get(
|
||||
"profile-bound-wallpapers", True
|
||||
):
|
||||
print("[Profile] Applying wallpapers...")
|
||||
@@ -365,6 +361,10 @@ class SettingsApplier:
|
||||
if not last_profile_name:
|
||||
return
|
||||
|
||||
config, _ = get_config()
|
||||
if not config.get("profile-bound-wallpapers", True):
|
||||
return
|
||||
|
||||
prev_profile_path = os.path.join(
|
||||
config_dir, "profiles", f"{last_profile_name}.json"
|
||||
)
|
||||
@@ -383,9 +383,6 @@ class SettingsApplier:
|
||||
with open(prev_profile_path, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if not data.get("config", {}).get("profile-bound-wallpapers", True):
|
||||
return
|
||||
|
||||
if "wallpapers" not in data:
|
||||
data["wallpapers"] = {}
|
||||
|
||||
|
||||
BIN
nwg_displays/utils/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
nwg_displays/utils/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
nwg_displays/utils/__pycache__/get_config.cpython-314.pyc
Normal file
BIN
nwg_displays/utils/__pycache__/get_config.cpython-314.pyc
Normal file
Binary file not shown.
20
nwg_displays/utils/get_config.py
Normal file
20
nwg_displays/utils/get_config.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import sys
|
||||
from nwg_displays.utils.get_config_dir import get_config_dir
|
||||
from nwg_displays.tools import load_json
|
||||
|
||||
|
||||
def get_config():
|
||||
config_dir = get_config_dir()
|
||||
config_file = os.path.join(config_dir, "config")
|
||||
|
||||
if not os.path.isfile(config_file):
|
||||
print(f"Config file not found at {config_file}")
|
||||
sys.exit(1)
|
||||
|
||||
config = load_json(config_file)
|
||||
if config is None:
|
||||
print("Failed to load configuration")
|
||||
sys.exit(1)
|
||||
|
||||
return config, config_file
|
||||
3
setup.py
3
setup.py
@@ -25,7 +25,8 @@ setup(
|
||||
"nwg-displays = nwg_displays.main:main",
|
||||
],
|
||||
"console_scripts": [
|
||||
"nwg-displays-apply = nwg_displays.scripts.apply_profile_json:main"
|
||||
"nwg-displays-apply = nwg_displays.scripts.apply_profile_json:main",
|
||||
"nwg-displays-toggle-wallpapers = nwg_displays.scripts.toggle_profile_wallpapers:main",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user