From 19b9741ec33eee2d9f436efda05b8e9a6a240af4 Mon Sep 17 00:00:00 2001 From: fdev31 Date: Thu, 14 Sep 2023 18:42:17 +0200 Subject: [PATCH] add some log in case of unexpected error --- pyprland/plugins/ironbar.py | 27 +++++++++++++++++++++++++++ pyprland/plugins/scratchpads.py | 11 ++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 pyprland/plugins/ironbar.py diff --git a/pyprland/plugins/ironbar.py b/pyprland/plugins/ironbar.py new file mode 100644 index 0000000..219d0e8 --- /dev/null +++ b/pyprland/plugins/ironbar.py @@ -0,0 +1,27 @@ +" Ironbar Plugin " +import os +import json +import asyncio + +from .interface import Plugin + +SOCKET = f"/run/user/{os.getuid()}/ironbar-ipc.sock" + + +async def ipcCall(**params): + ctl_reader, ctl_writer = await asyncio.open_unix_connection(SOCKET) + ctl_writer.write(json.dumps(params).encode("utf-8")) + await ctl_writer.drain() + ret = await ctl_reader.read() + ctl_writer.close() + await ctl_writer.wait_closed() + return json.loads(ret) + + +class Extension(Plugin): + "Toggles ironbar on/off" + is_visible = True + + async def run_toggle_ironbar(self, bar_name: str): + self.is_visible = not self.is_visible + await ipcCall(type="set_visible", visible=self.is_visible, bar_name=bar_name) diff --git a/pyprland/plugins/scratchpads.py b/pyprland/plugins/scratchpads.py index e7b37f3..43ff936 100644 --- a/pyprland/plugins/scratchpads.py +++ b/pyprland/plugins/scratchpads.py @@ -3,6 +3,7 @@ import asyncio import os import subprocess from typing import Any, cast +import logging from ..ipc import get_focused_monitor_props, hyprctl, hyprctlJSON from .interface import Plugin @@ -82,6 +83,7 @@ class Animations: class Scratch: "A scratchpad state including configuration & client state" + log = logging.getLogger("scratch") def __init__(self, uid, opts): self.uid = uid @@ -118,7 +120,14 @@ class Scratch: "update the internal client info property, if not provided, refresh based on the current address" if client_info is None: client_info = await get_client_props_by_address("0x" + self.address) - assert isinstance(client_info, dict) + try: + assert isinstance(client_info, dict) + except AssertionError as e: + self.log.error( + f"client_info of {self.address} must be a dict: {client_info}" + ) + raise AssertionError(e) from e + self.client_info.update(client_info) def __str__(self):