1- // Copyright (c) Microsoft Corporation
1+ // Copyright (c) Microsoft Corporation
22// The Microsoft Corporation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
1010using System . Linq ;
1111using System . Reflection ;
1212using System . Text . RegularExpressions ;
13+ using System . Threading ;
1314using System . Windows . Controls ;
1415using System . Windows . Input ;
1516using System . Windows . Shapes ;
@@ -56,6 +57,11 @@ public partial class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
5657
5758 // constructor
5859 public Main ( )
60+ {
61+ LoadInstalledList ( ) ;
62+ }
63+
64+ private static void LoadInstalledList ( )
5965 {
6066 Process process = new Process ( ) ;
6167
@@ -224,8 +230,7 @@ public List<Result> Query(Query query)
224230 ProgramArguments = idStr ,
225231 Action = action =>
226232 {
227- Helper . OpenInShell ( "winget" , "install " + idStr + " --wait" , "/" ) ;
228-
233+ Winget ( "install " + idStr + " --wait" ) ;
229234 return true ;
230235 } ,
231236 } ) ;
@@ -255,6 +260,28 @@ public void Init(PluginInitContext context)
255260 } ;
256261 }
257262
263+ public static void Winget ( string cmd )
264+ {
265+ // Call thread
266+ Thread thread = new Thread ( ( ) => WingetCmdThread ( cmd ) ) ;
267+ thread . Start ( ) ;
268+ }
269+
270+ public static void WingetCmdThread ( string cmd )
271+ {
272+ Process process = new Process ( ) ;
273+
274+ process . StartInfo . FileName = "winget" ;
275+ process . StartInfo . Arguments = cmd ;
276+ process . StartInfo . UseShellExecute = true ;
277+ process . StartInfo . WindowStyle = ProcessWindowStyle . Normal ;
278+ process . Start ( ) ;
279+
280+ // Wait for process to exit
281+ process . WaitForExit ( ) ;
282+ LoadInstalledList ( ) ;
283+ }
284+
258285 private static List < ContextMenuResult > GetContextMenu ( in Result result , in string assemblyName )
259286 {
260287 if ( result ? . Title == Properties . Resources . plugin_description )
@@ -273,7 +300,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
273300 AcceleratorModifiers = ModifierKeys . Control ,
274301 Action = _ =>
275302 {
276- Helper . OpenInShell ( "winget" , " install " + idStr + " -i --force --wait" , "/ ") ;
303+ Winget ( " install " + idStr + " -i --force --wait" ) ;
277304 return true ;
278305 } ,
279306 FontFamily = "Segoe MDL2 Assets" ,
@@ -291,7 +318,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
291318 AcceleratorModifiers = ModifierKeys . Control ,
292319 Action = _ =>
293320 {
294- Helper . OpenInShell ( "winget" , " upgrade " + idStr + " --wait" , "/ ") ;
321+ Winget ( " upgrade " + idStr + " --wait" ) ;
295322 return true ;
296323 } ,
297324 FontFamily = "Segoe MDL2 Assets" ,
@@ -305,7 +332,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
305332 AcceleratorModifiers = ModifierKeys . Control ,
306333 Action = _ =>
307334 {
308- Helper . OpenInShell ( "winget" , " uninstall " + idStr + " --wait" , "/ ") ;
335+ Winget ( " uninstall " + idStr + " --wait" ) ;
309336 return true ;
310337 } ,
311338 FontFamily = "Segoe MDL2 Assets" ,
0 commit comments