From 5f2f8f797bc31763c1e74b14975ac9b5b109108a Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Mon, 21 Jul 2025 09:48:39 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=85=20style:=20update=20color=20scheme?= =?UTF-8?q?=20and=20add=20power=20management=20commands=20to=20bash=20scri?= =?UTF-8?q?pts=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/hypr/colors.conf | 42 +++--- modules/launcher/plugins/bash_scripts.py | 166 +++++++++++++++++++++++ 2 files changed, 187 insertions(+), 21 deletions(-) diff --git a/config/hypr/colors.conf b/config/hypr/colors.conf index e5ce497..6d05899 100644 --- a/config/hypr/colors.conf +++ b/config/hypr/colors.conf @@ -1,27 +1,27 @@ -$wallpaper = /home/sankalp/Pictures/wallpapers/2.png -$background = 131318 -$foreground = e4e1e9 +$wallpaper = /home/sankalp/Pictures/wallpapers/1.png +$background = 1a1110 +$foreground = f1dfdb -$primary = bcc2ff -$secondary = c4c5dd -$tertiary = e6bad6 -$surface = 131318 -$surface_bright = 39393f -$outline = 90909a +$primary = ffb4a5 +$secondary = e7bdb5 +$tertiary = dcc48c +$surface = 1a1110 +$surface_bright = 423734 +$outline = a08c88 $error = ff5945 $shadow = 000000 -$red = ffb2b9 -$green = 95d5a7 -$yellow = b8cf84 -$blue = bdc2ff -$magenta = e4b7f3 -$cyan = 82d3e2 +$red = ffb4a7 +$green = b7d085 +$yellow = dec56e +$blue = cebdfe +$magenta = fcb0d5 +$cyan = 84d5c4 $white = 82d3e0 -$red_dim = ff4c5c -$green_dim = 4cb86a -$yellow_dim = 8baa43 -$blue_dim = 5764ff -$magenta_dim = c360e4 -$cyan_dim = 30b5ce +$red_dim = ff5d41 +$green_dim = 89ad42 +$yellow_dim = bb9b2b +$blue_dim = 8359fc +$magenta_dim = f84ea1 +$cyan_dim = 3eb59c diff --git a/modules/launcher/plugins/bash_scripts.py b/modules/launcher/plugins/bash_scripts.py index f5279e4..7a242a6 100644 --- a/modules/launcher/plugins/bash_scripts.py +++ b/modules/launcher/plugins/bash_scripts.py @@ -33,6 +33,25 @@ class BashScriptsPlugin(PluginBase): "screen-capture.sh" # Exclude screen-capture.sh as it's handled by screencapture plugin } + # Built-in power manager commands + self.power_manager_commands = { + "pm balanced": { + "description": "Switch to balanced power profile", + "profile": "balanced", + "icon": icons.power_balanced, + }, + "pm performance": { + "description": "Switch to performance power profile", + "profile": "performance", + "icon": icons.power_performance, + }, + "pm saver": { + "description": "Switch to power saver profile", + "profile": "power-saver", + "icon": icons.power_saving, + }, + } + # In-memory cache self._scripts_cache: Dict[str, Dict] = {} self._last_cache_update = 0 @@ -42,11 +61,15 @@ class BashScriptsPlugin(PluginBase): self._cache_building = False self._cache_thread = None + # Battery service reference + self._battery_service = None + def initialize(self): """Initialize the bash scripts plugin.""" self.set_triggers(["sh"]) self._load_scripts_cache() self._start_background_cache_update() + self._get_battery_service() def cleanup(self): """Cleanup the bash scripts plugin.""" @@ -55,6 +78,67 @@ class BashScriptsPlugin(PluginBase): # Note: We don't join the thread to avoid blocking cleanup pass + def _get_battery_service(self): + """Get reference to the battery service.""" + try: + from services.battery import Battery + self._battery_service = Battery() + except Exception as e: + print(f"BashScriptsPlugin: Error getting battery service: {e}") + self._battery_service = None + + def _set_power_profile(self, profile: str) -> bool: + """Set the power profile using the battery service.""" + if not self._battery_service: + print("BashScriptsPlugin: Battery service not available") + return False + + try: + # Check if profile proxy is available + if not hasattr(self._battery_service, '_profile_proxy') or not self._battery_service._profile_proxy: + print("BashScriptsPlugin: Power profile proxy not available") + return False + + # Get available profiles + profiles = self._battery_service._profile_proxy.Profiles + available_profiles = [] + for p in profiles: + if isinstance(p, dict) and "Profile" in p: + available_profiles.append(p["Profile"]) + elif hasattr(p, "Profile"): + available_profiles.append(p.Profile) + elif isinstance(p, str): + available_profiles.append(p) + + # Map profile types to actual profile names + profile_mapping = { + "power-saver": ["power-saver", "powersave", "power_saver"], + "balanced": ["balanced", "balance"], + "performance": ["performance", "performance-mode"] + } + + # Find the actual profile name + actual_profile = None + if profile in profile_mapping: + for candidate in profile_mapping[profile]: + if candidate in available_profiles: + actual_profile = candidate + break + elif profile in available_profiles: + actual_profile = profile + + if actual_profile: + self._battery_service._profile_proxy.ActiveProfile = actual_profile + print(f"BashScriptsPlugin: Successfully set power profile to {actual_profile}") + return True + else: + print(f"BashScriptsPlugin: No matching profile found for '{profile}' in available profiles: {available_profiles}") + return False + + except Exception as e: + print(f"BashScriptsPlugin: Error setting power profile: {e}") + return False + def _load_scripts_cache(self): @@ -205,10 +289,18 @@ class BashScriptsPlugin(PluginBase): results = [] + # Check for power manager commands first + power_results = self._search_power_commands(query) + if power_results: + results.extend(power_results) + # Handle special commands if not query: # Show all scripts when no query results.extend(self._list_all_scripts()) + # Also show power manager commands when no query + if not power_results: + results.extend(self._list_all_power_commands()) else: # Search for scripts results.extend(self._search_scripts(query)) @@ -282,6 +374,80 @@ class BashScriptsPlugin(PluginBase): return results + def _search_power_commands(self, query: str) -> List[Result]: + """Search for power manager commands matching the query.""" + if not query: + return [] + + results = [] + query_lower = query.lower() + + for cmd, info in self.power_manager_commands.items(): + cmd_lower = cmd.lower() + description_lower = info["description"].lower() + + # Check for exact match or partial match + if (query_lower == cmd_lower or + cmd_lower.startswith(query_lower) or + query_lower in cmd_lower or + query_lower in description_lower): + + relevance = 1.0 if query_lower == cmd_lower else 0.9 + + result = Result( + title=cmd, + subtitle=info["description"], + icon_markup=info["icon"], + action=self._create_power_action(info["profile"]), + relevance=relevance, + plugin_name=self.display_name, + data={"command": cmd, "profile": info["profile"], "type": "power_manager"} + ) + results.append(result) + + return results + + def _list_all_power_commands(self) -> List[Result]: + """List all power manager commands.""" + results = [] + + for cmd, info in self.power_manager_commands.items(): + result = Result( + title=cmd, + subtitle=info["description"], + icon_markup=info["icon"], + action=self._create_power_action(info["profile"]), + relevance=0.8, + plugin_name=self.display_name, + data={"command": cmd, "profile": info["profile"], "type": "power_manager"} + ) + results.append(result) + + return results + + def _create_power_action(self, profile: str): + """Create an action function for setting power profile.""" + def action(): + success = self._set_power_profile(profile) + if success: + # Clear the search query after successful execution + try: + from fabric import Application + from gi.repository import GLib + + app = Application.get_default() + if app and hasattr(app, "launcher"): + launcher = app.launcher + if launcher and hasattr(launcher, "search_entry"): + def clear_search(): + launcher.search_entry.set_text("") + return False + # Use a small delay to ensure the action completes first + GLib.timeout_add(50, clear_search) + except Exception as e: + print(f"BashScriptsPlugin: Could not clear search query: {e}") + return action + def _create_script_result(self, script_name: str, script_info: Dict, relevance: float) -> Result: """Create a Result object for a script.""" script_path = script_info.get("path", "")