@@ -46,6 +46,14 @@ public partial class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
4646
4747 public static string PluginID => "46778CB7A2FD4949A845B19EF1A6364B" ;
4848
49+ private static string waitStr = "--wait" ;
50+ private static string forceStr = "-force" ;
51+
52+ private static string upgradeAllText = string . Format (
53+ CultureInfo . CurrentCulture ,
54+ Properties . Resources . plugin_winget_upgrade_all_text ,
55+ Properties . Resources . plugin_winget_cmd_upgrade_all ) ;
56+
4957 public IEnumerable < PluginAdditionalOption > AdditionalOptions => new List < PluginAdditionalOption > ( )
5058 {
5159 new PluginAdditionalOption ( )
@@ -133,19 +141,32 @@ public List<Result> Query(Query query)
133141 // empty query
134142 if ( string . IsNullOrEmpty ( query . Search ) )
135143 {
136- string arguments = "winget " ;
137144 results . Add ( new Result
138145 {
139146 Title = Properties . Resources . plugin_description ,
140- SubTitle = "via winget CLI" ,
147+ SubTitle = Properties . Resources . plugin_via_winget_cli ,
148+ QueryTextDisplay = string . Empty ,
149+ IcoPath = _iconPath ,
150+ ProgramArguments = Properties . Resources . plugin_winget_start_cmd ,
151+ Action = action =>
152+ {
153+ return true ;
154+ } ,
155+ } ) ;
156+ results . Add ( new Result
157+ {
158+ Title = upgradeAllText ,
159+ SubTitle = Properties . Resources . plugin_via_winget_cli ,
141160 QueryTextDisplay = string . Empty ,
142161 IcoPath = _iconPath ,
143- ProgramArguments = arguments ,
162+ ProgramArguments = Properties . Resources . plugin_winget_start_cmd ,
144163 Action = action =>
145164 {
165+ Winget ( Properties . Resources . plugin_winget_cmd_upgrade_all , asAdmin : true ) ;
146166 return true ;
147167 } ,
148168 } ) ;
169+
149170 return results ;
150171 }
151172 else
@@ -166,7 +187,7 @@ public List<Result> Query(Query query)
166187 ProgramArguments = idStr ,
167188 Action = action =>
168189 {
169- Winget ( $ "install { idStr } --wait ") ;
190+ Winget ( $ "install { idStr } { waitStr } ") ;
170191 return true ;
171192 } ,
172193 } ) ;
@@ -198,22 +219,34 @@ public void Init(PluginInitContext context)
198219 LoadInstalledList ( ) ;
199220 }
200221
201- public static void Winget ( string cmd )
222+ public static void Winget ( string cmd , bool asAdmin = false )
202223 {
203- // Call thread
204- Thread thread = new Thread ( ( ) => WingetCmdThread ( cmd ) ) ;
224+ Thread thread = new Thread ( ( ) => WingetCmdThread ( cmd , asAdmin ) ) ;
205225 thread . Start ( ) ;
206226 }
207227
208- public static void WingetCmdThread ( string cmd )
228+ public static void WingetCmdThread ( string cmd , bool asAdmin )
209229 {
210230 Process process = new Process ( ) ;
211231
212232 process . StartInfo . FileName = "winget" ;
213233 process . StartInfo . Arguments = cmd ;
214234 process . StartInfo . UseShellExecute = true ;
215235 process . StartInfo . WindowStyle = ProcessWindowStyle . Normal ;
216- process . Start ( ) ;
236+ if ( asAdmin )
237+ {
238+ process . StartInfo . Verb = "runas" ;
239+ }
240+
241+ try
242+ {
243+ process . Start ( ) ;
244+ }
245+ catch ( Exception )
246+ {
247+ Console . WriteLine ( "User aborted UAC dialog" ) ;
248+ return ;
249+ }
217250
218251 // Wait for process to exit
219252 process . WaitForExit ( ) ;
@@ -222,7 +255,7 @@ public static void WingetCmdThread(string cmd)
222255
223256 private static List < ContextMenuResult > GetContextMenu ( in Result result , in string assemblyName )
224257 {
225- if ( result ? . Title == Properties . Resources . plugin_description )
258+ if ( result ? . Title == Properties . Resources . plugin_description || result ? . Title == upgradeAllText )
226259 {
227260 return new List < ContextMenuResult > ( 0 ) ;
228261 }
@@ -238,7 +271,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
238271 AcceleratorModifiers = ModifierKeys . Control ,
239272 Action = _ =>
240273 {
241- Winget ( "install " + idStr + " -i --force --wait ") ;
274+ Winget ( $ "install { idStr } -i { forceStr } { waitStr } ") ;
242275 return true ;
243276 } ,
244277 FontFamily = "Segoe MDL2 Assets" ,
@@ -256,7 +289,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
256289 AcceleratorModifiers = ModifierKeys . Control ,
257290 Action = _ =>
258291 {
259- Winget ( "upgrade " + idStr + " --wait ") ;
292+ Winget ( $ "upgrade { idStr } { waitStr } ") ;
260293 return true ;
261294 } ,
262295 FontFamily = "Segoe MDL2 Assets" ,
@@ -270,7 +303,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
270303 AcceleratorModifiers = ModifierKeys . Control ,
271304 Action = _ =>
272305 {
273- Winget ( "uninstall " + idStr + " --wait ") ;
306+ Winget ( $ "uninstall { idStr } { waitStr } ") ;
274307 return true ;
275308 } ,
276309 FontFamily = "Segoe MDL2 Assets" ,
0 commit comments