@@ -23,11 +23,11 @@ const NoUpdates = nls.localize(
23
23
'arduino/checkForUpdates/noUpdates' ,
24
24
'There are no recent updates available.'
25
25
) ;
26
- const UpdatesBoards = nls . localize (
26
+ const UpdateBoards = nls . localize (
27
27
'arduino/checkForUpdates/updatedBoth' ,
28
28
'Updates are available for some of your boards.'
29
29
) ;
30
- const UpdatesLibraries = nls . localize (
30
+ const UpdateLibraries = nls . localize (
31
31
'arduino/checkForUpdates/updatedBoth' ,
32
32
'Updates are available for some of your libraries.'
33
33
) ;
@@ -37,10 +37,12 @@ const InstallAll = nls.localize(
37
37
) ;
38
38
39
39
interface Task < T extends ArduinoComponent > {
40
- run : ( ) => Promise < void > ;
41
- item : T ;
40
+ readonly run : ( ) => Promise < void > ;
41
+ readonly item : T ;
42
42
}
43
43
44
+ const Updatable = { type : 'Updatable' } as const ;
45
+
44
46
@injectable ( )
45
47
export class CheckForUpdates extends Contribution {
46
48
@inject ( WindowServiceExt )
@@ -74,9 +76,9 @@ export class CheckForUpdates extends Contribution {
74
76
}
75
77
76
78
private async checkForUpdates ( silent = true ) {
77
- const [ libraryPackages , boardsPackages ] = await Promise . all ( [
78
- this . libraryService . updateables ( ) ,
79
- this . boardsService . updateables ( ) ,
79
+ const [ boardsPackages , libraryPackages ] = await Promise . all ( [
80
+ this . boardsService . search ( Updatable ) ,
81
+ this . libraryService . search ( Updatable ) ,
80
82
] ) ;
81
83
this . promptUpdateBoards ( boardsPackages ) ;
82
84
this . promptUpdateLibraries ( libraryPackages ) ;
@@ -90,8 +92,8 @@ export class CheckForUpdates extends Contribution {
90
92
items,
91
93
installable : this . libraryService ,
92
94
viewContribution : this . librariesContribution ,
93
- message : UpdatesLibraries ,
94
- viewSearchOptions : { query : '' , type : 'Updatable' , topic : 'All' } ,
95
+ viewSearchOptions : { query : '' , topic : 'All' , ... Updatable } ,
96
+ message : UpdateLibraries ,
95
97
} ) ;
96
98
}
97
99
@@ -100,8 +102,8 @@ export class CheckForUpdates extends Contribution {
100
102
items,
101
103
installable : this . boardsService ,
102
104
viewContribution : this . boardsContribution ,
103
- message : UpdatesBoards ,
104
- viewSearchOptions : { query : '' , type : 'Updatable' } ,
105
+ viewSearchOptions : { query : '' , ... Updatable } ,
106
+ message : UpdateBoards ,
105
107
} ) ;
106
108
}
107
109
@@ -120,17 +122,20 @@ export class CheckForUpdates extends Contribution {
120
122
if ( ! items . length ) {
121
123
return ;
122
124
}
123
- const actions = [ Later , InstallManually , InstallAll ] ;
124
- this . messageService . info ( message , ...actions ) . then ( ( answer ) => {
125
- if ( answer === InstallAll ) {
126
- const tasks = items . map ( ( item ) => this . installTask ( item , installable ) ) ;
127
- return this . executeTasks ( tasks ) ;
128
- } else if ( answer === InstallManually ) {
129
- viewContribution
130
- . openView ( { reveal : true } )
131
- . then ( ( widget ) => widget . refresh ( viewSearchOptions ) ) ;
132
- }
133
- } ) ;
125
+ this . messageService
126
+ . info ( message , Later , InstallManually , InstallAll )
127
+ . then ( ( answer ) => {
128
+ if ( answer === InstallAll ) {
129
+ const tasks = items . map ( ( item ) =>
130
+ this . createInstallTask ( item , installable )
131
+ ) ;
132
+ this . executeTasks ( tasks ) ;
133
+ } else if ( answer === InstallManually ) {
134
+ viewContribution
135
+ . openView ( { reveal : true } )
136
+ . then ( ( widget ) => widget . refresh ( viewSearchOptions ) ) ;
137
+ }
138
+ } ) ;
134
139
}
135
140
136
141
private async executeTasks ( tasks : Task < ArduinoComponent > [ ] ) : Promise < void > {
@@ -139,21 +144,33 @@ export class CheckForUpdates extends Contribution {
139
144
nls . localize ( 'arduino/checkForUpdates/updating' , 'Updating' ) ,
140
145
this . messageService ,
141
146
async ( progress ) => {
142
- const total = tasks . length ;
143
- let count = 0 ;
144
- for ( const { run, item } of tasks ) {
145
- progress . report ( {
146
- message : item . name ,
147
- } ) ;
148
- await run ( ) ;
149
- progress . report ( { work : { total, done : ++ count } } ) ;
147
+ try {
148
+ const total = tasks . length ;
149
+ let count = 0 ;
150
+ for ( const { run, item } of tasks ) {
151
+ // progress.report({
152
+ // message: item.name,
153
+ // });
154
+ try {
155
+ await run ( ) ; // runs update sequentially. // TODO: is parallel update desired?
156
+ } catch ( err ) {
157
+ console . error ( err ) ;
158
+ this . messageService . error (
159
+ `Failed to update ${ item . name } . ${ err } `
160
+ ) ;
161
+ } finally {
162
+ progress . report ( { work : { total, done : ++ count } } ) ;
163
+ }
164
+ }
165
+ } finally {
166
+ progress . cancel ( ) ;
150
167
}
151
168
}
152
169
) ;
153
170
}
154
171
}
155
172
156
- private installTask < T extends ArduinoComponent > (
173
+ private createInstallTask < T extends ArduinoComponent > (
157
174
item : T ,
158
175
installable : Installable < T >
159
176
) : Task < T > {
0 commit comments