SMAppService.agent.register() will launch a second instance of an application

Because I can't find a way to share StoreKit purchases between two apps (macOS), I was forced to make my LSUIElement application a single app. This is turning out to work reasonably well, except for one issue that I hadn't noticed before (maybe it's new in 14.2?).

The normal flow is this:

  1. User double-clicks app icon
  2. App calls SMAppService.agent(plistName: "com.myagent.plist").register(). The referenced plist points to the same application binary (see attached project) that the user launched in step 1.
  3. System launches a second instance of the application binary

What I want the call to do instead is see that the app is already running, and just adopt it (that is, if it is killed or crashes, relaunch it).

I see two inelegant workarounds:

  1. Wait until the user is done configuring the app after first launch, register the app and then quit. Thing is, I can't be sure when they're done, e.g. if they don't close the window.
  2. Allow both instances of the app to run, but quit if they close the window and it wasn't launched by launchd, or if there are other instances running. This feels fragile (e.g. if the behavior of register() is ever improved as I'd like).

The best solution, of course, would be to share StoreKit context between apps, so I could separate this into the UI app and background agent.

(To Apple: I've filed FB13574819 with my project attached.)