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

AppInstance redirection APIs don't transfer foreground rights #1439

Closed
andrewleader opened this issue Sep 17, 2021 · 3 comments · Fixed by #1416
Closed

AppInstance redirection APIs don't transfer foreground rights #1439

andrewleader opened this issue Sep 17, 2021 · 3 comments · Fixed by #1416
Assignees
Labels
area-Lifecycle bug Something isn't working
Milestone

Comments

@andrewleader
Copy link
Contributor

Describe the bug

I'm trying to use AppLifecycle.AppInstance redirection APIs to redirect to a single instance (and then bring that instance to the foreground), however it seems the foreground rights aren't being passed to the main instance when using RedirectActivationTo().

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create a WinUI 3 desktop app using 1.0 Preview 1 and add AppInstance with single-instance redirection
    1. Call GetCurrent().GetActivatedEventArgs() first
    2. Then call FindOrRegisterForKey("main")
    3. If that main instance is current, register the Activated event
    4. Otherwise, call main.RedirectActivationToAsync(args)
  2. Within the Activated event, attempt to bring the window to the foreground
    1. Get the DispatcherQueue to enter the UI thread
    2. Then call the Activate() method on your window
    3. Expected: Window comes to foreground
    4. Actual: Nothing happens

Version Info

NuGet package version:

Microsoft.WindowsAppSDK 1.0.0-preview1

Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)

Additional context

@andrewleader
Copy link
Contributor Author

Fixed for 1.0 Preview 2 via #1416

@andrewleader andrewleader added this to the 1.0 Preview 2 milestone Sep 17, 2021
@duracellko
Copy link

How does this work? It doesn't seem to work in my app.

I created small sample.
SingleAppInst.zip

Could you have a look at what is missing there?

When I select the app in the Start menu second time, the app does not go to foreground.

@duracellko
Copy link

How does this work? It doesn't seem to work in my app.

I created small sample. SingleAppInst.zip

Could you have a look at what is missing there?

When I select the app in the Start menu second time, the app does not go to foreground.

I found the way. Instead of Window.Activate() use https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetForegroundWindow(IntPtr hWnd);

IntPtr hWnd = WindowNative.GetWindowHandle(window);
SetForegroundWindow(hWnd);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Lifecycle bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants