improve the launcher and application switcher, now laucher become plugin based fully
This commit is contained in:
34 files changed
+3085
-768
No files matched your search
@@ -4,7 +4,8 @@ Base class for launcher plugins.
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
from .result import Result
|
||||
|
||||
from modules.launcher.result import Result
|
||||
|
||||
|
||||
class PluginBase(ABC):
|
||||
@@ -12,7 +13,7 @@ class PluginBase(ABC):
|
||||
Abstract base class for launcher plugins.
|
||||
All plugins must inherit from this class.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.name = self.__class__.__name__.lower()
|
||||
self.display_name = self.__class__.__name__
|
||||
@@ -20,7 +21,7 @@ class PluginBase(ABC):
|
||||
self.version = "1.0.0"
|
||||
self.enabled = True
|
||||
self._triggers = [] # List of trigger keywords
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def initialize(self):
|
||||
"""
|
||||
@@ -28,7 +29,7 @@ class PluginBase(ABC):
|
||||
Called when the plugin is activated.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def cleanup(self):
|
||||
"""
|
||||
@@ -36,20 +37,20 @@ class PluginBase(ABC):
|
||||
Called when the plugin is deactivated.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def query(self, query_string: str) -> List[Result]:
|
||||
"""
|
||||
Process a search query and return results.
|
||||
|
||||
|
||||
Args:
|
||||
query_string: The search query from the user
|
||||
|
||||
|
||||
Returns:
|
||||
List of Result objects
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def get_triggers(self) -> List[str]:
|
||||
"""
|
||||
Get list of trigger keywords for this plugin.
|
||||
@@ -68,7 +69,7 @@ class PluginBase(ABC):
|
||||
triggers: List of trigger keywords
|
||||
"""
|
||||
self._triggers = triggers
|
||||
|
||||
|
||||
def handles_query(self, query_string: str) -> bool:
|
||||
"""
|
||||
Check if this plugin should handle the given query.
|
||||
@@ -120,8 +121,10 @@ class PluginBase(ABC):
|
||||
|
||||
# Match trigger word followed by space
|
||||
trigger_word = trigger.strip().lower()
|
||||
if (query_lower.startswith(trigger_word + " ") or
|
||||
query_lower == trigger_word):
|
||||
if (
|
||||
query_lower.startswith(trigger_word + " ")
|
||||
or query_lower == trigger_word
|
||||
):
|
||||
return trigger
|
||||
|
||||
return ""
|
||||
@@ -139,13 +142,13 @@ class PluginBase(ABC):
|
||||
List of Result objects
|
||||
"""
|
||||
# Remove trigger from query and process remaining text
|
||||
remaining_query = query_string[len(trigger):].strip()
|
||||
remaining_query = query_string[len(trigger) :].strip()
|
||||
return self.query(remaining_query)
|
||||
|
||||
|
||||
def get_config(self) -> dict:
|
||||
"""
|
||||
Get plugin configuration.
|
||||
|
||||
|
||||
Returns:
|
||||
Dictionary of configuration options
|
||||
"""
|
||||
@@ -156,18 +159,18 @@ class PluginBase(ABC):
|
||||
"version": self.version,
|
||||
"enabled": self.enabled,
|
||||
}
|
||||
|
||||
|
||||
def set_config(self, config: dict):
|
||||
"""
|
||||
Set plugin configuration.
|
||||
|
||||
|
||||
Args:
|
||||
config: Dictionary of configuration options
|
||||
"""
|
||||
self.enabled = config.get("enabled", self.enabled)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"Plugin({self.name})"
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
Reference in new issue
Block a user