quicksilver / Quicksilver

Quicksilver Project Source
http://qsapp.com
Apache License 2.0
2.72k stars 283 forks source link

[Bug]: App specific triggers sometimes do not work right after starting the app. #2919

Closed dhoepfl closed 10 months ago

dhoepfl commented 1 year ago

Before submitting your bug report, please confirm you have completed the following steps

Bug description

I have a trigger who's scope is limited to one app. When I start this app, the trigger does not reliably work. It does work after I switched to a different app and returned to the specific app.

Steps to reproduce

  1. Add a trigger
  2. Limit its scope to an App
  3. Start the App
  4. Try the trigger

Expected behavior

The trigger should work each time.

MacOS Version

macOS 12

Quicksilver Version

Checked out main/Released 2.4.0 (4039)

Relevant Plugins

-/-

Crash Logs or Spindump

-/-

Screenshots

-/-

Additional info

1) QSProcessMonitor.m handles both appChanged (line 51) and appLaunched (line 70) carbon process events. 2) The appLaunched handler schedules an async task on the main thread that posts a notifications on the default notification center. 3) This notification is handled in the future on the main thread and updates the processesDict (in reloadProcesses, line 362). 4) The appChanged handler might be called before step 3 takes place. appChanged uses processObjectWithPSN to get the process information for the newly active app which is not yet stored in processesDict. The result of this call is attached as user info to another notification posted (one of the listeners to this notification updates which triggers are active).

Since in step 4, the processesDict has not been updated in all cases, the newly active app is not known and the triggers do not get updated.

Note: appLaunched calls processObjectWithPSN (in line 80) using the PSN of the new app. This call always returns nil.

I see two ways to fix this:

1) Lazy fix: Drop the call to processObjectWithPSN in appLaunched carbon event handler and move the call to processObjectWithPSN onto the main thread in appChanged.

2) Clean fix: reloadProcesses mentions a addProcessWithPSN which I could not find. If this existed, it should be called in appLaunched (instead of line 80, if it returns the new dictionary) to update the processesDict right away. Everything else could stay the same.

dhoepfl commented 1 year ago

See pull request #2921.