@@ -51,20 +51,20 @@ export class UpdatePowerShell {
51
51
private shouldCheckForUpdate ( ) : boolean {
52
52
// Respect user setting.
53
53
if ( ! this . sessionSettings . promptToUpdatePowerShell ) {
54
- this . logger . writeDiagnostic ( "Setting 'promptToUpdatePowerShell' was false." ) ;
54
+ this . logger . writeVerbose ( "Setting 'promptToUpdatePowerShell' was false." ) ;
55
55
return false ;
56
56
}
57
57
58
58
// Respect environment configuration.
59
59
if ( process . env . POWERSHELL_UPDATECHECK ?. toLowerCase ( ) === "off" ) {
60
- this . logger . writeDiagnostic ( "Environment variable 'POWERSHELL_UPDATECHECK' was 'Off'." ) ;
60
+ this . logger . writeVerbose ( "Environment variable 'POWERSHELL_UPDATECHECK' was 'Off'." ) ;
61
61
return false ;
62
62
}
63
63
64
64
// Skip prompting when using Windows PowerShell for now.
65
65
if ( this . localVersion . compare ( "6.0.0" ) === - 1 ) {
66
66
// TODO: Maybe we should announce PowerShell Core?
67
- this . logger . writeDiagnostic ( "Not offering to update Windows PowerShell." ) ;
67
+ this . logger . writeVerbose ( "Not prompting to update Windows PowerShell." ) ;
68
68
return false ;
69
69
}
70
70
@@ -78,27 +78,26 @@ export class UpdatePowerShell {
78
78
79
79
// Skip if PowerShell is self-built, that is, this contains a commit hash.
80
80
if ( commit . length >= 40 ) {
81
- this . logger . writeDiagnostic ( "Not offering to update development build." ) ;
81
+ this . logger . writeVerbose ( "Not prompting to update development build." ) ;
82
82
return false ;
83
83
}
84
84
85
85
// Skip if preview is a daily build.
86
86
if ( daily . toLowerCase ( ) . startsWith ( "daily" ) ) {
87
- this . logger . writeDiagnostic ( "Not offering to update daily build." ) ;
87
+ this . logger . writeVerbose ( "Not prompting to update daily build." ) ;
88
88
return false ;
89
89
}
90
90
}
91
91
92
92
// TODO: Check if network is available?
93
93
// TODO: Only check once a week.
94
- this . logger . writeDiagnostic ( "Should check for PowerShell update." ) ;
95
94
return true ;
96
95
}
97
96
98
- private async getRemoteVersion ( url : string ) : Promise < string > {
97
+ private async getRemoteVersion ( url : string ) : Promise < string | undefined > {
99
98
const response = await fetch ( url ) ;
100
99
if ( ! response . ok ) {
101
- throw new Error ( "Failed to get remote version!" ) ;
100
+ return undefined ;
102
101
}
103
102
// Looks like:
104
103
// {
@@ -107,7 +106,7 @@ export class UpdatePowerShell {
107
106
// "ReleaseTag": "v7.2.7"
108
107
// }
109
108
const data = await response . json ( ) ;
110
- this . logger . writeDiagnostic ( `From '${ url } ' received :\n${ data } `) ;
109
+ this . logger . writeVerbose ( `Received from '${ url } ':\n${ JSON . stringify ( data , undefined , 2 ) } `) ;
111
110
return data . ReleaseTag ;
112
111
}
113
112
@@ -116,38 +115,48 @@ export class UpdatePowerShell {
116
115
return undefined ;
117
116
}
118
117
118
+ this . logger . writeVerbose ( "Checking for PowerShell update..." ) ;
119
119
const tags : string [ ] = [ ] ;
120
120
if ( process . env . POWERSHELL_UPDATECHECK ?. toLowerCase ( ) === "lts" ) {
121
121
// Only check for update to LTS.
122
- this . logger . writeDiagnostic ( "Checking for LTS update." ) ;
123
- tags . push ( await this . getRemoteVersion ( UpdatePowerShell . LTSBuildInfoURL ) ) ;
122
+ this . logger . writeVerbose ( "Checking for LTS update..." ) ;
123
+ const tag = await this . getRemoteVersion ( UpdatePowerShell . LTSBuildInfoURL ) ;
124
+ if ( tag != undefined ) {
125
+ tags . push ( tag ) ;
126
+ }
124
127
} else {
125
128
// Check for update to stable.
126
- this . logger . writeDiagnostic ( "Checking for stable update." ) ;
127
- tags . push ( await this . getRemoteVersion ( UpdatePowerShell . StableBuildInfoURL ) ) ;
129
+ this . logger . writeVerbose ( "Checking for stable update..." ) ;
130
+ const tag = await this . getRemoteVersion ( UpdatePowerShell . StableBuildInfoURL ) ;
131
+ if ( tag != undefined ) {
132
+ tags . push ( tag ) ;
133
+ }
128
134
129
135
// Also check for a preview update.
130
136
if ( this . localVersion . prerelease . length > 0 ) {
131
- this . logger . writeDiagnostic ( "Checking for preview update." ) ;
132
- tags . push ( await this . getRemoteVersion ( UpdatePowerShell . PreviewBuildInfoURL ) ) ;
137
+ this . logger . writeVerbose ( "Checking for preview update..." ) ;
138
+ const tag = await this . getRemoteVersion ( UpdatePowerShell . PreviewBuildInfoURL ) ;
139
+ if ( tag != undefined ) {
140
+ tags . push ( tag ) ;
141
+ }
133
142
}
134
143
}
135
144
136
145
for ( const tag of tags ) {
137
146
if ( this . localVersion . compare ( tag ) === - 1 ) {
138
- this . logger . writeDiagnostic ( `Offering to update PowerShell to ${ tag } .` ) ;
139
147
return tag ;
140
148
}
141
149
}
142
150
151
+ this . logger . write ( "PowerShell is up-to-date." ) ;
143
152
return undefined ;
144
153
}
145
154
146
155
public async checkForUpdate ( ) : Promise < void > {
147
156
try {
148
157
const tag = await this . maybeGetNewRelease ( ) ;
149
158
if ( tag ) {
150
- return await this . installUpdate ( tag ) ;
159
+ return await this . promptToUpdate ( tag ) ;
151
160
}
152
161
} catch ( err ) {
153
162
// Best effort. This probably failed to fetch the data from .
@@ -160,21 +169,22 @@ export class UpdatePowerShell {
160
169
await vscode . env . openExternal ( url ) ;
161
170
}
162
171
163
- private async installUpdate ( tag : string ) : Promise < void > {
172
+ private async promptToUpdate ( tag : string ) : Promise < void > {
164
173
const releaseVersion = new SemVer ( tag ) ;
174
+ this . logger . write ( `Prompting to update PowerShell v${ this . localVersion . version } to v${ releaseVersion . version } .` ) ;
165
175
const result = await vscode . window . showInformationMessage (
166
- `You have an old version of PowerShell ( ${ this . localVersion . version } ) .
167
- The current latest release is ${ releaseVersion . version } .
168
- Would you like to open the release in your browser?` ,
176
+ `PowerShell v ${ this . localVersion . version } is out-of-date .
177
+ The latest version is v ${ releaseVersion . version } .
178
+ Would you like to open the release in your browser?`,
169
179
...UpdatePowerShell . promptOptions ) ;
170
180
171
181
// If the user cancels the notification.
172
182
if ( ! result ) {
173
- this . logger . writeDiagnostic ( "User canceled PowerShell update prompt." ) ;
183
+ this . logger . writeVerbose ( "User canceled PowerShell update prompt." ) ;
174
184
return ;
175
185
}
176
186
177
- this . logger . writeDiagnostic ( `User said '${ UpdatePowerShell . promptOptions [ result . id ] . title } '.` ) ;
187
+ this . logger . writeVerbose ( `User said '${ UpdatePowerShell . promptOptions [ result . id ] . title } '.` ) ;
178
188
179
189
switch ( result . id ) {
180
190
// Yes
0 commit comments