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

Proposal: Allow hosting of UWP apps inside UWP apps #66

Open
matthew4850 opened this issue Jun 2, 2020 · 27 comments
Open

Proposal: Allow hosting of UWP apps inside UWP apps #66

matthew4850 opened this issue Jun 2, 2020 · 27 comments
Assignees

Comments

@matthew4850
Copy link

Proposal: Allow hosting of UWP apps inside UWP apps

Summary

It would be awesome to be able to host a UWP app insider of another one.
This would be similar to what both My People and Xbox game bar do.

Rationale

I am one of the developers of Quarrel which is an unofficial UWP discord client.
The developer of MyTube (an unofficial UWP YouTube client) kindly provided us with a dll that contains large parts of the MyTube code that allows us to host an instance of MyTube inside Quarrel to provide youtube embeds in a way that does not require us to pull in a webview.
However, it would be much better if we could host the store version of MyTube inside Quarrel similarly to how Xbox game bar can host UWP apps.

I imagine there are many other similar cases in which other developers would find this useful.

Scope

Capability Priority
This proposal will allow UWP apps to host other UWP apps Must
This proposal will allow win32 apps to host UWP apps Could

Open Questions

  1. As this is not related directly to WinUI I'm not certain if this is the correct place to ask?
  2. Could this have broader security implications?
  3. Should any UWP app be able to host any other or should it require the hosted UWP app support it?
@michael-hawker
Copy link

This is almost a more scoped version of a request around app extensions.

I mean if we just had C# Roslyn code generation supported in the sandbox, then we could leverage XamlReader and that to do something similar today...

@matthew4850
Copy link
Author

matthew4850 commented Jun 3, 2020

This is almost a more scoped version of a request around app extensions.

I mean if we just had C# Roslyn code generation supported in the sandbox, then we could leverage XamlReader and that to do something similar today...

This is different from app extensions as this should allow you to host a whole uwp app that is activated with ActivationKind::Protocol with a custom scheme name.
This should also be done from a compiled app, not from source.
This can be done already as Xbox game bar does it, I just want that ability for all developers xD

@ranjeshj
Copy link

ranjeshj commented Jun 3, 2020

The title makes me think "UWP Inception" :)

Could the entire app be built as a custom control to achieve something like this ? That way we could leverage all the control library features for sharing/tooling etc ? I suppose that needs extra work on the app side as opposed to just embedding the app wholesale though.

@marcelwgn
Copy link

Would this allow apps to host apps that host apps that host app ... ?

How would/could this impact performance (which is one of the selling points of UWP)? Could we end up in the situation where UWP apps end up just like NPM modules, where we host an app for everything resulting in dozen dependencies?

@matthew4850
Copy link
Author

Would this allow apps to host apps that host apps that host app ... ?

How would/could this impact performance (which is one of the selling points of UWP)? Could we end up in the situation where UWP apps end up just like NPM modules, where we host an app for everything resulting in dozen dependencies?

Nested hosting would be less useful so it's certainly not a requirement.
This would be optional so performance would really be dependant on how you use it but clearly the My People and Xbox game bar teams thought it was performant enough to use.

@shaheedmalik
Copy link

Would this allow apps to host apps that host apps that host app ... ?
How would/could this impact performance (which is one of the selling points of UWP)? Could we end up in the situation where UWP apps end up just like NPM modules, where we host an app for everything resulting in dozen dependencies?

Nested hosting would be less useful so it's certainly not a requirement.
This would be optional so performance would really be dependant on how you use it but clearly the My People and Xbox game bar teams thought it was performant enough to use.

Correct me if I am wrong,, My People relies on app hooks. That's the reason why Facebook or Messenger doesn't tie into it.

@mdtauk
Copy link

mdtauk commented Jun 3, 2020

I am not sure all UWP app developers would like other apps "hosting" their app within other apps.

But, there could be a mechanism for an app creating a "hostable" page or UI - which could be used within other apps.

Some examples being

  • Displaying a contact's details in an app; (people app provider)
  • Loading a YouTube video from another app;
  • Linking to someone's Instagram profile;
  • Creating a Tweet from your photo app; (twitter providing a "compose tweet" UI);

Whether this UI appears in a popup window, or appears embedded in a Provider Hosting control. There would have to be behavioural hooks, so the main app hands over to another app, and is unable to log keystrokes or otherwise intercept the other app's control. But there be a way to handshake so hosted app content can return control to the main app, and send some kind of status message perhaps?

@matthew4850
Copy link
Author

I am not sure all UWP app developers would like other apps "hosting" their app within other apps.

But, there could be a mechanism for an app creating a "hostable" page or UI - which could be used within other apps.

Some examples being

  • Displaying a contact's details in an app; (people app provider)
  • Loading a YouTube video from another app;
  • Linking to someone's Instagram profile;
  • Creating a Tweet from your photo app; (twitter providing a "compose tweet" UI);

