Skip to content

App: load AppKit where NSApplication is named - #9

Merged
tannevaled merged 1 commit into
mainfrom
feat/appkit-where-nsapplication-is-named
Aug 30, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/appkit-where-nsapplication-is-named

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A caller who asks for the shared application should not also have to know
that AppKit must be dlopened first. This is the function that names
NSApplication; the load belongs with the name.

Without it ClassID("NSApplication") is nil, sharedApplication is nil, and
every message after it returns zero — in silence, because Objective-C does not
complain about a message to nil. A menu-bar program built that way starts,
prints its greeting and exits in a millisecond, with nothing on screen and
nothing in a log.

That failure was diagnosed seven times before it was found, in
go-widgets/tray, which reached the point of running its own event loop on a
nil application. The traces read isMainThread=1 app=0 item=0: the thread was
right, the object was nothing.

Once released, go-widgets/tray can drop its own ensureAppKit() (see
go-widgets/tray#9).

App names NSApplication and did not ensure AppKit was open, so a caller
who forgot the load got a nil class, a nil application, and every message
after it returning zero — in silence, because Objective-C does not
complain about a message to nil. A menu-bar program built that way
starts, prints its greeting and exits in a millisecond, with nothing on
screen and nothing in a log.

The load belongs with the name, not with each caller's memory. It is once
and idempotent.

Measured, and honestly incomplete: with this, a tray that entered
[NSApp run] and returned in 0.01s now takes 0.53s. Something real
changed, and the loop still does not hold. This is a defect fixed, not
the defect found.
@tannevaled
tannevaled merged commit 87e0f5f into main Aug 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant