diff --git a/Core/TabManager.cs b/Core/TabManager.cs index 9a289be..ca4e7ea 100644 --- a/Core/TabManager.cs +++ b/Core/TabManager.cs @@ -45,6 +45,7 @@ public sealed class TabManager : IAsyncDisposable public bool IsMinimizedMode => _minimizedMode; public bool ExtensionsAvailable { get; private set; } public bool SessionReady { get; private set; } + public bool IsElementPickerActive { get; private set; } public CoreWebView2Environment Environment => _environment; public WebView2 View => _view; public ExtensionManager? ExtensionManager { get; private set; } @@ -137,6 +138,7 @@ public sealed class TabManager : IAsyncDisposable try { if (ActiveTab is not null) await CaptureActiveStateAsync(); + IsElementPickerActive = false; ActiveTab = tab; _audioOnly = tab.IsAudioOnly; ActiveTabStateChanged?.Invoke(this, EventArgs.Empty); @@ -212,6 +214,15 @@ public sealed class TabManager : IAsyncDisposable public async Task StartElementPickerAsync() { if (_view.CoreWebView2 is null || ActiveTab is null) return; + if (IsElementPickerActive) + { + await _view.CoreWebView2.ExecuteScriptAsync("window.__foxElementPicker?.();"); + IsElementPickerActive = false; + ActiveTabStateChanged?.Invoke(this, EventArgs.Empty); + return; + } + IsElementPickerActive = true; + ActiveTabStateChanged?.Invoke(this, EventArgs.Empty); await _view.CoreWebView2.ExecuteScriptAsync(""" (()=>{ if(window.__foxElementPicker){window.__foxElementPicker();return;} @@ -369,7 +380,9 @@ public sealed class TabManager : IAsyncDisposable if (!_blockedElements.TryGetValue(host, out var selectors)) _blockedElements[host] = selectors = new List(); if (!selectors.Contains(selector, StringComparer.Ordinal)) selectors.Add(selector); + IsElementPickerActive = false; SaveBlockedElements(); + ActiveTabStateChanged?.Invoke(this, EventArgs.Empty); _ = ApplyBlockedElementsAsync(); } catch (JsonException) { } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 43d9777..b56bd6d 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -147,10 +147,15 @@ public partial class MainWindow : Window if (startupNotice is not null) System.Windows.MessageBox.Show(this, startupNotice, "FoxBrowser", MessageBoxButton.OK, MessageBoxImage.Information); _tabManager = new TabManager(WebViewHost, environment, !recoveryMode); - _tabManager.ActiveTabStateChanged += (_, _) => Dispatcher.Invoke(RefreshAddressBar); + _tabManager.ActiveTabStateChanged += (_, _) => Dispatcher.Invoke(() => + { + RefreshAddressBar(); + RefreshModeIndicators(); + }); DataContext = _tabManager; await _tabManager.InitializeAsync(); TabStrip.SelectedItem = _tabManager.ActiveTab; + RefreshModeIndicators(); var iconPath = ResolveAppIconPath(_appSettings); try { @@ -202,6 +207,7 @@ public partial class MainWindow : Window if (_tabManager is null) return; await _tabManager.ToggleDarkModeAsync(); TabStrip.Items.Refresh(); + RefreshModeIndicators(); } private void DarkMode_RightClick(object sender, MouseButtonEventArgs e) @@ -215,6 +221,7 @@ public partial class MainWindow : Window BlockedElementsPopup.IsOpen = false; if (_tabManager is null) return; await _tabManager.StartElementPickerAsync(); + RefreshModeIndicators(); } private void ElementPicker_RightClick(object sender, MouseButtonEventArgs e) @@ -336,6 +343,7 @@ public partial class MainWindow : Window AddressBox.Text = tab.Address; await _tabManager.SwitchToTabAsync(tab); RefreshAddressBar(); + RefreshModeIndicators(); } private async void CloseTab_Click(object sender, RoutedEventArgs e) @@ -398,4 +406,27 @@ public partial class MainWindow : Window AddressBox.Text = _tabManager.ActiveTab.Address; } } + + private void RefreshModeIndicators() + { + if (!IsInitialized) return; + var darkActive = _tabManager?.ActiveTab?.IsDarkMode == true; + var pickerActive = _tabManager?.IsElementPickerActive == true; + var activeBackground = (System.Windows.Media.Brush)FindResource("AurBlueSoft"); + var activeBorder = (System.Windows.Media.Brush)FindResource("AurBlue"); + var inactiveBackground = (System.Windows.Media.Brush)FindResource("CardBg"); + var inactiveBorder = (System.Windows.Media.Brush)FindResource("BorderMedium"); + + DarkModeButton.Background = darkActive ? activeBackground : inactiveBackground; + DarkModeButton.BorderBrush = darkActive ? activeBorder : inactiveBorder; + DarkModeButton.Foreground = darkActive + ? (System.Windows.Media.Brush)FindResource("TextPrimary") + : (System.Windows.Media.Brush)FindResource("TextSecondary"); + + ElementPickerButton.Background = pickerActive ? activeBackground : inactiveBackground; + ElementPickerButton.BorderBrush = pickerActive ? activeBorder : inactiveBorder; + ElementPickerButton.Foreground = pickerActive + ? (System.Windows.Media.Brush)FindResource("TextPrimary") + : (System.Windows.Media.Brush)FindResource("TextSecondary"); + } }