Whether this UI appears in a popup window, or appears embedded in a Provider Hosting control. There would have to be behavioural hooks, so the main app hands over to another app, and is unable to log keystrokes or otherwise intercept the other app's control. But there be a way to handshake so hosted app content can return control to the main app, and send some kind of status message perhaps?

This is more in line with what I was thinking, it makes sense to require the hosted app supported being hosted and provide a specific page for that.

@marcelwgn
Copy link

Nested hosting would be less useful so it's certainly not a requirement.

But if you try to host a page that already hosts content? E.g. I want to host a discord chat which uses a hosted youtube player?

@bkaankose
Copy link

I don't think it's a useful feature by any means. It looks like a specific need for your app, but I can hardly imagine some other UWP app needing to be hosted in another one. This will bring confusion as well.

For example, what if I don't want my UWP app to be hosted in another app? Or let's say I want to, how can I restrict some apps or how am I supposed to allow some apps? I am not even talking about technical difficulties for sandboxed environment being hosted in another sandboxed environment here. These are just permission management stuff.

Personally I don't find this feature useful or providing value to the framework itself.

@matthew4850
Copy link
Author

Nested hosting would be less useful so it's certainly not a requirement.

But if you try to host a page that already hosts content? E.g. I want to host a discord chat which uses a hosted youtube player?

Sure it has some uses, and maybe this should be allowed, but the main focus would be non-nested hosting.

@matthew4850
Copy link
Author

I don't think it's a useful feature by any means. It looks like a specific need for your app, but I can hardly imagine some other UWP app needing to be hosted in another one. This will bring confusion as well.

For example, what if I don't want my UWP app to be hosted in another app? Or let's say I want to, how can I restrict some apps or how am I supposed to allow some apps? I am not even talking about technical difficulties for sandboxed environment being hosted in another sandboxed environment here. These are just permission management stuff.

Personally I don't find this feature useful or providing value to the framework itself.

Its a feature used by both My People and Xbox game bar so clearly it has some uses.
The idea is that this would be opt-in so it would not affect you if you did not wish to use it.

@bkaankose
Copy link

The idea is that this would be opt-in so it would not affect you if you did not wish to use it.

I don't think it will work like that. I own AppA. You own AppB. I allow developers to host my app. Your AppB hosts my AppA. Then I update my app to host another UWP app called AppC. Or, I update it to host even your AppB. Suddenly your AppB hosts AppC inside my AppA, or there is a host-ception issue :) You can't rely on some other developer's app or published store app to just behave as it was in development stage of yours.

Just because some internal apps are using it doesn't mean that whole framework development effort should be re-directed to it. There might be useful cases, but those cases are very unique and minor. The reason why they are intended to be used only internally is that they are unique to Microsoft. Not to an external developer. If your argument is 'Microsoft internally has it, just enable us to do it as well', then allowing this to public will require a lot of tooling development for VS, some changes to developer portal in web and hard thinking on corner cases. Like, the app you're hosting might not be available for user region.

You handled this problem with your solution with the help of MyTube developer as it needed to be handled. That is the correct way to fix this problem. Enabling all devs to host any UWP app they want from Store is not a fix at all.

@marb2000
Copy link

marb2000 commented Jun 3, 2020

Interesting. This scenario is more like an App model scenario rather than WinUI scenario.

Just thinking about the security implications here, it could take a tremendous amount of time to design it, if the security team doesn't block it, of course, but I think there are a lot of chances this happen.

Adding @AdamBraden , who works in the app model, for awareness.

@matthew4850
Copy link
Author

The idea is that this would be opt-in so it would not affect you if you did not wish to use it.

I don't think it will work like that. I own AppA. You own AppB. I allow developers to host my app. Your AppB hosts my AppA. Then I update my app to host another UWP app called AppC. Or, I update it to host even your AppB. Suddenly your AppB hosts AppC inside my AppA, or there is a host-ception issue :) You can't rely on some other developer's app or published store app to just behave as it was in development stage of yours.

This can be solved by just not allowing nested hosting, or maybe by requiring nested hosting be enabled for all apps in the hosting chain.

@shaheedmalik
Copy link

Better off just using hooks.

@ranjeshj ranjeshj transferred this issue from microsoft/microsoft-ui-xaml Jun 8, 2020
@ghost ghost added the needs-triage label Jun 8, 2020
@JaiganeshKumaran
Copy link
Contributor

You can already host another app using Launcher.LaunchForResults.

@jonwis
Copy link
Member

jonwis commented Jun 9, 2020

This is super interesting, thank you!

At least in theory there's support for this through a combination of App Extensions and App Services that would let you put an iframe-like thing in your app from another app.

  • The hosting app declares a app extension where the "public" folder is expected to contain some HTML+JScript. It finds extension implementations and loads their HTML into a WebView.
  • The hosted app that included the HTML then can use App Services to call over from the hosting app to the hosted app's background task.

There are security concerns for the hosting app, as they're effectively running code (JavaScript) from another app under their own identity. There's ways to control access from the JavaScript runtime to the host, and the WebView can use the "out of process" model to further isolate it. But it is possible. And It's nowhere near the model proposed on the thread so far, but it's something that works today. We understand the challenges associated with (a) writing part of your app in HTML and another in XAML (b) using AppServices efficiently as part of an interactive application.

