Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt6.QtGui import QScreen
from PyQt6.QtWidgets import QFrame, QGridLayout, QHBoxLayout, QWidget

import pretty_log as _log
from core.bar_helper import AutoHideManager, BarContextMenu, FullscreenManager, OsThemeManager
from core.event_service import EventService
from core.utils.utilities import is_valid_percentage_str, percent_to_float
Expand Down Expand Up @@ -96,15 +97,15 @@ def __init__(
self._os_theme_manager = OsThemeManager(self._bar_frame, self)
self._os_theme_manager.update_theme_class()
except Exception as e:
logging.error(f"Failed to initialize theme manager: {e}")
_log.log_error("Failed to initialize theme manager", e)
self._os_theme_manager = None

# Initialize fullscreen manager
if self._window_flags["hide_on_fullscreen"] and self._window_flags["always_on_top"]:
try:
self._fullscreen_manager = FullscreenManager(self, self)
except Exception as e:
logging.error(f"Failed to initialize fullscreen manager: {e}")
_log.log_error("Failed to initialize fullscreen manager", e)
self._fullscreen_manager = None

self.position_bar(init)
Expand Down
21 changes: 11 additions & 10 deletions src/core/bar_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
QWidgetAction,
)

import pretty_log as _log
from core.utils.controller import exit_application, reload_application
from core.utils.utilities import refresh_widget_style
from core.utils.win32.bindings import DwmGetWindowAttribute
Expand Down Expand Up @@ -220,14 +221,14 @@ def start_monitoring(self):
try:
self._timer.start()
except Exception as e:
logging.error(f"Failed to start fullscreen polling: {e}")
_log.log_error("Failed to start fullscreen polling", e)

def stop_monitoring(self):
"""Stop monitoring for fullscreen applications"""
try:
self._timer.stop()
except Exception as e:
logging.error(f"Failed to stop fullscreen polling: {e}")
_log.log_error("Failed to stop fullscreen polling", e)

def is_window_cloaked(self, hwnd):
"""Check if a window is cloaked (hidden by DWM)"""
Expand Down Expand Up @@ -417,7 +418,7 @@ def detect_os_theme(self) -> bool:
value, _ = winreg.QueryValueEx(key, "AppsUseLightTheme")
return value == 0
except Exception as e:
logging.error(f"Failed to determine Windows theme: {e}")
_log.log_error("Failed to determine Windows theme", e)
return False

def update_theme_class(self):
Expand Down Expand Up @@ -518,7 +519,7 @@ def _on_menu_about_to_hide(self):
self.parent._autohide_manager._hide_timer.start(self.parent._autohide_manager._autohide_delay)

except Exception as e:
logging.error(f"Failed to restart autohide timer: {e}")
_log.log_error("Failed to restart autohide timer", e)

def _populate_widgets_menu(self, widgets_menu):
if not any(self._widgets.get(layout) for layout in ["left", "center", "right"]):
Expand Down Expand Up @@ -593,7 +594,7 @@ def controlled_hide():
widget.hide = controlled_hide

except Exception as e:
logging.error(f"Failed to toggle widget {self._get_widget_display_name(widget)}: {e}")
_log.log_error(f"Failed to toggle widget {self._get_widget_display_name(widget)}", e)

def _get_widget_display_name(self, widget):
for layout_type, widget_list in self._widgets.items():
Expand All @@ -613,7 +614,7 @@ def _open_task_manager(self):
try:
subprocess.Popen("taskmgr", shell=True, creationflags=subprocess.CREATE_NO_WINDOW)
except Exception as e:
logging.error(f"Failed to open Task Manager: {e}")
_log.log_error("Failed to open Task Manager", e)

def _take_screenshot(self):
"""Take a screenshot of the bar with proper padding"""
Expand Down Expand Up @@ -669,7 +670,7 @@ def _take_screenshot(self):
self._screenshot_flash()

except Exception as e:
logging.error(f"Failed to take screenshot: {e}")
_log.log_error("Failed to take screenshot", e)

def _screenshot_flash(self):
"""Create a flashing effect on the bar when taking screenshot"""
Expand All @@ -688,7 +689,7 @@ def _screenshot_flash(self):
self.flash_animation.start()

except Exception as e:
logging.error(f"Failed to create flash effect: {e}")
_log.log_error("Failed to create flash effect", e)

def _enable_autohide(self):
"""Enable autohide functionality for the bar"""
Expand All @@ -702,7 +703,7 @@ def _enable_autohide(self):
self.parent._autohide_manager.setup_autohide()

except Exception as e:
logging.error(f"Failed to enable autohide: {e}")
_log.log_error("Failed to enable autohide", e)

def _disable_autohide(self):
"""Disable autohide functionality"""
Expand All @@ -716,4 +717,4 @@ def _disable_autohide(self):
self.parent.show()

