@@ -21,7 +21,7 @@ function getExtensionMirrordPath(): Uri {
21
21
22
22
/**
23
23
* Tries to find local mirrord in path or in extension storage.
24
- * @param version If specified, then the version of the binary is checked and matched path is returned if it matches .
24
+ * @param version If specified, then the version of the binary is checked and matched path is returned.
25
25
* @returns Path to mirrord binary or null if not found
26
26
*/
27
27
export async function getLocalMirrordBinary ( version ?: string ) : Promise < string | null > {
@@ -47,7 +47,7 @@ export async function getLocalMirrordBinary(version?: string): Promise<string |
47
47
const api = new MirrordAPI ( mirrordPath ) ;
48
48
const installedVersion = await api . getBinaryVersion ( ) ;
49
49
50
- // we use semver.get here because installedVersion can be greater than the latest version
50
+ // we use semver.gte here because installedVersion can be greater than the latest version
51
51
// if we are running on the release CI.
52
52
if ( installedVersion && semver . gte ( installedVersion , version ) ) {
53
53
return mirrordPath ;
@@ -145,6 +145,7 @@ export async function getMirrordBinary(): Promise<string> {
145
145
if ( localMirrordBinary ) {
146
146
return localMirrordBinary ;
147
147
}
148
+ // donot block and download binary, instead download in background
148
149
await downloadMirrordBinary ( getExtensionMirrordPath ( ) , autoUpdateConfigured ) ;
149
150
return extensionPath ;
150
151
} else {
@@ -218,25 +219,35 @@ function getMirrordDownloadUrl(version: string): string {
218
219
* @param destPath Path to download the binary to
219
220
*/
220
221
async function downloadMirrordBinary ( destPath : Uri , version : string ) : Promise < void > {
221
- fs . mkdirSync ( Utils . dirname ( destPath ) . fsPath , { recursive : true } ) ;
222
- const response : AxiosResponse = await window . withProgress ( {
223
- location : ProgressLocation . Notification ,
222
+ await window . withProgress ( {
223
+ location : ProgressLocation . Window ,
224
224
title : "mirrord" ,
225
225
cancellable : false
226
- } , ( progress , _ ) => {
227
- progress . report ( { increment : 0 , "message" : "Downloading mirrord binary..." } ) ;
228
- const p = axios . get (
229
- getMirrordDownloadUrl ( version ) ,
230
- {
231
- onDownloadProgress : function ( progressEvent ) {
232
- progress . report ( { increment : progressEvent . progress , "message" : "Downloading mirrord binary..." } ) ;
233
- } ,
234
- responseType : 'arraybuffer' ,
235
- } ) ;
236
-
237
- return p ;
238
- }
239
- ) ;
240
- fs . writeFileSync ( destPath . fsPath , response . data ) ;
241
- fs . chmodSync ( destPath . fsPath , 0o755 ) ;
226
+ } , async ( progress ) => {
227
+ return new Promise < void > ( async ( resolve , reject ) => {
228
+ fs . mkdirSync ( Utils . dirname ( destPath ) . fsPath , { recursive : true } ) ;
229
+ try {
230
+ const response : AxiosResponse = await axios . get (
231
+ getMirrordDownloadUrl ( version ) ,
232
+ {
233
+ onDownloadProgress : function ( progressEvent ) {
234
+ progress . report ( { increment : progressEvent . progress , "message" : "Downloading mirrord binary..." } ) ;
235
+ } ,
236
+ responseType : 'arraybuffer' ,
237
+ } ) ;
238
+
239
+ fs . writeFileSync ( destPath . fsPath , response . data ) ;
240
+ fs . chmodSync ( destPath . fsPath , 0o755 ) ;
241
+ new NotificationBuilder ( )
242
+ . withMessage ( `Downloaded mirrord binary version ${ version } ` )
243
+ . info ( ) ;
244
+ resolve ( ) ;
245
+ } catch ( error ) {
246
+ new NotificationBuilder ( )
247
+ . withMessage ( `Error downloading mirrord binary: ${ error } ` )
248
+ . error ( ) ;
249
+ reject ( error ) ;
250
+ }
251
+ } ) ;
252
+ } ) ;
242
253
}
0 commit comments