Skip to content

[BUG] in window.filter global.active is set as a temporary table by WF:isWindowAllowed which conflicts with startAppWatcher #3795

@avegetablechicken

Description

@avegetablechicken

Window filters in my scripts do not subscribe to any window events when hammerspoon loads, which means WF:isWindowAllowed may be called before startAppWatcher (called by WF:subscribe & WF:getWindows). Thus in WF:isWindowAllowed, the global.activate is set as a table filled with necessary data only for WF:isWindowAllowed, which is invalid for startAppWatcher where global.activate is assumed to be an instance of App with a deactivated method. It leads to error when calling WF:subscribe or WF:getWindows (thus calling startApplWatcher) after calling WF:isWindowAllowed

The bug can be fixed by adding a check in App:getAppWindows:

-- events aren't "inserted" across apps (param name notwithstanding) so an active app should NOT :deactivate
-- another app, otherwise the latter's :unfocused will have a broken "inserted" chain with nothing to close it
function App:getAppWindows()
  self:getCurrentSpaceAppWindows()
  self:getFocused()
  if self.app:isFrontmost() then
    log.df('app %s is the frontmost app',self.name)
-    if global.active then global.active:deactivated() end --see comment above
+    if global.active and global.active.deactivated then global.active:deactivated() end --see comment above
    global.active = self
    if self.focused then
      self.focused:focused(true)
      log.df('window %d is the focused window',self.focused.id)
    end
  end
end

I have not experienced bugs since. But maybe we should add a similar check in App:activated too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions