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

Make Classic ApplicationLifetime API a bit more reliable #14267

Merged
merged 10 commits into from
Jan 20, 2024

Conversation

maxkatz6
Copy link
Member

What does the pull request do?

I recommend reviewing this PR commit by commit, as there are multiple independent changes.

  1. StartWithClassicDesktopLifetime method now has a builder callback to modify parameters of the lifetime. As a replacement for old "ShutdownMode shutdownMode" parameter. (this change is a low benefit, can be reverted)
  2. Makes it impossible to change Application.ApplicationLifetime after application was already initialized. As it doesn't make sense, and Avalonia won't properly handle it.
  3. Deprecates old Application.UrlsOpened - can be replaced with IActivatableApplicationLifetime which was added previously.
  4. Allow creation of multiple ClassicDesktopStyleApplicationLifetime instances by avoiding static global s_activeLifetime. Instead lifetime should subscribe on window events after it was set-up, and not when it was constructed. And also - unsubscribe from these events.
  5. Introduce SetupWithClassicDesktopLifetime method, that sets up lifetime and handlers, but doesn't run application MainLoop nor doesn't show window.
  6. Adds well missing XML docs.

Breaking changes

Application.ApplicationLifetime cannot be set after application was started. It will throw a runtime error.
Since this never was supported nor properly handled, I wouldn't consider it a blocker for backporting.

Obsoletions / Deprecations

Application.UrlsOpened is obsolete - use IActivatableApplicationLifetime.

@maxkatz6 maxkatz6 added the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Jan 18, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043722-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043740-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Jan 20, 2024
@maxkatz6 maxkatz6 removed this pull request from the merge queue due to a manual request Jan 20, 2024
@maxkatz6 maxkatz6 merged commit 6a71056 into master Jan 20, 2024
7 checks passed
@maxkatz6 maxkatz6 deleted the lifetime-api-fixes branch January 20, 2024 02:38
maxkatz6 added a commit that referenced this pull request Feb 8, 2024
      * Add StartWithClassicDesktopLifetime overload with a lifetime builder

* Disallow changing Application.ApplicationLifetime after setup was completed

* Avoid static dependency on a singleton lifetime

* Introduce SetupWithClassicDesktopLifetime method

* Move more logic from Start method to Setup

* Add docs

* Avoid public API changes

* Fix tests

* Repalce locator usage with `.UseLifetimeOverride`

---------

Co-authored-by: Benedikt Stebner <[email protected]>
@maxkatz6 maxkatz6 added backported-11.0.x and removed backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch labels Feb 8, 2024
@danipen
Copy link

danipen commented Mar 11, 2024

@maxkatz6 regarding this:

Application.UrlsOpened is obsolete - use IActivatableApplicationLifetime.

How can I get the (obsolete) UrlOpenedEventArgs.Urls from the new API?

@maxkatz6
Copy link
Member Author

@danipen
Copy link

danipen commented Mar 11, 2024

Got it! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants