hyprland-community / pyprland

Scratchpads & many goodies for Hyprland [maintainer=@fdev31]
MIT License
339 stars 15 forks source link

[FEAT] [Scratchpads] Improved error handling and recovery #125

Open punk-dev-robot opened 1 month ago

punk-dev-robot commented 1 month ago

Is your feature request related to a problem? Please describe. Sometimes when a scratchpad app crashes or I close it by mistake it causes pyprland to stop working, not only for that app but also for other scratchpads.

Describe the solution you'd like It would be great if it could handle errors like that more gracefully and provide options to recover. Maybe a notify-send system notification with some actions like stop tracking relaunch (that would run exec again and update process_id)

fdev31 commented 1 month ago

Can you provide a relatively simple setup which is a "worst case" in terms of scratchpad management when the window is closed ? (this is typically supported and isn't failing... so that must be with a specific config/unsupported app).

axelKeizoStahl commented 1 month ago

@kuba-gaj Can you give steps to reproduce? When using Firefox and Kitty, I close kitty and when trying to reopen kitty it launches again and everything is alright.

punk-dev-robot commented 1 month ago

I think it's mostly electron and pwa apps. But sometimes it feels random. I can replicate it easily with slack app:

[scratchpads.slack]
animation = "fromBottom"
command = "/usr/bin/slack --ozone-platform=wayland --enable-features=UseOzonePlatform,WebRTCPipeWireCapturer,WaylandWindowDecorations"
match_by = "initialTitle"
initialTitle = "re:.*Slack$"
class = "Slack"
size = "90% 90%"
max_size = "1920px 90%"
excludes = "*"

It is tracked by initialTitle because I think there was problem with class if I get logged out and see login screen first. After closing slack or other scratchpads stop working, including kitty with an error:

1425   │ Jul 16 00:16:49 arch pypr[9887]: [07/16/24, 00:16:49:804] info: [VISIBILITY-STATE] (T033J3T2Y) Main window visibility state changed: hidden
1426   │ Jul 16 00:16:51 arch pypr[2840]: ERROR:scratch:The client window 0x582467562000 vanished
1427   │ Jul 16 00:16:51 arch pypr[2840]: scratchpads::run_toggle(('slack',)) failed:
1428   │ Jul 16 00:16:51 arch pypr[2840]: Traceback (most recent call last):
1429   │ Jul 16 00:16:51 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 208, in _run_plugin_handler
1430   │ Jul 16 00:16:51 arch pypr[2840]:     await getattr(plugin, full_name)(*params)
1431   │ Jul 16 00:16:51 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 464, in run_toggle
1432   │ Jul 16 00:16:51 arch pypr[2840]:     await asyncio.gather(*(asyncio.create_task(t()) for t in tasks))
1433   │ Jul 16 00:16:51 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 726, in run_hide
1434   │ Jul 16 00:16:51 arch pypr[2840]:     await scratch.update_client_info(clients=clients)
1435   │ Jul 16 00:16:51 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/objects.py", line 159, in update_client_info
1436   │ Jul 16 00:16:51 arch pypr[2840]:     raise KeyError(msg)
1437   │ Jul 16 00:16:51 arch pypr[2840]: KeyError: 'Client window 0x582467562000 not found'
1438   │ Jul 16 00:16:52 arch pypr[2840]: ERROR:scratch:The client window 0x582467562000 vanished
1439   │ Jul 16 00:16:52 arch pypr[2840]: scratchpads::run_toggle(('dropterm',)) failed:
1440   │ Jul 16 00:16:52 arch pypr[2840]: Traceback (most recent call last):
1441   │ Jul 16 00:16:52 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/command.py", line 208, in _run_plugin_handler
1442   │ Jul 16 00:16:52 arch pypr[2840]:     await getattr(plugin, full_name)(*params)
1443   │ Jul 16 00:16:52 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 464, in run_toggle
1444   │ Jul 16 00:16:52 arch pypr[2840]:     await asyncio.gather(*(asyncio.create_task(t()) for t in tasks))
1445   │ Jul 16 00:16:52 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 549, in run_show
1446   │ Jul 16 00:16:52 arch pypr[2840]:     await self.run_hide(e_uid, autohide=True)
1447   │ Jul 16 00:16:52 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/__init__.py", line 726, in run_hide
1448   │ Jul 16 00:16:52 arch pypr[2840]:     await scratch.update_client_info(clients=clients)
1449   │ Jul 16 00:16:52 arch pypr[2840]:   File "/usr/lib/python3.12/site-packages/pyprland/plugins/scratchpads/objects.py", line 159, in update_client_info
1450   │ Jul 16 00:16:52 arch pypr[2840]:     raise KeyError(msg)
1451   │ Jul 16 00:16:52 arch pypr[2840]: KeyError: 'Client window 0x582467562000 not found'
fdev31 commented 1 month ago

I am not sure I want to add complexity for the PWA apps, I think it's already a bit borderline... Can you see if #127 can be a solution to this problem too?