Skip to content

Commit

Permalink
Reload installed list after installing
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrot committed Mar 18, 2023
1 parent 4198a5b commit 973e8ab
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -10,6 +10,7 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
Expand Down Expand Up @@ -56,6 +57,11 @@ public partial class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider

// constructor
public Main()
{
LoadInstalledList();
}

private static void LoadInstalledList()
{
Process process = new Process();

Expand Down Expand Up @@ -224,8 +230,7 @@ public List<Result> Query(Query query)
ProgramArguments = idStr,
Action = action =>
{
Helper.OpenInShell("winget", "install " + idStr + " --wait", "/");
Winget("install " + idStr + " --wait");
return true;
},
});
Expand Down Expand Up @@ -255,6 +260,28 @@ public void Init(PluginInitContext context)
};
}

public static void Winget(string cmd)
{
// Call thread
Thread thread = new Thread(() => WingetCmdThread(cmd));
thread.Start();
}

public static void WingetCmdThread(string cmd)
{
Process process = new Process();

process.StartInfo.FileName = "winget";
process.StartInfo.Arguments = cmd;
process.StartInfo.UseShellExecute = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();

// Wait for process to exit
process.WaitForExit();
LoadInstalledList();
}

private static List<ContextMenuResult> GetContextMenu(in Result result, in string assemblyName)
{
if (result?.Title == Properties.Resources.plugin_description)
Expand All @@ -273,7 +300,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Helper.OpenInShell("winget", "install " + idStr + " -i --force --wait", "/");
Winget("install " + idStr + " -i --force --wait");
return true;
},
FontFamily = "Segoe MDL2 Assets",
Expand All @@ -291,7 +318,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Helper.OpenInShell("winget", "upgrade " + idStr + " --wait", "/");
Winget("upgrade " + idStr + " --wait");
return true;
},
FontFamily = "Segoe MDL2 Assets",
Expand All @@ -305,7 +332,7 @@ private static List<ContextMenuResult> GetContextMenu(in Result result, in strin
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Helper.OpenInShell("winget", "uninstall " + idStr + " --wait", "/");
Winget("uninstall " + idStr + " --wait");
return true;
},
FontFamily = "Segoe MDL2 Assets",
Expand Down

0 comments on commit 973e8ab

Please sign in to comment.