Skip to content

Commit 5fcc817

Browse files
gitmsrcmsj
authored andcommitted
The event handler might receive an invalid pid
Sometimes an app generates an event just before dying/terminating thus the event handler tries to retrieve the app of the PID but it is no longer available. This patch avoids a crash due to not finding the app for the given pid
1 parent 530e084 commit 5fcc817

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

extensions/window/window_filter.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,14 @@ local windowWatcherDelayed={}
13751375

13761376
appWindowEvent=function(win,event,_,pid,retry)
13771377
if not win:isWindow() then return end
1378-
local appname = application.applicationForPID(pid):name()
1378+
local app = application.applicationForPID(pid)
1379+
if not app then
1380+
-- it is very likely the PID died/terminated before this code
1381+
-- gets executed
1382+
-- simply ignore event
1383+
return
1384+
end
1385+
local appname = app:name()
13791386
local role=win.subrole and win:subrole()
13801387
if appname=='Hammerspoon' and (not role or role=='AXUnknown') then return end
13811388
local id = win.id and win:id()

0 commit comments

Comments
 (0)