Skip to content

Commit d0289b4

Browse files
Refactor file watcher logic
* Remove LastAccessed filter to avoid unwanted recursive RegisterBookmarkFile() calls * Check if watcher exists
1 parent c55edca commit d0289b4

File tree

1 file changed

+9
-7
lines changed
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,19 @@ private async Task MonitorRefreshQueue()
106106
internal static void RegisterBookmarkFile(string path)
107107
{
108108
var directory = Path.GetDirectoryName(path);
109-
if (!Directory.Exists(directory))
109+
if (!Directory.Exists(directory) || !File.Exists(path))
110+
{
110111
return;
111-
var watcher = new FileSystemWatcher(directory!);
112-
if (File.Exists(path))
112+
}
113+
if (Watchers.Any(x => x.Path.Equals(directory, StringComparison.OrdinalIgnoreCase)))
113114
{
114-
var fileName = Path.GetFileName(path);
115-
watcher.Filter = fileName;
115+
return;
116116
}
117+
118+
var watcher = new FileSystemWatcher(directory!);
119+
watcher.Filter = Path.GetFileName(path);
117120

118121
watcher.NotifyFilter = NotifyFilters.FileName |
119-
NotifyFilters.LastAccess |
120122
NotifyFilters.LastWrite |
121123
NotifyFilters.Size;
122124

@@ -131,7 +133,7 @@ internal static void RegisterBookmarkFile(string path)
131133
};
132134

133135
watcher.EnableRaisingEvents = true;
134-
136+
135137
Watchers.Add(watcher);
136138
}
137139

0 commit comments

Comments
 (0)