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

Implement ConnectionState and closeOnExit=graceful/always/never #3623

Merged
merged 18 commits into from
Nov 25, 2019

Conversation

DHowett-MSFT
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT commented Nov 19, 2019

Summary of the Pull Request

This pull request implements the new ITerminalConnection::ConnectionState interface (enum, event) and connects it through TerminalControl to Pane, Tab and App as specified in #2039. It does so to implement closeOnExit = graceful in addition to the other two normal CoE types.

It also:

  • ... exposes the singleton CascadiaSettings through a function that looks it up by using the current Xaml application's AppLogic.
    • In so doing, we've broken up the weird runaround where App tells TerminalSettings to CloseOnExit and then later another part of App asks TerminalControl to tell it what TerminalSettings said App told it earlier. :crazy_eyes:
  • ... wires up a bunch of connection state points to AzureConnection. This required moving the Azure connection's state machine to use another enum name (oops).
  • ... ships a helper class for managing connection state transitions.
  • ... contains a bunch of template magic.
  • ... contains a TODO (whoops, sorry, if you point it out you'll be removed from the selfhost program)
  • ... introduces WINRT_CALLBACK, a oneshot callback like TYPED_EVENT.
  • ... replaces a bunch of disparate _connecting and _closing members with just one uberstate.

References

Specification is in PR #2039.

PR Checklist

commit c36b2482c04070529cbb009b09ec60cea70da8bd
Merge: 4d6e975 c274b38
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Fri Nov 8 14:16:44 2019 -0800

    Merge remote-tracking branch 'github/master' into dev/duhowett/closeonexit

commit 4d6e975
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Wed Nov 6 15:49:38 2019 -0800

    further hax

commit 1950413
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Wed Nov 6 07:30:32 2019 -0800

    hacks: try to implement the state thing

commit 22dd029
Merge: 5763be3 357e835
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Wed Nov 6 15:15:21 2019 -0800

    Merge remote-tracking branch 'github/master' into HEAD

commit 5763be3
Author: Dustin Howett <duhowett@microsoft.com>
Date:   Tue Nov 5 17:47:22 2019 -0800

    Spec: propose an evolution of closeOnExit and TerminalConnection
@DHowett-MSFT DHowett-MSFT changed the title Implement closeOnExit=graceful/always/never Implement ITerminalConnection::ConnectionState and closeOnExit=graceful/always/never Nov 19, 2019
@DHowett-MSFT DHowett-MSFT marked this pull request as ready for review November 19, 2019 01:56
doc/cascadia/profiles.schema.json Show resolved Hide resolved
src/cascadia/inc/cppwinrt_utils.h Show resolved Hide resolved
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 20, 2019
Copy link
Contributor Author

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@DHowett-MSFT
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm 27/32, and it's 5pm here, so unfortunately this is going to have to wait till monday from me :(

Nothing major so far though

src/cascadia/TerminalApp/CascadiaSettings.cpp Show resolved Hide resolved
src/cascadia/inc/cppwinrt_utils.h Show resolved Hide resolved
std::lock_guard<std::mutex> stateLock{ _stateMutex };
// dark magic: this is a C++17 fold expression that expands into
// state == 1 || state == 2 || state == 3 ...
return (... || (_connectionState == args));
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand what this dark magic does. is it equivalent to the following:

_connectionState == args[0] || _connectionState == args[1] || _connectionState == args[2] ...

(if you could index into the params like that?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

YES! Exactly.

And the one above it is like

typeof(args[0]) == ConnectionState && typeof(args[1] == ConnectionState) && ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to expand these since i have to make a comment revision anyway

@DHowett-MSFT
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I suppose none of my comments are more than nits.

{
_state = State::NoConnect;
Copy link
Member

Choose a reason for hiding this comment

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

Should we just remove the AzureState::NoConnect state entirely now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm working on the AZ conn in my free time, I'll defer this to then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

er defer this to that work

@@ -156,8 +156,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// DON'T CALL _InitializeTerminal here - wait until the swap chain is loaded to do that.

// Subscribe to the connection's disconnected event and call our connection closed handlers.
_connection.TerminalDisconnected([=]() {
_connectionClosedHandlers();
_connectionStateChangedRevoker = _connection.StateChanged(winrt::auto_revoke, [weakThis = get_weak()](auto&& /*s*/, auto&& /*v*/) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a pattern we should probably be using in other places, right? Where the event handler doesn't capture a strong ref to the handler object? (maybe we should file a CodeHealth task for this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, absolutely.

@DHowett-MSFT DHowett-MSFT changed the title Implement ITerminalConnection::ConnectionState and closeOnExit=graceful/always/never Implement ConnectionState and closeOnExit=graceful/always/never Nov 25, 2019
@DHowett-MSFT DHowett-MSFT merged commit 901a1e1 into master Nov 25, 2019
@DHowett-MSFT DHowett-MSFT deleted the dev/duhowett/closeonexit branch November 25, 2019 22:22
@ghost
Copy link

ghost commented Jan 14, 2020

🎉Windows Terminal Preview v0.8.10091.0 has been released which incorporates this pull request.:tada:

Handy links:

@mu88
Copy link

mu88 commented Jan 15, 2020

I curiously tried the new graceful behavior and one question came up to me. I've updated to v0.8.10091.0 and have the following profile:

{
    "name" : "Build Script",
    "closeOnExit": "graceful",
    "guid" : "{65869F08-7651-44A5-9EAB-982A1577BC65}",
    "commandline" : "cmd.exe /k Batch\\Build.bat",
    "startingDirectory" : "C:\\Projects\\Code",
    "fontFace" : "Fira Code",
    "fontSize" : 10,
    "icon" : "C:\\Projects\\Code\\DotNet\\icon.ico"
}

When opening a new tab with Build Script, the script Build.bat gets triggered and succeeds. When executing echo Exit Code is %errorlevel% in the opened tab, 0 is returned. Nonetheless, the tab remains open. I would have expected the tab to close. Is my assumption wrong or is there any issue?

@DHowett-MSFT
Copy link
Contributor Author

if I recall correctly, You want cmd /c. /k means “continue running after you evaluate the command.” You can pretend it means “[k]eep running”.

@mu88
Copy link

mu88 commented Jan 15, 2020

You are absolutely right, thank you!

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