-
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathTabsCache.cs
More file actions
51 lines (44 loc) · 1.15 KB
/
TabsCache.cs
File metadata and controls
51 lines (44 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
using System.Windows.Automation;
namespace Flow.Launcher.Plugin.BrowserBookmark.Tabs;
/// <summary>
/// Keeps record of all known browser's tabs.
/// It is used by TabsWalker to identify new tabs as they appear.
/// </summary>
internal class TabsCache
{
private readonly HashSet<string> _knownTabs = new();
private readonly object sync = new();
private static string RuntimeIdToKey(AutomationElement elem) => elem != null ? string.Join("-", elem.GetRuntimeId()) : "NULL";
public bool Empty()
{
lock (sync)
{
return _knownTabs.Count == 0;
}
}
public void Add(AutomationElement tab)
{
lock (sync)
{
_knownTabs.Add(RuntimeIdToKey(tab));
}
}
public void Add(IEnumerable<AutomationElement> tabs)
{
lock (sync)
{
foreach (var tab in tabs)
{
_knownTabs.Add(RuntimeIdToKey(tab));
}
}
}
public bool Contains(AutomationElement tab)
{
lock (sync)
{
return _knownTabs.Contains(RuntimeIdToKey(tab));
}
}
}