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

C# GUI app integration example #274

Closed
pingzing opened this issue Oct 7, 2018 · 14 comments
Closed

C# GUI app integration example #274

pingzing opened this issue Oct 7, 2018 · 14 comments
Labels
Area-Interop Communication between processes Issue-Question For questions or discussion Issue-Samples A request for an example on how we do something. Probably a good docs candidate. Product-Conpty For console issues specifically related to conpty Resolution-Answered Related to questions that have been answered

Comments

@pingzing
Copy link
Contributor

pingzing commented Oct 7, 2018

Hi! Building on @waf's good work with his C# ConPTY sample I put together an (extremely) basic sample of what a custom console might look like as implemented in WPF and UWP. Strong caveat, it currently doesn't parse, or properly render the VT codes, but it shows the skeleton of what such an app might look like.

https://github.com/pingzing/ModernPseudoSh

This was mostly a proof-of-concept that I thought would be fun to throw together, to see what was possible. However, it occurs to me that it reveals some useful things about what's required to get a GUI application talking to and displaying a ConPTY. Would this be a useful thing to have as a sample in the repo?

@ysc3839
Copy link
Contributor

ysc3839 commented Oct 8, 2018

Is it possible to use ConPTY API in UWP Apps?

@pingzing
Copy link
Contributor Author

pingzing commented Oct 8, 2018

It seems like the answer is "broadly, yes". I did notice that pwsh.exe threw an error setting up its filesystem access, but I suspect that's because I was missing the broadFileSystemAccess capability. I'm already using the runFullTrust capability, which allows the UWP app to start arbitrary external processes.

Do note that both of those capabilities will torpedo your chances of distributing through the Store, though.

@zadjii-msft
Copy link
Member

Is it possible to use ConPTY API in UWP Apps?

Boy what a question this is.

I believe it's certainly possible to build an app like @pingzing has here that'll run as a UWP. However, that comes with some strong caveats:

  1. CreatePseudoConsole and the other conpty APIs are part of the "desktop" api partition, not the "App" API partition. This means that although they exist in the SDK, your app won't pass certification in the store if you try and call them. This is mainly due to the fact that all of the PROC_THREAD_ATTRIBUTE API's are also only in the Desktop partition. It wouldn't make sense to be able to create a pseudoconsole from a UWP, and not be able to attach anything to it.

  2. Any UWP can technically call CreateProcess on any arbitrary commandline - you don't need RunFullTrust for that. However, when you do launch that external process, it will also be running in the same Low-IL app container as the UWP app itself. That's why it seems as though powershell is unable to access the filesystem, because it doesn't have the permission to do so from within the app container.

  3. RunFullTrust only works for "Desktop Bridge"/Centennial/<Whatever we're calling it now> apps. These are Win32 apps that are running as an app package basically. Unfortunately, the RunFullTrust capability does not magically make your UWP application a Medium-IL, non app containered thing. It actually doesn't do anything to a UWP app :/.

  4. RunFullTrust won't torpedo your chances of being in the store - there are plenty of Win32 apps in the store nowadays with the RunFullTrust capability.

@zadjii-msft zadjii-msft added Issue-Question For questions or discussion Product-Conpty For console issues specifically related to conpty labels Oct 8, 2018
@pingzing
Copy link
Contributor Author

pingzing commented Oct 8, 2018

RunFullTrust only works for "Desktop Bridge"/Centennial/<Whatever we're calling it now> apps.

I suspected that might be the case, and that actually informed my initial approach. My first stab at this had a regular Windows Desktop console app as a "host", and then wrapped it to inside a Centennial package. I couldn't find a way to transmit data between it and the UWP app except by using AppService, though, and that has a number of complicated drawbacks, especially for a bitty li'l PoC. Though it occurs to me that this Bridged app might also have the same App Container sandbox issues. Hmm.

At any rate, the WPF app presents many fewer issues =P

@miniksa
Copy link
Member

miniksa commented Oct 8, 2018

It looks like @zadjii-msft is being a bit coy. This is actually what he's been spending a lot of time investigating as of late. We let the ConPTY API out in the world and now we're trying to sand the rough edges off and one of the biggest ones is around using it with UWP. He's exploring many solutions to it. Ask him how many meetings he has had related to it. :P I can't say much more without upsetting the planning and management gods, but trust that he is on top of it and we'll let you know more when we figure it out.

