Skip to content

Commit 4cd0891

Browse files
authored
Merge branch 'dev' into file_tooltip
2 parents 4e4707a + 86ca41a commit 4cd0891

File tree

9 files changed

+192
-87
lines changed

9 files changed

+192
-87
lines changed

Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Microsoft.Win32;
2-
using System;
1+
using System;
2+
using System.ComponentModel;
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using Microsoft.Win32;
67

78
namespace Flow.Launcher.Plugin.SharedCommands
89
{
@@ -13,7 +14,7 @@ public static class SearchWeb
1314
{
1415
private static string GetDefaultBrowserPath()
1516
{
16-
string name = string.Empty;
17+
var name = string.Empty;
1718
try
1819
{
1920
using var regDefault = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
@@ -23,8 +24,7 @@ private static string GetDefaultBrowserPath()
2324
name = regKey.GetValue(null).ToString().ToLower().Replace("\"", "");
2425

2526
if (!name.EndsWith("exe"))
26-
name = name.Substring(0, name.LastIndexOf(".exe") + 4);
27-
27+
name = name[..(name.LastIndexOf(".exe") + 4)];
2828
}
2929
catch
3030
{
@@ -65,12 +65,21 @@ public static void OpenInBrowserWindow(this string url, string browserPath = "",
6565
{
6666
Process.Start(psi)?.Dispose();
6767
}
68-
catch (System.ComponentModel.Win32Exception)
68+
// This error may be thrown if browser path is incorrect
69+
catch (Win32Exception)
6970
{
70-
Process.Start(new ProcessStartInfo
71+
try
72+
{
73+
Process.Start(new ProcessStartInfo
74+
{
75+
FileName = url,
76+
UseShellExecute = true
77+
});
78+
}
79+
catch
7180
{
72-
FileName = url, UseShellExecute = true
73-
});
81+
throw; // Re-throw the exception if we cannot open the URL in the default browser
82+
}
7483
}
7584
}
7685

@@ -100,12 +109,20 @@ public static void OpenInBrowserTab(this string url, string browserPath = "", bo
100109
Process.Start(psi)?.Dispose();
101110
}
102111
// This error may be thrown if browser path is incorrect
103-
catch (System.ComponentModel.Win32Exception)
112+
catch (Win32Exception)
104113
{
105-
Process.Start(new ProcessStartInfo
114+
try
115+
{
116+
Process.Start(new ProcessStartInfo
117+
{
118+
FileName = url,
119+
UseShellExecute = true
120+
});
121+
}
122+
catch
106123
{
107-
FileName = url, UseShellExecute = true
108-
});
124+
throw; // Re-throw the exception if we cannot open the URL in the default browser
125+
}
109126
}
110127
}
111128
}

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@
473473
</system:String>
474474
<system:String x:Key="errorTitle">Error</system:String>
475475
<system:String x:Key="folderOpenError">An error occurred while opening the folder. {0}</system:String>
476+
<system:String x:Key="browserOpenError">An error occurred while opening the URL in the browser. Please check your Default Web Browser configuration in the General section of the settings window</system:String>
476477

477478
<!-- General Notice -->
478479
<system:String x:Key="pleaseWait">Please wait...</system:String>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,27 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
399399

400400
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
401401

402-
if (browserInfo.OpenInTab)
402+
try
403403
{
404-
uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
404+
if (browserInfo.OpenInTab)
405+
{
406+
uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
407+
}
408+
else
409+
{
410+
uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
411+
}
405412
}
406-
else
413+
catch (Exception e)
407414
{
408-
uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
415+
var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window";
416+
LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e);
417+
ShowMsgBox(
418+
GetTranslation("browserOpenError"),
419+
GetTranslation("errorTitle"),
420+
MessageBoxButton.OK,
421+
MessageBoxImage.Error
422+
);
409423
}
410424
}
411425
else

Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
24
using System.IO;
35
using System.Text.Json;
4-
using System;
6+
using System.Threading.Tasks;
57
using Flow.Launcher.Plugin.BrowserBookmark.Models;
68
using Microsoft.Data.Sqlite;
79

