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

[macOS] Display alert by Window #14361

Merged
merged 4 commits into from
Apr 4, 2023
Merged

[macOS] Display alert by Window #14361

merged 4 commits into from
Apr 4, 2023

Conversation

jsuarezruiz
Copy link
Contributor

Description of Change

Display alert by Window on macOS.

fix-14343

This fix is similar to #14229

To test the changes, launch the .NET MAUI Gallery and navigate to Core > MultiWindow. Open a secondary Window and then, tap the button to display an alert. The alert only must appear in the parent Window.

Issues Fixed

Fixes #14343

@jsuarezruiz jsuarezruiz added t/bug Something isn't working platform/macOS 🍏 macOS / Mac Catalyst area-controls-dialogalert DisplayAlert, dialog labels Apr 3, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Apr 3, 2023
Comment on lines -247 to +249
bool PageIsInThisWindow(Page page)
{
var window = page?.Window;
var platformWindow = window?.MauiContext.GetPlatformWindow();

if (window is null || platformWindow is null)
return false;

return platformWindow == Window;
}
bool PageIsInThisWindow(Page page) =>
page?.Window == VirtualView;
Copy link
Member

Choose a reason for hiding this comment

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

The alert manager already knows about the window, so this is now possible. The iOS code had everything set up, but Windows just needed an extra constructor argument for the helper to simplify all this.

@mattleibow mattleibow dismissed mandel-macaque’s stale review April 3, 2023 18:22

All the logic has been rewritten.

@mattleibow mattleibow enabled auto-merge (squash) April 3, 2023 18:24
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

On windows if you close a window while a dialog box is open then dialog boxes stop working all together

  • open the Gallery
  • navigate to core => multi window
  • open a new window
  • click "open dialog" on that new window
  • close the new window without closing the dialog
  • now try to click "open dialog" on the original window

@mattleibow
Copy link
Member

Oh wow. Let me look at that then...

Comment on lines -40 to +41
static Task<bool>? CurrentAlert;
static Task<string?>? CurrentPrompt;
Task<bool>? CurrentAlert;
Task<string?>? CurrentPrompt;
Copy link
Member

Choose a reason for hiding this comment

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

@PureWeen this was causing the issue. No need for statics anymore! We have multiple windows!

@mattleibow mattleibow requested a review from PureWeen April 3, 2023 21:55
@mattleibow mattleibow added the backport/suggested The PR author or issue review has suggested that the change should be backported. label Apr 3, 2023
}

internal void Unsubscribe(Window window)
{
var platformWindow = window.MauiContext.GetPlatformWindow();

var toRemove = Subscriptions.Where(s => s.Window == platformWindow).ToList();
var toRemove = Subscriptions.Where(s => s.PlatformView == platformWindow).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

@PureWeen I though that the use of LINQ was limited, should we remove it from here?

Copy link
Member

@mandel-macaque mandel-macaque left a comment

Choose a reason for hiding this comment

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

Code looks good, I am surprised to see LINQ when a foreach would have worked and made the deps smaller.

@mattleibow mattleibow merged commit d5b4dda into main Apr 4, 2023
@mattleibow mattleibow deleted the fix-14343 branch April 4, 2023 21:29
@hartez hartez added the backport/approved After some discussion or review, this PR or change was approved to be backported. label Jun 14, 2023
@hartez
Copy link
Contributor

hartez commented Jun 14, 2023

/backport to net7.0

@github-actions
Copy link
Contributor

Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5270383073

@github-actions
Copy link
Contributor

@hartez backporting to net7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Display alert by Window on macOS
Applying: Unify the logic a bit
error: sha1 information is lacking or useless (src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Unify the logic a bit
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

@hartez an error occurred while backporting to net7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

hartez added a commit that referenced this pull request Jun 14, 2023
* Display alert by Window on macOS

* Unify the logic a bit

---------

Co-authored-by: Matthew Leibowitz <[email protected]>
rmarinho pushed a commit that referenced this pull request Jun 15, 2023
* Display alert by Window on macOS

* Unify the logic a bit

---------

Co-authored-by: Matthew Leibowitz <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@samhouts samhouts added the fixed-in-8.0.0-preview.4.8333 Look for this fix in 8.0.0-preview.4.8333! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-dialogalert DisplayAlert, dialog backport/approved After some discussion or review, this PR or change was approved to be backported. backport/suggested The PR author or issue review has suggested that the change should be backported. fixed-in-8.0.0-preview.4.8333 Look for this fix in 8.0.0-preview.4.8333! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display alert is popping up on all windows in MacCatalyst instead window / page requested it
7 participants