If we do something more here, we'd follow the same model that app extensions use - the hosted app would say "this is the part of me that I'm OK to have hosted elsewhere" and use capabilities to verify that the hosting app is who they want to be. We'd also want app A's code to run inside app A's process and app B's code to run in app B's, while getting an input/output pipe between them.

A core issue for all apps is lifecycle - if A hosts B hosts C then the system needs to keep all of them alive. These would also necessarily be optional and somewhat ephemeral - the user can choose to uninstall B or A at any time, and the hosting app needs to be OK with a "this child thing disappeared" message.

So yes - I've got a lot of ideas here, but we're looking to the community to know whether this is something we should spend additional resources on, either at the platform layer or in Project Reunion. For now, please pile onto this thread:

  • Suggested API shapes
  • Scenarios you'd like to enable (either with multiple of your own apps, or apps to whom you're related)
  • Non-scenarios
  • Security, lifecycle, and identity concerns

@soumyamahunt
Copy link

This idea has great potential, may be in future the whole windows shell could be a UWP app and other developers can just make different shells as UWP app just like how Android handles Launchers.

@JaiganeshKumaran
Copy link
Contributor

JaiganeshKumaran commented Apr 10, 2021

Seems like the Calender is able to show content from the People app when you click on a specific event member even though the People app is now in a separate app package.

திரைப்பிடிப்பு (370)

@mdtauk
Copy link

mdtauk commented Apr 10, 2021

Seems like the Calender is able to show content from the People app when you click on a specific event member even though the People app is now in a separate app package.

திரைப்பிடிப்பு (370)

Mail, Calendar is a combined app. And I think the People app provides a "picker" interface. So you can use one app to load content from another UWP app - if that app provides the support.

@JaiganeshKumaran
Copy link
Contributor

@mdtauk I know Mail and Calender are in the same package but how UI from People from Calender? I only know about launching for results which would show a modal window but this seems something only Microsoft can do

@mdtauk
Copy link

mdtauk commented Apr 10, 2021

@mdtauk I know Mail and Calender are in the same package but how UI from People from Calender? I only know about launching for results which would show a modal window but this seems something only Microsoft can do

I imagine its through this API
Windows.Storage.Pickers.Provider

https://docs.microsoft.com/en-us/uwp/api/windows.storage.pickers.provider?view=winrt-19041

@JaiganeshKumaran
Copy link
Contributor

No those APIs for adding yourself to the File/Folder Picker. I think this is some undocumented stuff that only Microsoft knows

@visionarylab
Copy link

visionarylab commented Feb 18, 2022

Subset of the feature already in Game Bar Widget Overview,
The Xbox Game Bar Widget can display XAML view for "GameBar" project through UI Extension host.

Anyone know that UI Extension host available in SDK to let us mirrow two UWP Apps?

Xbox Game Bar Design

@zadjii-msft
Copy link
Member

I did something horrifying in microsoft/terminal@main...dev/migrie/fhl/dyndep that let an "extension host" app package load WinRT runtimeclasses from another package. This just used the public SDK, and dynamic dependencies. It's all in-proc though, so reliability is suspect at best.

image

I didn't get it loading a xbf from the extension package (but XAML generated in code-behind worked fine), nor did I try C#.

I'm pretty sure @jonwis has explicitly warned me not to try this in the past (again, reliability issues), but I had to see if it was possible 😄

@jonwis
Copy link
Member

jonwis commented May 14, 2023

I'm pretty sure @jonwis has explicitly warned me not to try this in the past (again, reliability issues), but I had to see if it was possible 😄

Ow, my eyes.

The main problem here is that UWP code is not usually designed to be loaded into other apps' appcontainers. That is, when you use dynamic dependency to bring in otherapp.main.dll code in that binary is now running inside the yourapp_8wkey... package family appcontainer and not the otherpublisher.otherapp_2k3fm... container. If the code in the DLL is a "pure function" (meaning it doesn't read-write any state and only uses its parameters) then sure, that probably works. If it produces any state, that state goes into your yourapp_8wkey... container.

Which means it's also something of a security risk - if your app manages credentials, and you load a DLL from another app, that other app now has access to your app's credentials. Normally this would be blocked by UWPs and appcontainers, as they can't reach-across container boundaries directly. This somewhat breaks the user's mental notion of "store apps" and UWPs - apps are isolated from each other and the system, and they have to directly approve when two apps want to work together.

So if you are doing this in terminal, @zadjii-msft , please make sure there's a user-consent prompt.

I won't say "dyndep allows app 1 to load code from app 2 is a bug" as it's something app1 decided to do. But it's a sharp tool to be used carefully.

In another world entirely we'd fully support cross-app-package composition islands, so you host the visuals of another app without loading its code into your process. As other have noted above, this is how the Xbox GameBar as well as various Picker types work. We just never enabled it for UWPs.

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

No branches or pull requests