diff --git a/PeyrSharp.Env/Sys.cs b/PeyrSharp.Env/Sys.cs
index 7c3988d..dc49080 100644
--- a/PeyrSharp.Env/Sys.cs
+++ b/PeyrSharp.Env/Sys.cs
@@ -30,6 +30,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
+using System.Text.Json;
+using System.Threading.Tasks;
+using static System.Net.Mime.MediaTypeNames;
namespace PeyrSharp.Env
{
@@ -248,5 +251,52 @@ public static bool TerminateProcess(int processId)
return false;
}
}
+
+ ///
+ /// Retrieves a list of UWP (Universal Windows Platform) apps asynchronously.
+ ///
+ /// Only works on Windows 10 and higher.
+ /// A task that represents the asynchronous operation. The task result contains a list of UwpApp objects representing the UWP apps.
+ ///
+ ///
+ [SupportedOSPlatform("windows")]
+ public static async Task> GetUwpAppsAsync()
+ {
+ ProcessStartInfo pInfo = new()
+ {
+ FileName = "powershell.exe",
+ Arguments = @"& Get-StartApps | ConvertTo-Json > $env:appdata\UwpApps.json",
+ UseShellExecute = true,
+ CreateNoWindow = true
+ };
+
+ Process process = new() { StartInfo = pInfo };
+ process.Start();
+ await process.WaitForExitAsync();
+
+ string appsFile = await File.ReadAllTextAsync($@"{FileSys.AppDataPath}\UWPapps.json");
+ List apps = JsonSerializer.Deserialize>(appsFile); // Get apps
+ List sortedApps = new(); // Create final list
+ Dictionary uwpApps = new(); // Create a dictionnary
+
+ // Sort apps to only have UWP apps (they have a "!" in the AppID property)
+ for (int i = 0; i < apps.Count; i++)
+ {
+ if (apps[i].AppID.Contains('!'))
+ {
+ uwpApps.Add(apps[i], apps[i].Name);
+ }
+ }
+
+ // Sort alphabetically
+ var sorted = from pair in uwpApps orderby pair.Value ascending select pair; // Sort
+
+ foreach (KeyValuePair pair1 in sorted)
+ {
+ sortedApps.Add(pair1.Key);
+ }
+
+ return sortedApps; // Return
+ }
}
}