add some log in case of unexpected error

This commit is contained in:
fdev31 2023-09-14 18:42:17 +02:00
parent 43619bc1ca
commit 19b9741ec3
2 changed files with 37 additions and 1 deletions

View file

@ -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)

View file

@ -3,6 +3,7 @@ import asyncio
import os import os
import subprocess import subprocess
from typing import Any, cast from typing import Any, cast
import logging
from ..ipc import get_focused_monitor_props, hyprctl, hyprctlJSON from ..ipc import get_focused_monitor_props, hyprctl, hyprctlJSON
from .interface import Plugin from .interface import Plugin
@ -82,6 +83,7 @@ class Animations:
class Scratch: class Scratch:
"A scratchpad state including configuration & client state" "A scratchpad state including configuration & client state"
log = logging.getLogger("scratch")
def __init__(self, uid, opts): def __init__(self, uid, opts):
self.uid = uid self.uid = uid
@ -118,7 +120,14 @@ class Scratch:
"update the internal client info property, if not provided, refresh based on the current address" "update the internal client info property, if not provided, refresh based on the current address"
if client_info is None: if client_info is None:
client_info = await get_client_props_by_address("0x" + self.address) client_info = await get_client_props_by_address("0x" + self.address)
try:
assert isinstance(client_info, dict) 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) self.client_info.update(client_info)
def __str__(self): def __str__(self):