mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Resolved: several issues reported in PR
This commit is contained in:
parent
9d27bcf589
commit
736e3764e1
4 changed files with 38 additions and 47 deletions
|
|
@ -1,10 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Xml.Linq;
|
||||
using static Flow.Launcher.Plugin.BrowserBookmark.Main;
|
||||
|
||||
namespace Flow.Launcher.Plugin.BrowserBookmark.Tabs;
|
||||
|
|
|
|||
|
|
@ -83,16 +83,17 @@ public class TabsTracker : IDisposable
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_focusHandler != null)
|
||||
{
|
||||
Automation.RemoveAutomationFocusChangedEventHandler(_focusHandler);
|
||||
_focusHandler = null;
|
||||
}
|
||||
var windowsToUnsubscribe = _browserWindowsTracked.ToList();
|
||||
foreach (var wnd in windowsToUnsubscribe)
|
||||
{
|
||||
UnsubscribeStructureChangedForWindow(wnd);
|
||||
}
|
||||
if (_focusHandler != null)
|
||||
{
|
||||
Automation.RemoveAutomationFocusChangedEventHandler(_focusHandler);
|
||||
_focusHandler = null;
|
||||
_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExpectUrl(string url)
|
||||
|
|
@ -145,44 +146,37 @@ public class TabsTracker : IDisposable
|
|||
return;
|
||||
|
||||
int pid = element.Current.ProcessId;
|
||||
try
|
||||
{
|
||||
using var process = Process.GetProcessById(pid);
|
||||
var chromium = chromiumProcessNames.Contains(process.ProcessName);
|
||||
var firefox = firefoxProcessNames.Contains(process.ProcessName);
|
||||
if (!chromium && !firefox)
|
||||
return; // not a browser
|
||||
using var process = Process.GetProcessById(pid);
|
||||
|
||||
Context.API.LogDebug(ClassName, $"The active browser is {process.ProcessName}");
|
||||
var chromium = chromiumProcessNames.Contains(process.ProcessName);
|
||||
var firefox = firefoxProcessNames.Contains(process.ProcessName);
|
||||
if (!chromium && !firefox)
|
||||
return; // not a browser
|
||||
|
||||
var rootElement = AutomationElement.FromHandle(process.MainWindowHandle);
|
||||
if (rootElement == null)
|
||||
return;
|
||||
Context.API.LogDebug(ClassName, $"The active browser is {process.ProcessName}");
|
||||
|
||||
Context.API.LogDebug(ClassName, $"The root element is {rootElement.Current.Name}");
|
||||
|
||||
var currentTab = _walker.GetCurrentTabFromWindow(rootElement, process, CancellationToken.None);
|
||||
if (currentTab != null)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
Context.API.LogDebug(ClassName, $"Registering {urlToBind} as tab: {currentTab.Title}");
|
||||
UrlToBrowserTab[urlToBind] = currentTab;
|
||||
_expectedUrl = null;
|
||||
|
||||
// required to take the tab into account by Flow Launcher main UI search window
|
||||
Context.API.ReQuery();
|
||||
}
|
||||
|
||||
Automation.AddStructureChangedEventHandler(rootElement, TreeScope.Subtree, OnStructureChanged);
|
||||
Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, rootElement, TreeScope.Subtree, OnWindowClosed);
|
||||
_browserWindowsTracked.Add(rootElement);
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// No such process / not running
|
||||
var rootElement = AutomationElement.FromHandle(process.MainWindowHandle);
|
||||
if (rootElement == null)
|
||||
return;
|
||||
|
||||
Context.API.LogDebug(ClassName, $"The root element is {rootElement.Current.Name}");
|
||||
|
||||
var currentTab = _walker.GetCurrentTabFromWindow(rootElement, process, CancellationToken.None);
|
||||
if (currentTab != null)
|
||||
{
|
||||
lock (_sync)
|
||||
{
|
||||
Context.API.LogDebug(ClassName, $"Registering {urlToBind} as tab: {currentTab.Title}");
|
||||
UrlToBrowserTab[urlToBind] = currentTab;
|
||||
_expectedUrl = null;
|
||||
|
||||
// required to take the tab into account by Flow Launcher main UI search window
|
||||
Context.API.ReQuery();
|
||||
}
|
||||
|
||||
Automation.AddStructureChangedEventHandler(rootElement, TreeScope.Subtree, OnStructureChanged);
|
||||
Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, rootElement, TreeScope.Subtree, OnWindowClosed);
|
||||
_browserWindowsTracked.Add(rootElement);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Automation;
|
||||
using BrowserTabs;
|
||||
using static Flow.Launcher.Plugin.BrowserBookmark.Main;
|
||||
|
|
@ -67,7 +68,7 @@ internal class TabsWalker
|
|||
if (tabs.Count == 0)
|
||||
{
|
||||
Context.API.LogDebug(ClassName, "No valid tabs found");
|
||||
Thread.Sleep(_tabRetryInterval);
|
||||
Task.Delay(_tabRetryInterval, cancellationToken);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ internal class TabsWalker
|
|||
}
|
||||
|
||||
Context.API.LogDebug(ClassName, "No new tab found");
|
||||
Thread.Sleep(_tabRetryInterval);
|
||||
Task.Delay(_tabRetryInterval, cancellationToken);
|
||||
}
|
||||
|
||||
Context.API.LogDebug(ClassName, "Timeout waiting for new tab");
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public partial class SettingsControl
|
|||
set
|
||||
{
|
||||
Settings.ReuseTabs = value;
|
||||
_ = Task.Run(() => Main.ReloadAllBookmarks());
|
||||
// reloading of bookmarks is not needed while this settings changes
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue