diff --git a/Community.PowerToys.Run.Plugin.Winget.csproj b/Community.PowerToys.Run.Plugin.Winget.csproj
index 3ab41eb..2352f9a 100644
--- a/Community.PowerToys.Run.Plugin.Winget.csproj
+++ b/Community.PowerToys.Run.Plugin.Winget.csproj
@@ -2,7 +2,7 @@
- net8.0-windows
+ net8.0-windows8.0
{46778CB7-A2FD-4949-A845-B19EF1A6364B}
Properties
Community.PowerToys.Run.Plugin.Winget
diff --git a/Community.PowerToys.Run.Plugin.Winget.sln b/Community.PowerToys.Run.Plugin.Winget.sln
new file mode 100644
index 0000000..fcd3408
--- /dev/null
+++ b/Community.PowerToys.Run.Plugin.Winget.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.002.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.PowerToys.Run.Plugin.Winget", "Community.PowerToys.Run.Plugin.Winget.csproj", "{22FEFF75-335F-4995-8290-1219ED7E09BE}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {22FEFF75-335F-4995-8290-1219ED7E09BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {22FEFF75-335F-4995-8290-1219ED7E09BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {22FEFF75-335F-4995-8290-1219ED7E09BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {22FEFF75-335F-4995-8290-1219ED7E09BE}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {D2F57221-2395-4F5E-8FB5-C0F2084D7E0E}
+ EndGlobalSection
+EndGlobal
diff --git a/Main.cs b/Main.cs
index 9376a97..2c0e94e 100644
--- a/Main.cs
+++ b/Main.cs
@@ -46,6 +46,14 @@ public partial class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
public static string PluginID => "46778CB7A2FD4949A845B19EF1A6364B";
+ private static string waitStr = "--wait";
+ private static string forceStr = "-force";
+
+ private static string upgradeAllText = string.Format(
+ CultureInfo.CurrentCulture,
+ Properties.Resources.plugin_winget_upgrade_all_text,
+ Properties.Resources.plugin_winget_cmd_upgrade_all);
+
public IEnumerable AdditionalOptions => new List()
{
new PluginAdditionalOption()
@@ -133,19 +141,32 @@ public List Query(Query query)
// empty query
if (string.IsNullOrEmpty(query.Search))
{
- string arguments = "winget ";
results.Add(new Result
{
Title = Properties.Resources.plugin_description,
- SubTitle = "via winget CLI",
+ SubTitle = Properties.Resources.plugin_via_winget_cli,
+ QueryTextDisplay = string.Empty,
+ IcoPath = _iconPath,
+ ProgramArguments = Properties.Resources.plugin_winget_start_cmd,
+ Action = action =>
+ {
+ return true;
+ },
+ });
+ results.Add(new Result
+ {
+ Title = upgradeAllText,
+ SubTitle = Properties.Resources.plugin_via_winget_cli,
QueryTextDisplay = string.Empty,
IcoPath = _iconPath,
- ProgramArguments = arguments,
+ ProgramArguments = Properties.Resources.plugin_winget_start_cmd,
Action = action =>
{
+ Winget(Properties.Resources.plugin_winget_cmd_upgrade_all, asAdmin: true);
return true;
},
});
+
return results;
}
else
@@ -166,7 +187,7 @@ public List Query(Query query)
ProgramArguments = idStr,
Action = action =>
{
- Winget($"install {idStr} --wait");
+ Winget($"install {idStr} {waitStr}");
return true;
},
});
@@ -198,14 +219,13 @@ public void Init(PluginInitContext context)
LoadInstalledList();
}
- public static void Winget(string cmd)
+ public static void Winget(string cmd, bool asAdmin = false)
{
- // Call thread
- Thread thread = new Thread(() => WingetCmdThread(cmd));
+ Thread thread = new Thread(() => WingetCmdThread(cmd, asAdmin));
thread.Start();
}
- public static void WingetCmdThread(string cmd)
+ public static void WingetCmdThread(string cmd, bool asAdmin)
{
Process process = new Process();
@@ -213,7 +233,20 @@ public static void WingetCmdThread(string cmd)
process.StartInfo.Arguments = cmd;
process.StartInfo.UseShellExecute = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
- process.Start();
+ if (asAdmin)
+ {
+ process.StartInfo.Verb = "runas";
+ }
+
+ try
+ {
+ process.Start();
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("User aborted UAC dialog");
+ return;
+ }
// Wait for process to exit
process.WaitForExit();
@@ -222,7 +255,7 @@ public static void WingetCmdThread(string cmd)
private static List GetContextMenu(in Result result, in string assemblyName)
{
- if (result?.Title == Properties.Resources.plugin_description)
+ if (result?.Title == Properties.Resources.plugin_description || result?.Title == upgradeAllText)
{
return new List(0);
}
@@ -238,7 +271,7 @@ private static List GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
- Winget("install " + idStr + " -i --force --wait");
+ Winget($"install {idStr} -i {forceStr} {waitStr}");
return true;
},
FontFamily = "Segoe MDL2 Assets",
@@ -256,7 +289,7 @@ private static List GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
- Winget("upgrade " + idStr + " --wait");
+ Winget($"upgrade {idStr} {waitStr}");
return true;
},
FontFamily = "Segoe MDL2 Assets",
@@ -270,7 +303,7 @@ private static List GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
- Winget("uninstall " + idStr + " --wait");
+ Winget($"uninstall {idStr} {waitStr}");
return true;
},
FontFamily = "Segoe MDL2 Assets",
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
index 03017e6..c0a4494 100644
--- a/Properties/Resources.Designer.cs
+++ b/Properties/Resources.Designer.cs
@@ -140,5 +140,41 @@ public static string plugin_search_failed {
return ResourceManager.GetString("plugin_search_failed", resourceCulture);
}
}
+
+ ///
+ /// Sucht eine lokalisierte Zeichenfolge, die via winget CLI ähnelt.
+ ///
+ public static string plugin_via_winget_cli {
+ get {
+ return ResourceManager.GetString("plugin_via_winget_cli", resourceCulture);
+ }
+ }
+
+ ///
+ /// Sucht eine lokalisierte Zeichenfolge, die update --all --source winget ähnelt.
+ ///
+ public static string plugin_winget_cmd_upgrade_all {
+ get {
+ return ResourceManager.GetString("plugin_winget_cmd_upgrade_all", resourceCulture);
+ }
+ }
+
+ ///
+ /// Sucht eine lokalisierte Zeichenfolge, die winget ähnelt.
+ ///
+ public static string plugin_winget_start_cmd {
+ get {
+ return ResourceManager.GetString("plugin_winget_start_cmd", resourceCulture);
+ }
+ }
+
+ ///
+ /// Sucht eine lokalisierte Zeichenfolge, die Upgrade all winget packages ({0}) ähnelt.
+ ///
+ public static string plugin_winget_upgrade_all_text {
+ get {
+ return ResourceManager.GetString("plugin_winget_upgrade_all_text", resourceCulture);
+ }
+ }
}
}
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index 9a4d952..8130d6e 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -145,4 +145,16 @@
Failed to open {0}.
+
+ via winget CLI
+
+
+ update --all --source winget
+
+
+ winget
+
+
+ Upgrade all winget packages ({0})
+
\ No newline at end of file
diff --git a/README.md b/README.md
index e79535d..8fd5a50 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,16 @@ This is a plugin for [PowerToys Run](https://github.com/microsoft/PowerToys/wiki
## Installation
+Use the installation script `release.ps1`:
+
+```powershell
+.\release.ps1
+```
+
+Then restart PowerToys
+
+**Or manually:**
+
1. Download the latest release of the Winget Plugin from the [releases page](https://github.com/bostrot/PowerToysRunPluginWinget/releases).
2. Extract the zip file's contents to your PowerToys modules directory (usually `%LOCALAPPDATA%\Microsoft\PowerToys\RunPlugins`).
3. Restart PowerToys.
diff --git a/installer.ps1 b/installer.ps1
index 28e3d2a..1fc692a 100644
--- a/installer.ps1
+++ b/installer.ps1
@@ -1,7 +1,7 @@
# PowerShell script that downloads latest release from GitHub and installs it to PowerToys Run plugin folder
# Usage: .\installer.ps1
-$installLocation = "%LOCALAPPDATA%\PowerToys\RunPlugins\Winget"
+$installLocation = "$env:LOCALAPPDATA\Microsoft\PowerToys\PowerToys Run\Plugins\Winget"
# Get latest release from GitHub
$latestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/bostrot/PowerToysRunPluginWinget/releases/latest"
diff --git a/installer_local.ps1 b/installer_local.ps1
new file mode 100644
index 0000000..a11cebd
--- /dev/null
+++ b/installer_local.ps1
@@ -0,0 +1,16 @@
+# PowerShell script that downloads latest release from GitHub and installs it to PowerToys Run plugin folder
+# Usage: .\installer.ps1
+
+
+$version = "1.3.0"
+$release = "C:\Users\erict\Downloads\winget-powertoys-$version.zip"
+$installLocation = "$env:LOCALAPPDATA\PowerToys\RunPlugins\Winget"
+
+# Unzip latest release
+Expand-Archive -Path $release -DestinationPath "$installLocation.tmp"
+
+# Move files to plugin folder
+Move-Item "$installLocation.tmp\Winget" $installLocation
+
+# Remove temporary folder
+Remove-Item "$installLocation.tmp" -Recurse
\ No newline at end of file
diff --git a/release.ps1 b/release.ps1
index 3f6ad7d..dbfc1a4 100644
--- a/release.ps1
+++ b/release.ps1
@@ -1,9 +1,9 @@
# Script for copying the release files and creating the release zip file
# C:\Users\erict\PowerToys-dev\x64\Release\RunPlugins\Winget
-$version = "1.2.3"
+$version = "1.3.0"
$release = "C:\Users\erict\Downloads\winget-powertoys-$version.zip"
$zip = "C:\Program Files\7-Zip\7z.exe"
-$path = "C:\Users\erict\PowerToys-dev\x64\Release\RunPlugins\Winget"
+$path = "D:\erict\PowerToys-dev\x64\Release\RunPlugins\Winget"
# pack the files from path and excluding
&$zip a -aoa -bb0 -bso0 -xr!PowerToys* -xr!Backup* -xr!Ijwhost* -tzip $release $path