diff --git a/src/Widgets/Logger.cs b/src/Widgets/Logger.cs index 1edcefe..52648f1 100644 --- a/src/Widgets/Logger.cs +++ b/src/Widgets/Logger.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics; namespace Widgets_for_UniGetUI { diff --git a/src/Widgets/Program.cs b/src/Widgets/Program.cs index 275d337..08db508 100644 --- a/src/Widgets/Program.cs +++ b/src/Widgets/Program.cs @@ -1,12 +1,9 @@ // Program.cs -using System.Runtime.InteropServices; -using ComTypes = System.Runtime.InteropServices.ComTypes; -using Microsoft.Windows.Widgets; -using WingetUIWidgetProvider; using COM; -using System; +using System.Runtime.InteropServices; using Widgets_for_UniGetUI; +using WingetUIWidgetProvider; [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); @@ -40,7 +37,7 @@ static extern int CoRegisterClassObject( else { // Wait until the manager has disposed of the last widget provider. - using (var emptyWidgetListEvent = WidgetProvider.GetEmptyWidgetListEvent()) + using (ManualResetEvent emptyWidgetListEvent = WidgetProvider.GetEmptyWidgetListEvent()) { emptyWidgetListEvent.WaitOne(); } diff --git a/src/Widgets/Templates.cs b/src/Widgets/Templates.cs index 9f9ba8d..b41e5c9 100644 --- a/src/Widgets/Templates.cs +++ b/src/Widgets/Templates.cs @@ -1,22 +1,4 @@ -using ABI.System; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; -using Microsoft.VisualBasic; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Net.WebSockets; -using System.Text; -using System.Threading.Tasks; -using Windows.ApplicationModel; -using Windows.Graphics.Printing.PrintSupport; -using Windows.UI.Text; -using WingetUIWidgetProvider; -using static System.Net.Mime.MediaTypeNames; - -namespace WingetUIWidgetProvider +namespace WingetUIWidgetProvider { public static class Verbs diff --git a/src/Widgets/WidgetProvider.cs b/src/Widgets/WidgetProvider.cs index 3dc8b1e..1bc873b 100644 --- a/src/Widgets/WidgetProvider.cs +++ b/src/Widgets/WidgetProvider.cs @@ -1,24 +1,13 @@ using Microsoft.Windows.Widgets; using Microsoft.Windows.Widgets.Providers; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Widgets_for_UniGetUI; -using Windows.ApplicationModel.Chat; -using Windows.Management.Deployment; -using Windows.Security.Cryptography.Core; -using Windows.Storage.Pickers; namespace WingetUIWidgetProvider { internal class WidgetProvider : IWidgetProvider { - public static Dictionary RunningWidgets = new Dictionary(); + public static Dictionary RunningWidgets = new(); WingetUIConnector UniGetUI; @@ -27,16 +16,16 @@ public WidgetProvider() UniGetUI = new WingetUIConnector(); UniGetUI.UpdateCheckFinished += UniGetUI_UpdateCheckFinished; - var runningWidgets = WidgetManager.GetDefault().GetWidgetInfos(); + WidgetInfo[] runningWidgets = WidgetManager.GetDefault().GetWidgetInfos(); - foreach (var widgetInfo in runningWidgets) + foreach (WidgetInfo? widgetInfo in runningWidgets) { - var widgetContext = widgetInfo.WidgetContext; - var widgetId = widgetContext.Id; - var widgetName = widgetContext.DefinitionId; + WidgetContext widgetContext = widgetInfo.WidgetContext; + string widgetId = widgetContext.Id; + string widgetName = widgetContext.DefinitionId; if (!RunningWidgets.ContainsKey(widgetId)) { - GenericWidget runningWidgetInfo = new GenericWidget(widgetId, widgetName); + GenericWidget runningWidgetInfo = new(widgetId, widgetName); try { runningWidgetInfo.isActive = true; @@ -54,7 +43,7 @@ public WidgetProvider() private void StartLoadingRoutine(GenericWidget widget) { - WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(widget.Id); + WidgetUpdateRequestOptions updateOptions = new(widget.Id); updateOptions.Data = "{ \"IsLoading\": true }"; Logger.Log("Calling to UniGetUI.GetAvailableUpdates(widget) from widget"); updateOptions.Template = Templates.BaseTemplate; @@ -64,7 +53,7 @@ private void StartLoadingRoutine(GenericWidget widget) private void UniGetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEventArgs e) { - WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(e.widget.Id); + WidgetUpdateRequestOptions updateOptions = new(e.widget.Id); updateOptions.Template = Templates.BaseTemplate; if (!e.Succeeded) @@ -88,7 +77,7 @@ private void UniGetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv e.widget.AvailableUpdates = e.Updates; Logger.Log("Showing available updates..."); - List upgradablePackages = new List(); + List upgradablePackages = new(); for (int i = 0; i < e.widget.AvailableUpdates.Length; i++) { if (e.widget.AvailableUpdates[i].Name != String.Empty) @@ -119,9 +108,9 @@ private void UniGetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv public void CreateWidget(WidgetContext widgetContext) { - var widgetId = widgetContext.Id; - var widgetName = widgetContext.DefinitionId; - GenericWidget runningWidgetInfo = new GenericWidget(widgetId, widgetName); + string widgetId = widgetContext.Id; + string widgetName = widgetContext.DefinitionId; + GenericWidget runningWidgetInfo = new(widgetId, widgetName); RunningWidgets[widgetId] = runningWidgetInfo; StartLoadingRoutine(runningWidgetInfo); } @@ -136,7 +125,7 @@ public void DeleteWidget(string widgetId, string customState) } } - static ManualResetEvent emptyWidgetListEvent = new ManualResetEvent(false); + static ManualResetEvent emptyWidgetListEvent = new(false); public static ManualResetEvent GetEmptyWidgetListEvent() { @@ -145,13 +134,13 @@ public static ManualResetEvent GetEmptyWidgetListEvent() public void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) { - var widgetId = actionInvokedArgs.WidgetContext.Id; - var data = actionInvokedArgs.Data; - WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(widgetId); + string widgetId = actionInvokedArgs.WidgetContext.Id; + string data = actionInvokedArgs.Data; + WidgetUpdateRequestOptions updateOptions = new(widgetId); if (RunningWidgets.ContainsKey(widgetId)) { GenericWidget widget = RunningWidgets[widgetId]; - var verb = actionInvokedArgs.Verb; + string verb = actionInvokedArgs.Verb; switch (verb) { @@ -201,12 +190,12 @@ public void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs) public void OnWidgetContextChanged(WidgetContextChangedArgs contextChangedArgs) { - var widgetContext = contextChangedArgs.WidgetContext; - var widgetId = widgetContext.Id; - var widgetSize = widgetContext.Size; + WidgetContext widgetContext = contextChangedArgs.WidgetContext; + string widgetId = widgetContext.Id; + WidgetSize widgetSize = widgetContext.Size; if (RunningWidgets.ContainsKey(widgetId)) { - var widget = RunningWidgets[widgetId]; + GenericWidget widget = RunningWidgets[widgetId]; widget.size = widgetContext.Size; UniGetUI.GetAvailableUpdates(widget); @@ -215,11 +204,11 @@ public void OnWidgetContextChanged(WidgetContextChangedArgs contextChangedArgs) public void Activate(WidgetContext widgetContext) { - var widgetId = widgetContext.Id; + string widgetId = widgetContext.Id; if (RunningWidgets.ContainsKey(widgetId)) { - var widget = RunningWidgets[widgetId]; + GenericWidget widget = RunningWidgets[widgetId]; widget.isActive = true; widget.size = widgetContext.Size; UniGetUI.GetAvailableUpdates(widget); @@ -229,7 +218,7 @@ public void Deactivate(string widgetId) { if (RunningWidgets.ContainsKey(widgetId)) { - var widget = RunningWidgets[widgetId]; + GenericWidget widget = RunningWidgets[widgetId]; widget.isActive = false; } } diff --git a/src/Widgets/WingetUIConnector.cs b/src/Widgets/WingetUIConnector.cs index 87f95f1..0c5131c 100644 --- a/src/Widgets/WingetUIConnector.cs +++ b/src/Widgets/WingetUIConnector.cs @@ -1,24 +1,7 @@ -using Microsoft.Windows.ApplicationModel.DynamicDependency; -using Microsoft.Windows.Widgets.Providers; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.Diagnostics; -using System.Linq; +using Microsoft.Windows.Widgets.Providers; using System.Net.Http.Headers; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; using System.Timers; using Widgets_for_UniGetUI; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Background; -using Windows.ApplicationModel.UserDataTasks; -using Windows.Devices.Printers; -using Windows.Management.Deployment; -using Windows.Media.Protection.PlayReady; -using static System.Net.Mime.MediaTypeNames; namespace WingetUIWidgetProvider { @@ -34,9 +17,9 @@ internal class WingetUIConnector private bool update_cache_is_valid = false; private Package[] cached_updates = new Package[0]; - private System.Timers.Timer CacheExpirationTimer = new System.Timers.Timer(); + private System.Timers.Timer CacheExpirationTimer = new(); - public Dictionary WidgetSourceReference = new Dictionary() + public Dictionary WidgetSourceReference = new() { {Widgets.All, ""}, {Widgets.Winget, "Winget"}, @@ -77,7 +60,7 @@ public void OnCacheExpire(object? source, ElapsedEventArgs? e) async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = false) { Logger.Log("BEGIN GetAvailableUpdates(). Widget.Name=" + Widget.Name + ", DeepCheck=" + DeepCheck.ToString()); - UpdatesCheckFinishedEventArgs result = new UpdatesCheckFinishedEventArgs(Widget); + UpdatesCheckFinishedEventArgs result = new(Widget); string AllowedSource = WidgetSourceReference[Widget.Name]; Package[] found_updates; @@ -88,13 +71,13 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal if (!is_connected_to_host) { Logger.Log("GetAvailableUpdates: BEGIN connection to the host"); - WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(Widget.Id); + WidgetUpdateRequestOptions updateOptions = new(Widget.Id); updateOptions.Template = Templates.BaseTemplate; updateOptions.Data = Templates.GetData_IsLoading(); WidgetManager.GetDefault().UpdateWidget(updateOptions); - var old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui", "CurrentSessionToken"); - var new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CurrentSessionToken"); + string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui", "CurrentSessionToken"); + string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI", "CurrentSessionToken"); string SessionTokenFile; if(!File.Exists(new_path)) @@ -103,18 +86,18 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal SessionTokenFile = new_path; else { - FileInfo old_path_data = new FileInfo(old_path); - var old_created = old_path_data.LastWriteTimeUtc; //File Creation - FileInfo new_path_data = new FileInfo(new_path); - var new_created = new_path_data.LastWriteTimeUtc; //File Creation + FileInfo old_path_data = new(old_path); + DateTime old_created = old_path_data.LastWriteTimeUtc; //File Creation + FileInfo new_path_data = new(new_path); + DateTime new_created = new_path_data.LastWriteTimeUtc; //File Creation SessionTokenFile = old_created > new_created ? old_path : new_path; } - StreamReader reader = new StreamReader(SessionTokenFile); + StreamReader reader = new(SessionTokenFile); SessionToken = reader.ReadToEnd().ToString().Replace("\n", "").Trim(); reader.Close(); - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -180,13 +163,13 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal try { Logger.Log("GetAvailableUpdates: BEGIN retrieving updates from the host"); - WidgetUpdateRequestOptions updateOptions = new WidgetUpdateRequestOptions(Widget.Id); + WidgetUpdateRequestOptions updateOptions = new(Widget.Id); updateOptions.Template = Templates.BaseTemplate; updateOptions.Data = Templates.GetData_IsLoading(); WidgetManager.GetDefault().UpdateWidget(updateOptions); Logger.Log("Fetching updates from server"); - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -210,7 +193,7 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal cached_updates = new Package[updateCount]; for (int i = 0; i < updateCount; i++) { - Package package = new Package(packageStrings[i]); + Package package = new(packageStrings[i]); cached_updates[i] = package; } update_cache_is_valid = true; @@ -284,7 +267,7 @@ async public void OpenWingetUI() { try { - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -302,7 +285,7 @@ async public void ViewOnWingetUI() { try { - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -320,7 +303,7 @@ async public void UpdatePackage(Package package) { try { - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -339,7 +322,7 @@ async public void UpdateAllPackages() { try { - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -357,7 +340,7 @@ async public void UpdateAllPackagesForSource(string source) { try { - HttpClient client = new HttpClient(); + HttpClient client = new(); client.BaseAddress = new Uri("http://localhost:7058//"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));