Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to register the application delegate on macOS and iOS #3758

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

madsmtm
Copy link
Member

@madsmtm madsmtm commented Jun 24, 2024

Register for event-loop lifecycle events using the NSNotification API instead of application delegates. This gives the user full control over the application delegate, which opens several doors for customization that were previously closed.

In particular, this fixes #1751, closes #3713, fixes #2674, fixes #3499, fixes #3650 and fixes #2141, all by allowing the user to override [NS|UI]ApplicationDelegate themselves outside Winit.

Also fixes #1281 by listening on notifications instead of using the application delegate.

Resolves part of the macOS side of #2120.

  • Tested on all platforms changed
    • macOS
    • iOS
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior

This is a breaking change, although unlikely to matter in practice,
since the return value of `application:didFinishLaunchingWithOptions:`
is seldom used by the system.
This allows the user to override the application delegate themselves,
which opens several doors for customization that were previously closed.
@madsmtm madsmtm force-pushed the madsmtm/remove-app-delegates branch from 39b651e to 4a53350 Compare June 24, 2024 21:53
@madsmtm madsmtm added this to the Version 0.31.0 milestone Jun 24, 2024
Copy link
Member

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

I'm starting to understand the MacOS backend quite a bit now, the cleanup you have done so far is pretty amazing.

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

I'm not that familiar with observers, but it looks ok-ish? I know that it works by appkit basically signalling you when something happens and you can register a lot of observers.

Also does it affect performance/input latency in any aspect or it's all the same because macOS is just giant message passing infra already and dispatching observer is not slower than dispatching regular methods?

);
// TODO(madsmtm): Use `MainThreadBound` once that is possible in `static`s.
thread_local! {
static GLOBAL: OnceCell<Rc<AppState>> = const { OnceCell::new() };
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason to Rc thread local global? I'd assume the main reason is that the user creates it in Rc and shares the pointer with winit, thus it's correctly ref-counted.

And you're using global here just for simplicity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DS - ios DS - macos S - docs Awareness, docs, examples, etc. S - enhancement Wouldn't this be the coolest?
3 participants