35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
import pygetwindow as gw
|
||
|
import logging
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
class WindowManager:
|
||
|
"""
|
||
|
Manages interactions related to system windows,
|
||
|
primarily retrieving active window titles.
|
||
|
"""
|
||
|
def __init__(self):
|
||
|
logger.info("WindowManager: Initialized.")
|
||
|
|
||
|
def get_window_titles(self):
|
||
|
"""
|
||
|
Retrieves a sorted list of active window titles.
|
||
|
Excludes the utility's own window by its title.
|
||
|
"""
|
||
|
logger.info("WindowManager: Attempting to retrieve active window list.")
|
||
|
try:
|
||
|
all_windows = gw.getAllWindows()
|
||
|
# Filter out empty titles and the utility's own window by its default title
|
||
|
window_titles = sorted(
|
||
|
list(set([
|
||
|
win.title for win in all_windows
|
||
|
if win.title and win.title != "Jarvis Key Press Utility (AHK Integrated)"
|
||
|
]))
|
||
|
)
|
||
|
logger.info(f"WindowManager: Found {len(window_titles)} active windows.")
|
||
|
return window_titles
|
||
|
except Exception as e:
|
||
|
logger.error(f"WindowManager: Failed to retrieve window list: {e}", exc_info=True)
|
||
|
return []
|
||
|
|