Skip to content

Commit 18a7de5

Browse files
daxian-dbwkilasuit
authored andcommitted
Support notification on pwsh startup when a new release is available (PowerShell#10689)
1 parent 13fe488 commit 18a7de5

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,7 @@ internal static void ShowUpdateNotification(PSHostUserInterface hostUI)
6262
? ManagedEntranceStrings.StableUpdateNotificationMessage
6363
: ManagedEntranceStrings.PreviewUpdateNotificationMessage;
6464

65-
string notificationColor = string.Empty;
66-
string resetColor = string.Empty;
67-
68-
string line2Padding = string.Empty;
69-
string line3Padding = string.Empty;
70-
71-
// We calculate how much whitespace we need to make it look nice
72-
if (hostUI.SupportsVirtualTerminal)
73-
{
74-
// Use Warning Color
75-
notificationColor = "\x1B[7m";
76-
resetColor = "\x1B[0m";
77-
78-
// The first line is longest, if the message changes, this needs to be updated
79-
int line1Length = notificationMsgTemplate.IndexOf('\n');
80-
int line2Length = notificationMsgTemplate.IndexOf('\n', line1Length + 1);
81-
int line3Length = notificationMsgTemplate.IndexOf('\n', line2Length + 1);
82-
line3Length -= line2Length + 1;
83-
line2Length -= line1Length + 1;
84-
85-
line2Padding = line2Padding.PadRight(line1Length - line2Length + releaseTag.Length);
86-
// 3 represents the extra placeholder in the template
87-
line3Padding = line3Padding.PadRight(line1Length - line3Length + 3);
88-
}
89-
90-
string notificationMsg = string.Format(CultureInfo.CurrentCulture, notificationMsgTemplate, releaseTag, notificationColor, resetColor, line2Padding, line3Padding);
91-
65+
string notificationMsg = string.Format(CultureInfo.CurrentCulture, notificationMsgTemplate, releaseTag);
9266
hostUI.WriteLine(notificationMsg);
9367
}
9468
}
@@ -106,13 +80,6 @@ internal static async Task CheckForUpdates()
10680
return;
10781
}
10882

109-
// Daily builds do not support update notifications
110-
string preReleaseLabel = PSVersionInfo.PSCurrentVersion.PreReleaseLabel;
111-
if (preReleaseLabel != null && preReleaseLabel.StartsWith("daily", StringComparison.OrdinalIgnoreCase))
112-
{
113-
return;
114-
}
115-
11683
// If the host is not connect to a network, skip the rest of the check.
11784
if (!NetworkInterface.GetIsNetworkAvailable())
11885
{

src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ Type 'help' to get help.</value>
128128
<value>Warning: PowerShell detected that you might be using a screen reader and has disabled PSReadLine for compatibility purposes. If you want to re-enable it, run 'Import-Module PSReadLine'.</value>
129129
</data>
130130
<data name="PreviewUpdateNotificationMessage" xml:space="preserve">
131-
<value> {1} A new PowerShell preview release is available: v{0} {2}
132-
{1} Upgrade now, or check out the release page at:{3}{2}
133-
{1} https://aka.ms/PowerShell-Release?tag=v{0} {4}{2}
131+
<value>!! A new PowerShell preview release is available: v{0} !!
132+
Upgrade now, or check out the release page at:
133+
https://github.com/PowerShell/PowerShell/releases/tag/v{0}
134134
</value>
135135
</data>
136136
<data name="StableUpdateNotificationMessage" xml:space="preserve">
137-
<value> {1} A new PowerShell stable release is available: v{0} {2}
138-
{1} Upgrade now, or check out the release page at:{3}{2}
139-
{1} https://aka.ms/PowerShell-Release?tag=v{0} {4}{2}
137+
<value>!! A new PowerShell stable release is available: v{0} !!
138+
Upgrade now, or check out the release page at:
139+
https://github.com/PowerShell/PowerShell/releases/tag/v{0}
140140
</value>
141141
</data>
142142
<data name="UsageHelp" xml:space="preserve">

src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ static ExperimentalFeature()
117117
description: "Support the ternary operator in PowerShell language"),
118118
new ExperimentalFeature(
119119
name: "PSErrorView",
120-
description: "New formatting for ErrorRecord")
120+
description: "New formatting for ErrorRecord"),
121+
new ExperimentalFeature(
122+
name: "PSUpdatesNotification",
123+
description: "Print notification message when new releases are available")
121124
};
122125
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
123126

0 commit comments

Comments
 (0)