except Exception as e:
logging.error(f"Failed to disable autohide: {e}")
_log.log_error("Failed to disable autohide", e)
3 changes: 2 additions & 1 deletion src/core/bar_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from PyQt6.QtGui import QScreen
from PyQt6.QtWidgets import QApplication

import pretty_log as _log
from core.bar import Bar
from core.config import get_config, get_stylesheet
from core.event_service import EventService
Expand Down Expand Up @@ -53,7 +54,7 @@ def on_config_modified(self):
try:
config = get_config(show_error_dialog=True)
except Exception as e:
logging.error(f"Error loading config: {e}")
_log.log_error("Error loading config", e)
return
if config and (config != self.config):
if any(
Expand Down
5 changes: 3 additions & 2 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from yaml import dump, safe_load
from yaml.parser import ParserError

import pretty_log as _log
import settings
from core.utils.alert_dialog import raise_info_alert
from core.utils.css_processor import CSSProcessor
Expand Down Expand Up @@ -121,7 +122,7 @@ def get_config(show_error_dialog=False) -> Union[dict, None]:
additional_details=pretty_errors,
)
except ParserError as e:
logging.error(f"The file '{config_path}' contains Parser Error(s). Please fix:\n{str(e)}")
_log.log_error(f"The file '{config_path}' contains Parser Error(s). Please fix", e)
except FileNotFoundError:
logging.error(f"The file '{config_path}' could not be found. Does it exist?")
except OSError:
Expand All @@ -136,7 +137,7 @@ def get_stylesheet(show_error_dialog=False) -> Union[str, None]:
return css_content

except SyntaxErr as e:
logging.error(f"The file '{styles_path}' contains Syntax Error(s). Please fix:\n{str(e)}")
_log.log_error(f"The file '{styles_path}' contains Syntax Error(s). Please fix:", e)
if show_error_dialog:
raise_info_alert(
title="Failed to load recently updated stylesheet file.",
Expand Down
12 changes: 6 additions & 6 deletions src/core/tray.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import shutil
import subprocess
Expand All @@ -10,6 +9,7 @@
from PyQt6.QtGui import QCursor, QIcon
from PyQt6.QtWidgets import QMenu, QSystemTrayIcon

import pretty_log as _log
from core.bar_manager import BarManager
from core.config import get_config
from core.ui.windows.about import AboutDialog
Expand Down Expand Up @@ -61,7 +61,7 @@ def _load_config(self):
try:
config = get_config(show_error_dialog=True)
except Exception as e:
logging.error(f"Error loading config: {e}")
_log.log_error("Error loading config", e)
return
if config["komorebi"]:
self.komorebi_start = config["komorebi"]["start_command"]
Expand Down Expand Up @@ -205,7 +205,7 @@ def is_wm_installed(self, wm) -> bool:
wm_path = shutil.which(wm)
return wm_path is not None
except Exception as e:
logging.error(f"Error checking {wm} installation: {e}")
_log.log_error(f"Error checking {wm} installation", e)
return False

def _enable_startup(self):
Expand All @@ -224,7 +224,7 @@ def _open_config(self):
try:
subprocess.run(["explorer", str(os.path.join(Path.home(), DEFAULT_CONFIG_DIRECTORY))])
except Exception as e:
logging.error(f"Failed to open config directory: {e}")
_log.log_error("Failed to open config directory", e)

def _run_wm_command(self, wm, command):
def wm_command():
Expand All @@ -237,7 +237,7 @@ def wm_command():
creationflags=subprocess.CREATE_NO_WINDOW,
)
except Exception as e:
logging.error(f"Failed to start {wm}: {e}")
_log.log_error(f"Failed to start {wm}", e)

threading.Thread(target=wm_command).start()

Expand All @@ -251,7 +251,7 @@ def _open_in_browser(self, url):
try:
webbrowser.open(url)
except Exception as e:
logging.error(f"Failed to open browser: {e}")
_log.log_error("Failed to open browser", e)

def _show_about_dialog(self):
dialog = AboutDialog(self)
Expand Down
3 changes: 2 additions & 1 deletion src/core/utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt6.QtCore import QMetaObject, QProcess, Qt
from PyQt6.QtWidgets import QApplication

import pretty_log as _log
from core.event_service import EventService
from core.utils.cli_server import CliPipeHandler
from core.utils.win32.utilities import find_focused_screen
Expand All @@ -27,7 +28,7 @@ def reload_application(msg="Reloading Application..."):
if app is not None:
QMetaObject.invokeMethod(app, "quit", Qt.ConnectionType.QueuedConnection)
except Exception as e:
logging.error(f"Error during reload: {e}")
_log.log_error("Error during reload", e)
os._exit(0)


Expand Down
4 changes: 3 additions & 1 deletion src/core/utils/css_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
from typing import Dict, Set

import pretty_log as _log


