diff --git a/README.md b/README.md index b8d953b..d4ef570 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Host process for multiple Hyprland plugins, such as: Check the [Getting started](https://github.com/hyprland-community/pyprland/wiki/Getting-started) page and the [plugins list](https://github.com/hyprland-community/pyprland/wiki/Plugins), finally browse the [wiki](https://github.com/hyprland-community/pyprland/wiki) for more information. +# WIP + +- Using hyprland's notifications in case of serious errors + # 1.5.0 - Add support for a [TOML](https://toml.io/) configuration file, will be used if found (instead of JSON) diff --git a/pyprland/command.py b/pyprland/command.py index bc46d9b..d342598 100755 --- a/pyprland/command.py +++ b/pyprland/command.py @@ -11,7 +11,7 @@ from collections import defaultdict from .common import PyprError, get_logger, init_logger -from .ipc import get_event_stream +from .ipc import get_event_stream, notify_error, notify_fatal, notify_info from .ipc import init as ipc_init from .plugins.interface import Plugin @@ -77,8 +77,12 @@ async def load_config(self, init=True): self.plugins[name] = plug except ModuleNotFoundError: self.log.error("Unable to locate plugin called '%s'", name) + await notify_info( + f'Config requires plugin "{name}" but pypr can\'t find it' + ) continue except Exception as e: + await notify_info(f"Error loading plugin {name}: {e}") self.log.error("Error loading plugin %s:", name, exc_info=True) raise PyprError() from e if init: @@ -87,6 +91,7 @@ async def load_config(self, init=True): except PyprError: raise except Exception as e: + await notify_info(f"Error initializing plugin {name}: {e}") self.log.error("Error initializing plugin %s:", name, exc_info=True) raise PyprError() from e @@ -103,11 +108,15 @@ async def _callHandler(self, full_name, *params): "Bug detected, please report on https://github.com/fdev31/pyprland/issues" ) self.log.exception(e) + await notify_error( + f"Pypr integrity check failed on {plugin.name}::{full_name}: {e}" + ) except Exception as e: # pylint: disable=W0718 self.log.warning( "%s::%s(%s) failed:", plugin.name, full_name, params ) self.log.exception(e) + await notify_error(f"Pypr error {plugin.name}::{full_name}: {e}") break else: return False @@ -206,9 +215,15 @@ async def run_daemon(): try: await manager.load_config() # ensure sockets are connected first except PyprError as e: + if bool(str(e)): + await notify_fatal(f"Pypr failed to start: {e}") + else: + await notify_fatal("Pypr failed to start!") + raise SystemExit(1) from e except Exception as e: manager.log.critical("Failed to load config.", exc_info=True) + await notify_fatal(f"Pypr couldn't load config: {e}") raise SystemExit(1) from e try: @@ -253,6 +268,7 @@ async def run_client(): _, writer = await asyncio.open_unix_connection(CONTROL) except (ConnectionRefusedError, FileNotFoundError) as e: manager.log.critical("Failed to open control socket, is pypr daemon running ?") + await notify_error("Pypr can't connect, is daemon running ?") raise PyprError() from e writer.write((" ".join(sys.argv[1:])).encode()) diff --git a/pyprland/ipc.py b/pyprland/ipc.py index ea269dd..14c6c53 100644 --- a/pyprland/ipc.py +++ b/pyprland/ipc.py @@ -3,8 +3,9 @@ import asyncio import json import os -from logging import Logger from typing import Any +from logging import Logger +from functools import partial from .common import PyprError, get_logger @@ -14,6 +15,16 @@ EVENTS = f'/tmp/hypr/{ os.environ["HYPRLAND_INSTANCE_SIGNATURE"] }/.socket2.sock' +async def notify(text, duration=3, color="ff1010", icon=-1): + "Uses hyprland notification system" + await hyprctl(f"{icon} {int(duration*1000)} rgb({color}) {text}", "notify") + + +notify_fatal = partial(notify, icon=3, duration=10) +notify_error = partial(notify, icon=1, duration=5) +notify_info = partial(notify, icon=2, duration=5) + + async def get_event_stream(): "Returns a new event socket connection" return await asyncio.open_unix_connection(EVENTS)