diff --git a/Main.cs b/Main.cs index f72b59b..bd0d079 100644 --- a/Main.cs +++ b/Main.cs @@ -104,9 +104,16 @@ private async Task CreateResult(SettingItem settingItem, List ar if (!Uri.TryCreate(updatedUrl, UriKind.Absolute, out Uri uri)) return null; - string iconPath = string.IsNullOrEmpty(settingItem.IconPath) - ? await GetFaviconUrl(uri) ?? "Images\\app.png" - : settingItem.IconPath; + string iconPath = settingItem.IconPath; + + if (string.IsNullOrEmpty(iconPath)) + { + string faviconUrl = $"https://www.google.com/s2/favicons?domain_url={uri.Host}&sz=48"; + if (await IsFaviconAccessible(faviconUrl)) + iconPath = faviconUrl; + else + iconPath = "Images\\app.png"; + } return new Result { @@ -122,25 +129,20 @@ private async Task CreateResult(SettingItem settingItem, List ar }; } - private async Task GetFaviconUrl(Uri uri) + private async Task IsFaviconAccessible(string faviconUrl) { try { - string faviconUrl = $"{uri.Scheme}://{uri.Host}/favicon.ico"; - using (HttpClient client = new HttpClient()) { - var request = new HttpRequestMessage(HttpMethod.Head, faviconUrl); - var response = await client.SendAsync(request); - - if (response.IsSuccessStatusCode) - { - return faviconUrl; - } + var response = await client.GetAsync(faviconUrl); + return response.IsSuccessStatusCode; } } - catch {} - return null; + catch + { + return false; + } } private Result CreateBulkOpenResult(string searchTerm, IEnumerable itemsToOpen, List args) diff --git a/plugin.json b/plugin.json index 5ae96ab..bd24598 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "Name": "LinkOpener", "Description": "Allows you to open URLs using keywords set in the settings", "Author": "Exarilo", - "Version": "1.0.9", + "Version": "1.1.0", "Language": "csharp", "Website": "https://github.com/Exarilo/Flow.Launcher.Plugin.LinkOpener", "IcoPath": "Images\\app.png",