Skip to content

Commit

Permalink
Support notification on pwsh startup when a new release is available (
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw authored and kilasuit committed Oct 31, 2019
1 parent c3d3fdc commit 531868e
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,11 @@ private void ParseHelper(string[] args)
if (_showBanner && !_showHelp)
{
DisplayBanner();

if (UpdatesNotification.CanNotifyUpdates)
{
UpdatesNotification.ShowUpdateNotification(_hostUI);
}
}

Dbg.Assert(
Expand Down
39 changes: 21 additions & 18 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ internal sealed partial class ConsoleHost
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);

// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
// Removed HandleUnexpectedExceptions infrastructure
/// <summary>
/// Internal Entry point in msh console host implementation.
/// </summary>
Expand All @@ -78,8 +76,8 @@ internal sealed partial class ConsoleHost
/// <returns>
/// The exit code for the shell.
///
/// NTRAID#Windows OS Bugs-1036968-2005/01/20-sburns The behavior here is related to monitor work. The low word of the
/// exit code is available for the user. The high word is reserved for the shell and monitor.
/// The behavior here is related to monitor work.
/// The low word of the exit code is available for the user. The high word is reserved for the shell and monitor.
///
/// The shell process needs to return:
///
Expand All @@ -98,13 +96,10 @@ internal sealed partial class ConsoleHost
/// or 0xFFFE0000 (user hit ctrl-break), the monitor should restart the shell.exe. Otherwise, the monitor should exit
/// with the same exit code as the shell.exe.
///
/// Anyone checking the exit code of the shell or monitor can mask off the hiword to determine the exit code passed
/// Anyone checking the exit code of the shell or monitor can mask off the high word to determine the exit code passed
/// by the script that the shell last executed.
/// </returns>
internal static int Start(
string bannerText,
string helpText,
string[] args)
internal static int Start(string bannerText, string helpText, string[] args)
{
#if DEBUG
if (Environment.GetEnvironmentVariable("POWERSHELL_DEBUG_STARTUP") != null)
Expand Down Expand Up @@ -162,10 +157,8 @@ internal static int Start(
hostException = e;
}

s_cpp = new CommandLineParameterParser(
(s_theConsoleHost != null) ? s_theConsoleHost.UI : new NullHostUserInterface(),
bannerText, helpText);

PSHostUserInterface hostUi = s_theConsoleHost?.UI ?? new NullHostUserInterface();
s_cpp = new CommandLineParameterParser(hostUi, bannerText, helpText);
s_cpp.Parse(args);

#if UNIX
Expand Down Expand Up @@ -239,10 +232,20 @@ internal static int Start(
throw hostException;
}

ProfileOptimization.StartProfile(
s_theConsoleHost.LoadPSReadline()
? "StartupProfileData-Interactive"
: "StartupProfileData-NonInteractive");
if (s_theConsoleHost.LoadPSReadline())
{
ProfileOptimization.StartProfile("StartupProfileData-Interactive");

if (UpdatesNotification.CanNotifyUpdates)
{
// Start a task in the background to check for the update release.
_ = UpdatesNotification.CheckForUpdates();
}
}
else
{
ProfileOptimization.StartProfile("StartupProfileData-NonInteractive");
}

s_theConsoleHost.BindBreakHandler();
PSHost.IsStdOutputRedirected = Console.IsOutputRedirected;
Expand Down Expand Up @@ -1532,7 +1535,7 @@ private bool LoadPSReadline()
// Don't load PSReadline if:
// * we don't think the process will be interactive, e.g. -command or -file
// - exception: when -noexit is specified, we will be interactive after the command/file finishes
// * -noninteractive: this should be obvious, they've asked that we don't every prompt
// * -noninteractive: this should be obvious, they've asked that we don't ever prompt
//
// Note that PSReadline doesn't support redirected stdin/stdout, but we don't check that here because
// a future version might, and we should automatically load it at that unknown point in the future.
Expand Down
Loading

0 comments on commit 531868e

Please sign in to comment.