Skip to content

core: Add with_existing_context for callers that need a platform - #13733

Merged
ogoffart merged 1 commit into
slint-ui:masterfrom
jfarmer:with-existing-context
Oct 2, 2026
Merged

ogoffart merged 1 commit into
slint-ui:masterfrom
jfarmer:with-existing-context

Conversation

@jfarmer

@jfarmer jfarmer commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #13684, as discussed there.

Most callers of with_global_context only want a context that already exists. They passed a factory that panics or returns NoPlatform, and since #13684 with_global_context starts a font scan before it calls that factory.

with_existing_context(f) takes no factory. It returns AlreadySet when another thread installed the event-loop proxy through set_platform, and NoPlatform otherwise. These are the errors with_global_context returned 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-interpreter builds for wasm32.

Built with assistance from Claude Code

  • I license this and all my future contributions to Slint under the MIT-0 license. They are my own work, and no third party (such as my employer) holds rights to them.

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 ogoffart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@jfarmer

jfarmer commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

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)

Happy to do that, just let me know.

@ogoffart
ogoffart merged commit e3cd8f1 into slint-ui:master Oct 2, 2026
52 checks passed
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

1 active deployment
pr-preview-13733 — f9fe7410 Deployed Sep 30, 2026 by github-actions[bot]
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.

2 participants