@@ -43,16 +45,23 @@ protected List<Bookmark> LoadBookmarks(string browserDataPath, string name)
4345
catch (Exception ex)
4446
{
4547
Main._context.API.LogException(ClassName, $"Failed to register bookmark file monitoring: {bookmarkPath}", ex);
48+
continue;
4649
}
4750

4851
var source = name + (Path.GetFileName(profile) == "Default" ? "" : $" ({Path.GetFileName(profile)})");
4952
var profileBookmarks = LoadBookmarksFromFile(bookmarkPath, source);
5053

5154
// Load favicons after loading bookmarks
52-
var faviconDbPath = Path.Combine(profile, "Favicons");
53-
if (File.Exists(faviconDbPath))
55+
if (Main._settings.EnableFavicons)
5456
{
55-
LoadFaviconsFromDb(faviconDbPath, profileBookmarks);
57+
var faviconDbPath = Path.Combine(profile, "Favicons");
58+
if (File.Exists(faviconDbPath))
59+
{
60+
Main._context.API.StopwatchLogInfo(ClassName, $"Load {profileBookmarks.Count} favicons cost", () =>
61+
{
62+
LoadFaviconsFromDb(faviconDbPath, profileBookmarks);
63+
});
64+
}
5665
}
5766

5867
bookmarks.AddRange(profileBookmarks);
@@ -148,19 +157,24 @@ private void LoadFaviconsFromDb(string dbPath, List<Bookmark> bookmarks)
148157

149158
try
150159
{
151-
using var connection = new SqliteConnection($"Data Source={tempDbPath}");
152-
connection.Open();
160+
// Since some bookmarks may have same favicon id, we need to record them to avoid duplicates
161+
var savedPaths = new ConcurrentDictionary<string, bool>();
153162

154-
foreach (var bookmark in bookmarks)
163+
// Get favicons based on bookmarks concurrently
164+
Parallel.ForEach(bookmarks, bookmark =>
155165
{
166+
// Use read-only connection to avoid locking issues
167+
var connection = new SqliteConnection($"Data Source={tempDbPath};Mode=ReadOnly");
168+
connection.Open();
169+
156170
try
157171
{
158172
var url = bookmark.Url;
159-
if (string.IsNullOrEmpty(url)) continue;
173+
if (string.IsNullOrEmpty(url)) return;
160174

161175
// Extract domain from URL
162176
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
163-
continue;
177+
return;
164178

165179
var domain = uri.Host;
166180

@@ -178,28 +192,36 @@ ORDER BY b.width DESC
178192

179193
using var reader = cmd.ExecuteReader();
180194
if (!reader.Read() || reader.IsDBNull(1))
181-
continue;
195+
return;
182196

183197
var iconId = reader.GetInt64(0).ToString();
184198
var imageData = (byte[])reader["image_data"];
185199

186200
if (imageData is not { Length: > 0 })
187-
continue;
201+
return;
188202

189203
var faviconPath = Path.Combine(_faviconCacheDir, $"chromium_{domain}_{iconId}.png");
190-
SaveBitmapData(imageData, faviconPath);
204+
205+
// Filter out duplicate favicons
206+
if (savedPaths.TryAdd(faviconPath, true))
207+
{
208+
SaveBitmapData(imageData, faviconPath);
209+
}
191210

192211
bookmark.FaviconPath = faviconPath;
193212
}
194213
catch (Exception ex)
195214
{
196215
Main._context.API.LogException(ClassName, $"Failed to extract bookmark favicon: {bookmark.Url}", ex);
197216
}
198-
}
199-
200-
// https://github.com/dotnet/efcore/issues/26580
201-
SqliteConnection.ClearPool(connection);
202-
connection.Close();
217+
finally
218+
{
219+
// https://github.com/dotnet/efcore/issues/26580
220+
SqliteConnection.ClearPool(connection);
221+
connection.Close();
222+
connection.Dispose();
223+
}
224+
});
203225
}
204226
catch (Exception ex)
205227
{

0 commit comments

Comments
 (0)