@@ -19,8 +19,16 @@ public class AppUpgrader : IAsyncPlugin
1919 private DateTime _lastRefreshTime = DateTime . MinValue ;
2020 private const int CACHE_EXPIRATION_MINUTES = 15 ;
2121 private const int COMMAND_TIMEOUT_SECONDS = 10 ;
22- private static readonly Regex AppLineRegex = new Regex ( @"^(.+?)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$" ,
23- RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
22+ private static readonly Regex AppLineRegex = new Regex (
23+ @"^(.+?)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$" ,
24+ RegexOptions . Compiled | RegexOptions . IgnoreCase ,
25+ TimeSpan . FromMilliseconds ( 500 )
26+ ) ;
27+ private static readonly Regex DashLineRegex = new Regex (
28+ @"^-+$" ,
29+ RegexOptions . Compiled ,
30+ TimeSpan . FromMilliseconds ( 500 )
31+ ) ;
2432 public Task InitAsync ( PluginInitContext context )
2533 {
2634 Context = context ;
@@ -86,7 +94,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
8694 private bool ShouldRefreshCache ( )
8795 {
8896 return upgradableApps == null ||
89- DateTime . Now - _lastRefreshTime > TimeSpan . FromMinutes ( CACHE_EXPIRATION_MINUTES ) ;
97+ DateTime . UtcNow - _lastRefreshTime > TimeSpan . FromMinutes ( CACHE_EXPIRATION_MINUTES ) ;
9098 }
9199
92100 private async Task RefreshUpgradableAppsAsync ( )
@@ -128,12 +136,12 @@ private async Task<List<UpgradableApp>> GetUpgradableAppsAsync()
128136 return ParseWingetOutput ( output ) ;
129137 }
130138
131- private List < UpgradableApp > ParseWingetOutput ( string output )
139+ private static List < UpgradableApp > ParseWingetOutput ( string output )
132140 {
133141 var upgradableApps = new List < UpgradableApp > ( ) ;
134142 var lines = output . Split ( new [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) ;
135143
136- var startIndex = Array . FindIndex ( lines , line => Regex . IsMatch ( line , @"^-+$" ) ) ;
144+ var startIndex = Array . FindIndex ( lines , line => DashLineRegex . IsMatch ( line ) ) ;
137145 if ( startIndex == - 1 ) return upgradableApps ;
138146
139147 for ( int i = startIndex + 1 ; i < lines . Length - 1 ; i ++ )
@@ -153,7 +161,7 @@ private List<UpgradableApp> ParseWingetOutput(string output)
153161 Source = match . Groups [ 5 ] . Value
154162 } ;
155163
156- if ( app . Id . Contains ( "." ) || app . Id . Contains ( "-" ) )
164+ if ( app . Id . Contains ( '.' ) || app . Id . Contains ( '-' ) )
157165 {
158166 upgradableApps . Add ( app ) ;
159167 }
@@ -162,7 +170,7 @@ private List<UpgradableApp> ParseWingetOutput(string output)
162170 return upgradableApps ;
163171 }
164172
165- private async Task < string > ExecuteWingetCommandAsync ( string command , CancellationToken cancellationToken = default )
173+ private static async Task < string > ExecuteWingetCommandAsync ( string command , CancellationToken cancellationToken = default )
166174 {
167175 var processInfo = new ProcessStartInfo ( "cmd.exe" , "/c " + command )
168176 {
@@ -176,8 +184,8 @@ private async Task<string> ExecuteWingetCommandAsync(string command, Cancellatio
176184 if ( process == null )
177185 throw new InvalidOperationException ( "Failed to start process." ) ;
178186
179- var output = await process . StandardOutput . ReadToEndAsync ( ) ;
180- var error = await process . StandardError . ReadToEndAsync ( ) ;
187+ var output = await process . StandardOutput . ReadToEndAsync ( cancellationToken ) ;
188+ var error = await process . StandardError . ReadToEndAsync ( cancellationToken ) ;
181189
182190 await process . WaitForExitAsync ( cancellationToken ) ;
183191 if ( ! string . IsNullOrEmpty ( error ) )
0 commit comments