Repository navigation
core: Add with_existing_context for callers that need a platform - #13733
Merged
Merged
Conversation
Most callers of with_global_context only want a context that already exists. They passed a factory that panics or fails, and with_global_context now starts a font scan before it calls that factory. with_existing_context takes no factory. It returns AlreadySet when another thread installed the event-loop proxy through set_platform, and NoPlatform otherwise, which is what with_global_context returned for those callers. The 11 callers that never created a platform use it. Those that passed a panicking factory use expect() with the same message. Built with assistance from Claude Code
ogoffart
approved these changes
Sep 30, 2026
ogoffart
left a comment
Member
There was a problem hiding this comment.
looks good to me.
Although perhaps should be name with_existing_global_context to make it more explicit that this is a "bad" function (as we are trying to get rid of the global context)
Contributor
Author
Happy to do that, just let me know. |
bigtree108-dmytro
added a commit
to bigtree108-dmytro/slint
that referenced
this pull request
Oct 5, 2026
Follows slint-ui#13733, which moved set_system_accent_color and the other testing helpers from with_global_context with a panicking factory to with_existing_context.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Follow-up to #13684, as discussed there.
Most callers of
with_global_contextonly want a context that already exists. They passed a factory that panics or returnsNoPlatform, and since #13684with_global_contextstarts a font scan before it calls that factory.with_existing_context(f)takes no factory. It returnsAlreadySetwhen another thread installed the event-loop proxy throughset_platform, andNoPlatformotherwise. These are the errorswith_global_contextreturned for these callers.The 11 callers that never created a platform use it. Those that passed a panicking factory now call
expect()with the same message. The 2 MCP server sites run on the context's thread, where the error can't occur.1 unit test covers the function. Core, testing, interpreter and winit tests pass on macOS, and
api/wasm-interpreterbuilds for wasm32.Built with assistance from Claude Code