diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Community.PowerToys.Run.Plugin.CurrencyConverter.csproj b/Community.PowerToys.Run.Plugin.CurrencyConverter/Community.PowerToys.Run.Plugin.CurrencyConverter.csproj index 51cfebe..49599c4 100644 --- a/Community.PowerToys.Run.Plugin.CurrencyConverter/Community.PowerToys.Run.Plugin.CurrencyConverter.csproj +++ b/Community.PowerToys.Run.Plugin.CurrencyConverter/Community.PowerToys.Run.Plugin.CurrencyConverter.csproj @@ -8,26 +8,46 @@ true Community.PowerToys.Run.Plugin.CurrencyConverter Community.PowerToys.Run.Plugin.CurrencyConverter - 1.1.0 + 1.1.1 false false AnyCPU;x64;ARM64 - - - - - + + Libs\x64\PowerToys.Common.UI.dll + + + Libs\x64\PowerToys.ManagedCommon.dll + + + Libs\x64\PowerToys.Settings.UI.Lib.dll + + + Libs\x64\Wox.Infrastructure.dll + + + Libs\x64\Wox.Plugin.dll + - - - - - + + Libs\ARM64\PowerToys.Common.UI.dll + + + Libs\ARM64\PowerToys.ManagedCommon.dll + + + Libs\ARM64\PowerToys.Settings.UI.Lib.dll + + + Libs\ARM64\Wox.Infrastructure.dll + + + Libs\ARM64\Wox.Plugin.dll + diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Common.UI.dll b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Common.UI.dll index efcf86a..67c2229 100644 Binary files a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Common.UI.dll and b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Common.UI.dll differ diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.ManagedCommon.dll b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.ManagedCommon.dll index e60d514..a52e754 100644 Binary files a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.ManagedCommon.dll and b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.ManagedCommon.dll differ diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Settings.UI.Lib.dll b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Settings.UI.Lib.dll index 4ee83d3..8421808 100644 Binary files a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Settings.UI.Lib.dll and b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/PowerToys.Settings.UI.Lib.dll differ diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Infrastructure.dll b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Infrastructure.dll index 45c346e..c4f3ecb 100644 Binary files a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Infrastructure.dll and b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Infrastructure.dll differ diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Plugin.dll b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Plugin.dll index d642dac..3ad0338 100644 Binary files a/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Plugin.dll and b/Community.PowerToys.Run.Plugin.CurrencyConverter/Libs/x64/Wox.Plugin.dll differ diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/Main.cs b/Community.PowerToys.Run.Plugin.CurrencyConverter/Main.cs index fe7cf2e..7ea6a19 100644 --- a/Community.PowerToys.Run.Plugin.CurrencyConverter/Main.cs +++ b/Community.PowerToys.Run.Plugin.CurrencyConverter/Main.cs @@ -20,14 +20,15 @@ public class Main : IPlugin, ISettingProvider private PluginInitContext Context { get; set; } public string Name => "Currency Converter"; - public string Description => "Currency Converter Plugin"; + public string Description => "Convert real and crypto currencies."; - private Dictionary ConversionCache = new Dictionary(); + private Dictionary ConversionCache = []; private readonly HttpClient Client = new HttpClient(); private readonly RegionInfo regionInfo = new RegionInfo(CultureInfo.CurrentCulture.Name); private int ConversionDirection; private string LocalCurrency, GlobalCurrency; + private string[] ExtraCurrencies; public IEnumerable AdditionalOptions => new List() { @@ -37,12 +38,12 @@ public class Main : IPlugin, ISettingProvider DisplayLabel = "Quick Convertion Direction", DisplayDescription = "Set in which direction you want to convert.", PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Combobox, - ComboBoxItems = new List> - { + ComboBoxItems = + [ new KeyValuePair("From local to global", "0"), new KeyValuePair("From global to local", "1"), - }, - ComboBoxValue = ConversionDirection, + ], + ComboBoxValue = 0, }, new PluginAdditionalOption() { @@ -60,6 +61,14 @@ public class Main : IPlugin, ISettingProvider PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox, TextValue = "USD", }, + new PluginAdditionalOption() + { + Key = "QuickConversionExtraCurrencies", + DisplayLabel = "Extra currencies for quick conversion", + DisplayDescription = "Add currencies comma separated. eg: USD, EUR, BTC", + PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox, + TextValue = "", + }, }; public void UpdateSettings(PowerLauncherPluginSettings settings) @@ -70,8 +79,14 @@ public void UpdateSettings(PowerLauncherPluginSettings settings) string _LocalCurrency = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "QuickConversionLocalCurrency").TextValue; LocalCurrency = _LocalCurrency == "" ? regionInfo.ISOCurrencySymbol : _LocalCurrency; - string _GlobalCurrency = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "QuickConversionGlobalCurrency").TextValue; - GlobalCurrency = _GlobalCurrency == "" ? "USD" : _GlobalCurrency; + GlobalCurrency = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "QuickConversionGlobalCurrency").TextValue; + + ExtraCurrencies = settings.AdditionalOptions + .FirstOrDefault(x => x.Key == "QuickConversionExtraCurrencies") + .TextValue.Split(',') + .Select(x => x.Trim()) + .Where(x => !string.IsNullOrEmpty(x)) + .ToArray(); } } @@ -119,12 +134,20 @@ private double GetConversionRate(string fromCurrency, string toCurrency) } } - private Result GetConversion(double amountToConvert, string fromCurrency, string toCurrency) + private Result? GetConversion(double amountToConvert, string fromCurrency, string toCurrency) { + fromCurrency = fromCurrency.ToLower(); + toCurrency = toCurrency.ToLower(); + + if (fromCurrency == toCurrency || fromCurrency == "" || toCurrency == "") + { + return null; + } + double conversionRate = 0; try { - conversionRate = GetConversionRate(fromCurrency.ToLower(), toCurrency.ToLower()); + conversionRate = GetConversionRate(fromCurrency, toCurrency); } catch (Exception e) { @@ -158,17 +181,17 @@ private Result GetConversion(double amountToConvert, string fromCurrency, string }; } - public List Query(Query query) + private List ParseQuery(string search) { double amountToConvert = 0; string fromCurrency = ""; string toCurrency = ""; - var match = Regex.Match(query.Search.Trim(), @"([0-9.,]+) ?(\w*) ?(to)? ?(\w*)"); + var match = Regex.Match(search.Trim(), @"([0-9.,]+) ?(\w*) ?(to)? ?(\w*)"); if (! match.Success) { - return new List(); + return []; } if (double.TryParse(match.Groups[1].Value, out amountToConvert)) @@ -186,25 +209,45 @@ public List Query(Query query) fromCurrency = ConversionDirection == 0 ? LocalCurrency : GlobalCurrency; toCurrency = ConversionDirection == 0 ? GlobalCurrency : LocalCurrency; - return new List + List results = [GetConversion(amountToConvert, fromCurrency, toCurrency)]; + foreach (string currency in ExtraCurrencies) { - GetConversion(amountToConvert, fromCurrency, toCurrency), - GetConversion(amountToConvert, toCurrency, fromCurrency) - }; - } + results.Add(GetConversion(amountToConvert, fromCurrency, currency)); + } + + results.Add(GetConversion(amountToConvert, toCurrency, fromCurrency)); + foreach (string currency in ExtraCurrencies) + { + results.Add(GetConversion(amountToConvert, toCurrency, currency)); + } + + return results; + } else if (String.IsNullOrEmpty(toCurrency)) { - return new List - { + List results = + [ GetConversion(amountToConvert, fromCurrency, ConversionDirection == 0 ? GlobalCurrency : LocalCurrency), GetConversion(amountToConvert, fromCurrency, ConversionDirection == 0 ? LocalCurrency : GlobalCurrency) - }; + ]; + + foreach (string currency in ExtraCurrencies) + { + results.Add(GetConversion(amountToConvert, fromCurrency, currency)); + } + + return results; } - return new List - { + return + [ GetConversion(amountToConvert, fromCurrency, toCurrency) - }; + ]; + } + + public List Query(Query query) + { + return ParseQuery(query.Search).Where(x => x != null).ToList(); } public void Init(PluginInitContext context) diff --git a/Community.PowerToys.Run.Plugin.CurrencyConverter/plugin.json b/Community.PowerToys.Run.Plugin.CurrencyConverter/plugin.json index 1fddfed..11d6271 100644 --- a/Community.PowerToys.Run.Plugin.CurrencyConverter/plugin.json +++ b/Community.PowerToys.Run.Plugin.CurrencyConverter/plugin.json @@ -4,7 +4,7 @@ "ActionKeyword": "$$", "Name": "Currency Converter", "Author": "advaith3600", - "Version": "1.1.0", + "Version": "1.1.1", "Language": "csharp", "Website": "https://github.com/advaith3600/PowerToys-Run-Currency-Converter", "ExecuteFileName": "Community.PowerToys.Run.Plugin.CurrencyConverter.dll", diff --git a/README.md b/README.md index d1962bf..3ff473c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ You can change the `$$` prefix from the settings page. To use this plugin withou 1 eur to usd ``` -![Screenshot](screenshots/screenshot5.png) +![Screenshot](screenshots/screenshot2.png) ### Crypto and other currencies @@ -30,25 +30,25 @@ Example Usage: $$ 1 btc to usd ``` -![Screenshot](screenshots/screenshot2.png) +![Screenshot](screenshots/screenshot3.png) ### Quick Conversions -You can quickly convert from your local currency to a global currency by just typing the number. +You can quickly convert from your local currency to a global currency by just typing the number. This list will also include all the extra currencies that you have configured in the settings panel. ``` $$ 102.2 ``` -![Screenshot](screenshots/screenshot3.png) +![Screenshot](screenshots/screenshot4.png) -Or, you can convert any currency to your local and global by: +Or, you can convert any currency to your local and global including the extra currencies by: ``` $$ 1 eur ``` -![Screenshot](screenshots/screenshot4.png) +![Screenshot](screenshots/screenshot5.png) Your local currency, global currency and the quick conversion direction can also be changed from the settings page in PowerToys Run under this plugin. diff --git a/screenshots/screenshot2.png b/screenshots/screenshot2.png index 06deda6..647df59 100644 Binary files a/screenshots/screenshot2.png and b/screenshots/screenshot2.png differ diff --git a/screenshots/screenshot3.png b/screenshots/screenshot3.png index b1e9209..06deda6 100644 Binary files a/screenshots/screenshot3.png and b/screenshots/screenshot3.png differ diff --git a/screenshots/screenshot4.png b/screenshots/screenshot4.png index c8fd7fe..e166e86 100644 Binary files a/screenshots/screenshot4.png and b/screenshots/screenshot4.png differ diff --git a/screenshots/screenshot5.png b/screenshots/screenshot5.png index c1f1c80..33c436f 100644 Binary files a/screenshots/screenshot5.png and b/screenshots/screenshot5.png differ