class CSSProcessor:
"""
Expand Down Expand Up @@ -38,7 +40,7 @@ def _read_css_file(self, file_path: str) -> str:
with open(file_path, "r", encoding="utf-8") as file:
return file.read()
except (FileNotFoundError, OSError) as e:
logging.error(f"CSSProcessor Error '{file_path}': {e}")
_log.log_error(f"CSSProcessor Error '{file_path}'", e)
return ""

def _remove_comments(self, css: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions src/core/utils/update_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import certifi

import pretty_log as _log
from core.utils.utilities import ToastNotifier, app_data_path, get_app_identifier, get_architecture
from settings import APP_ID, BUILD_VERSION, RELEASE_CHANNEL, SCRIPT_PATH

Expand Down Expand Up @@ -275,10 +276,10 @@ def check_for_updates(
logging.warning(f"Network error checking for updates: {e.reason}")
raise
except json.JSONDecodeError as e:
logging.error(f"Failed to parse GitHub API response: {e}")
_log.log_error("Failed to parse GitHub API response", e)
raise ValueError("Invalid JSON response from GitHub API")
except Exception as e:
logging.error(f"Unexpected error checking for updates: {e}")
_log.log_error("Unexpected error checking for updates", e)
raise

def should_check_for_updates(self) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions src/core/utils/win32/app_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from PIL import Image
from win32con import DIB_RGB_COLORS

import pretty_log as _log
from core.utils.win32.aumid import GetApplicationUserModelId, get_aumid_for_window
from core.utils.win32.aumid_icons import get_icon_for_aumid
from core.utils.win32.bindings import (
Expand Down Expand Up @@ -174,7 +175,7 @@ def _is_fully_transparent(img: Image.Image) -> bool:

return None
except Exception as e:
logging.error(f"Error fetching icon: {e}")
_log.log_error("Error fetching icon", e)
return None


Expand Down Expand Up @@ -410,5 +411,5 @@ def get_stock_icon(icon_id: int) -> Image.Image | None:
pass

except Exception as e:
logging.error(f"Error getting stock icon {icon_id}: {e}")
_log.log_error(f"Error getting stock icon {icon_id}", e)
return None
9 changes: 5 additions & 4 deletions src/core/utils/win32/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from win32gui import GetClassName, GetWindowPlacement, GetWindowRect, GetWindowText
from winrt.windows.management.deployment import PackageManager

import pretty_log as _log
from core.utils.utilities import is_windows_10
from core.utils.win32.bindings import (
CloseHandle,
Expand Down Expand Up @@ -349,7 +350,7 @@ def is_valid(name):
if screen.geometry().contains(pos) and is_valid(screen.name()):
return screen.name()
except Exception as e:
logging.error(f"Exception in follow_mouse: {e}")
_log.log_error("Exception in follow_mouse", e)

if follow_window:
hwnd = win32gui.GetForegroundWindow()
Expand Down Expand Up @@ -384,7 +385,7 @@ def enable_autostart(app_name: str, executable_path: str) -> bool:
logging.info(f"{app_name} added to startup")
return True
except Exception as e:
logging.error(f"Failed to add {app_name} to startup: {e}")
_log.log_error(f"Failed to add {app_name} to startup", e)
return False


Expand All @@ -400,7 +401,7 @@ def disable_autostart(app_name: str) -> bool:
logging.info(f"Startup entry for {app_name} not found")
return True
except Exception as e:
logging.error(f"Failed to remove {app_name} from startup: {e}")
_log.log_error(f"Failed to remove {app_name} from startup", e)
return False


Expand All @@ -413,5 +414,5 @@ def is_autostart_enabled(app_name: str) -> bool:
except WindowsError:
return False
except Exception as e:
logging.error(f"Failed to check startup status for {app_name}: {e}")
_log.log_error(f"Failed to check startup status for {app_name}", e)
return False
7 changes: 4 additions & 3 deletions src/core/utils/win32/window_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import win32con
import win32process

import pretty_log as _log
from core.utils.win32.bindings import kernel32 as k32
from core.utils.win32.bindings import user32 as u32

Expand Down Expand Up @@ -209,7 +210,7 @@ def close_application(hwnd: int, force: bool = False):
try:
_, process_id = win32process.GetWindowThreadProcessId(hwnd)
except Exception as e:
logging.error(f"Failed to get process ID for HWND {hwnd}: {e}")
_log.log_error(f"Failed to get process ID for HWND {hwnd}", e)
return

if not process_id:
Expand Down Expand Up @@ -247,7 +248,7 @@ def close_application(hwnd: int, force: bool = False):
k32.CloseHandle(process_handle)

except Exception as term_ex:
logging.error(f"Failed to terminate process {process_id}: {term_ex}")
_log.log_error(f"Failed to terminate process {process_id}", term_ex)

else:
# Graceful close path
Expand Down Expand Up @@ -286,4 +287,4 @@ def close_application(hwnd: int, force: bool = False):
logging.warning(f"EndTask unavailable/failed for HWND {target_hwnd}: {et_ex}")

except Exception as e:
logging.error(f"Failed to close window {hwnd}: {e}")
_log.log_error(f"Failed to close window {hwnd}", e)
Loading