@pingzing on your other question, I personally think more samples is more better. I hate not having a variety of samples when trying to code something. If you clean them up and want to contribute them along side our original example and @waf's C# one, I'd be happy to review your pull request. Maybe just start with the WPF one and let the UWP hang for a bit?

@pingzing
Copy link
Contributor Author

pingzing commented Oct 8, 2018

@miniksa oho, very interesting indeed! Best of luck to you, @zadjii-msft. (If you do find a way to pull it off, open source iiiiiit)

But yeah, WPF alone seems like a reasonable enough thing to do. I'll clean it up a bit and come back with a PR.

@zadjii-msft
Copy link
Member

Why, I was being coy :P It's been a LOT of meetings across Windows, and I think I'm getting awfully close to the line of what I can and can't say.

My first stab at this had a regular Windows Desktop console app as a "host", and then wrapped it to inside a Centennial package. I couldn't find a way to transmit data between it and the UWP app except by using AppService, though

That was one of many attempts we had at enabling this. Unfortunately the AppServiceConnection doesn't provide any ordering guarantees, so you'd have to implement that yourself... there are basically a TON of drawbacks to doing it that way.

Suffice to say, working with a Pseudoconsole in a UWP application is not a workflow the platform currently (Windows 1809) supports.

@Biswa96
Copy link

Biswa96 commented Oct 10, 2018

I've zero idea about UWP world! But I have some useful info. Quote from @zadjii-msft's first point:

This is mainly due to the fact that all of the PROC_THREAD_ATTRIBUTE API's are also only in the Desktop partition.

Those PROC_THREAD_ATTRIBUTE APIs aka. UpdateProcThreadAttribute() and InitializeProcThreadAttributeList() function manipulates some value in struct _PROC_THREAD_ATTRIBUTE_LIST which is appended with struct _STARTUPINFOEXW.
So if OP translates those functions to C# then it may be possible to convert ConPty to UWP (without Desktop Bridge/Centennial).

@zadjii-msft
Copy link
Member

From experience: don't do that. While yes, technically possible, it's mostly just a red herring. The much bigger issue with UWP is getting the child process out of the app container.

In fact, you don't even need to translate them to C#: you can build a UWP in straight-up C++. However, if you do call those functions, again, you're going to end up failing certification.

@ysc3839
Copy link
Contributor

ysc3839 commented Oct 18, 2018

Found this feature, which allows you use UWP XAML UI in Win32 apps.

Windows 10 now enables you to use UWP controls in non-UWP desktop applications so that you can enhance the look, feel, and functionality of your existing desktop applications with the latest Windows 10 UI features that are only available via UWP controls.
https://docs.microsoft.com/en-us/windows/uwp/xaml-platform/xaml-host-controls

@zadjii-msft
Copy link
Member

Ah yes, XAML Islands. That is another route you could take for embedding some UWP XAML elements within a Win32. It's got some caveats, but if you've got an existing WPF app, it's a really good way to incrementally include some UWP controls.

@doubleyewdee
Copy link

Stumbled on this while trying to figure out a since-resolved issue. I'm not sure it makes sense to include my project as a direct sample but it night be worth a link in the examples area? https://github.com/doubleyewdee/condo is what I've been up to.

With noting I also briefly looked at UWP and ended up peeling off due to the mentioned issues.

@miniksa miniksa added the Issue-Samples A request for an example on how we do something. Probably a good docs candidate. label Jan 18, 2019
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@miniksa
Copy link
Member

miniksa commented May 18, 2019

@pingzing, is this still relevant?

@miniksa miniksa added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Area-Interop Communication between processes labels May 18, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 18, 2019
@pingzing
Copy link
Contributor Author

Nope! Though it is fun looking back at this discussion now =) Will close this.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 18, 2019
@miniksa miniksa removed the Needs-Attention The core contributors need to come back around and look at this ASAP. label May 18, 2019
@miniksa miniksa added the Resolution-Answered Related to questions that have been answered label May 18, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interop Communication between processes Issue-Question For questions or discussion Issue-Samples A request for an example on how we do something. Probably a good docs candidate. Product-Conpty For console issues specifically related to conpty Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

6 participants