From 2aca5a3980f3ad49c96d2f069e2e1f9d95269404 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 15 Nov 2024 00:01:40 -0600 Subject: [PATCH 1/2] Manage DictionaryManager like other singletons --- RetroBar/App.xaml.cs | 13 ++++++------- RetroBar/Taskbar.xaml.cs | 10 ++++++---- RetroBar/Utilities/WindowManager.cs | 6 ++++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/RetroBar/App.xaml.cs b/RetroBar/App.xaml.cs index d636ac99..2f73cabe 100644 --- a/RetroBar/App.xaml.cs +++ b/RetroBar/App.xaml.cs @@ -20,9 +20,8 @@ namespace RetroBar /// public partial class App : Application { - public DictionaryManager DictionaryManager { get; } - private bool _errorVisible; + private DictionaryManager _dictionaryManager; private ManagedShellLogger _logger; private WindowManager _windowManager; @@ -35,7 +34,7 @@ public App() _shellManager = SetupManagedShell(); _startMenuMonitor = new StartMenuMonitor(new AppVisibilityHelper(false)); - DictionaryManager = new DictionaryManager(); + _dictionaryManager = new DictionaryManager(); _updater = new Updater(); Settings.Instance.PropertyChanged += Settings_PropertyChanged; @@ -54,9 +53,9 @@ private void App_OnStartup(object sender, StartupEventArgs e) RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } - DictionaryManager.SetLanguageFromSettings(); + _dictionaryManager.SetLanguageFromSettings(); loadTheme(); - _windowManager = new WindowManager(_shellManager, _startMenuMonitor, _updater); + _windowManager = new WindowManager(_dictionaryManager, _shellManager, _startMenuMonitor, _updater); } private void App_OnExit(object sender, ExitEventArgs e) @@ -90,7 +89,7 @@ private void Settings_PropertyChanged(object sender, System.ComponentModel.Prope private void loadTheme() { - DictionaryManager.SetThemeFromSettings(); + _dictionaryManager.SetThemeFromSettings(); setTaskIconSize(); } @@ -137,7 +136,7 @@ private void ExitApp() Settings.Instance.PropertyChanged -= Settings_PropertyChanged; _windowManager.Dispose(); - DictionaryManager.Dispose(); + _dictionaryManager.Dispose(); _shellManager.Dispose(); _startMenuMonitor.Dispose(); _updater.Dispose(); diff --git a/RetroBar/Taskbar.xaml.cs b/RetroBar/Taskbar.xaml.cs index cb989eec..37702d8a 100644 --- a/RetroBar/Taskbar.xaml.cs +++ b/RetroBar/Taskbar.xaml.cs @@ -53,14 +53,16 @@ public int Rows private LowLevelMouseHook _mouseDragHook; private Point? _mouseDragStart = null; private bool _mouseDragResize = false; + private DictionaryManager _dictionaryManager; private ShellManager _shellManager; private Updater _updater; public WindowManager windowManager; - public Taskbar(WindowManager windowManager, ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater, AppBarScreen screen, AppBarEdge edge, AppBarMode mode) + public Taskbar(WindowManager windowManager, DictionaryManager dictionaryManager, ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater, AppBarScreen screen, AppBarEdge edge, AppBarMode mode) : base(shellManager.AppBarManager, shellManager.ExplorerHelper, shellManager.FullScreenHelper, screen, edge, mode, 0) { + _dictionaryManager = dictionaryManager; _shellManager = shellManager; _updater = updater; this.windowManager = windowManager; @@ -136,7 +138,7 @@ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP handled = true; // If the color scheme changes, re-apply the current theme to get updated colors. - ((App)Application.Current).DictionaryManager.SetThemeFromSettings(); + _dictionaryManager.SetThemeFromSettings(); } return IntPtr.Zero; @@ -314,7 +316,7 @@ private void DateTimeMenuItem_OnClick(object sender, RoutedEventArgs e) private void CustomizeNotificationsMenuItem_OnClick(object sender, RoutedEventArgs e) { - PropertiesWindow propWindow = PropertiesWindow.Open(_shellManager.NotificationArea, ((App)Application.Current).DictionaryManager, Screen, DpiScale, Orientation == Orientation.Horizontal ? DesiredHeight : DesiredWidth); + PropertiesWindow propWindow = PropertiesWindow.Open(_shellManager.NotificationArea, _dictionaryManager, Screen, DpiScale, Orientation == Orientation.Horizontal ? DesiredHeight : DesiredWidth); propWindow.OpenCustomizeNotifications(); } @@ -336,7 +338,7 @@ private void UpdateAvailableMenuItem_OnClick(object sender, RoutedEventArgs e) private void PropertiesMenuItem_OnClick(object sender, RoutedEventArgs e) { - PropertiesWindow.Open(_shellManager.NotificationArea, ((App)Application.Current).DictionaryManager, Screen, DpiScale, Orientation == Orientation.Horizontal ? DesiredHeight : DesiredWidth); + PropertiesWindow.Open(_shellManager.NotificationArea, _dictionaryManager, Screen, DpiScale, Orientation == Orientation.Horizontal ? DesiredHeight : DesiredWidth); } private void ExitMenuItem_OnClick(object sender, RoutedEventArgs e) diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index 90215133..a85b0c59 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -14,14 +14,16 @@ public class WindowManager : IDisposable private List _screenState = new List(); private List _taskbars = new List(); + private readonly DictionaryManager _dictionaryManager; private readonly StartMenuMonitor _startMenuMonitor; private readonly ShellManager _shellManager; private readonly Updater _updater; private readonly ExplorerMonitor _explorerMonitor = new(); - public WindowManager(ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater) + public WindowManager(DictionaryManager dictionaryManager, ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater) { + _dictionaryManager = dictionaryManager; _shellManager = shellManager; _startMenuMonitor = startMenuMonitor; _updater = updater; @@ -142,7 +144,7 @@ private void openTaskbars() private void openTaskbar(AppBarScreen screen) { ShellLogger.Debug($"WindowManager: Opening taskbar on screen {screen.DeviceName}"); - Taskbar taskbar = new Taskbar(this, _shellManager, _startMenuMonitor, _updater, screen, Settings.Instance.Edge, Settings.Instance.AutoHide ? AppBarMode.AutoHide : AppBarMode.Normal); + Taskbar taskbar = new Taskbar(this, _dictionaryManager, _shellManager, _startMenuMonitor, _updater, screen, Settings.Instance.Edge, Settings.Instance.AutoHide ? AppBarMode.AutoHide : AppBarMode.Normal); taskbar.Show(); _taskbars.Add(taskbar); From 24715e77963a028f9fdc3c79739489bca84b617d Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 15 Nov 2024 21:35:01 -0600 Subject: [PATCH 2/2] Adjust ExplorerMonitor lifecycle --- RetroBar/App.xaml.cs | 9 ++++++--- RetroBar/Utilities/WindowManager.cs | 11 +++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/RetroBar/App.xaml.cs b/RetroBar/App.xaml.cs index 2f73cabe..adcf3cbe 100644 --- a/RetroBar/App.xaml.cs +++ b/RetroBar/App.xaml.cs @@ -21,18 +21,20 @@ namespace RetroBar public partial class App : Application { private bool _errorVisible; - private DictionaryManager _dictionaryManager; private ManagedShellLogger _logger; private WindowManager _windowManager; - private readonly StartMenuMonitor _startMenuMonitor; + private readonly DictionaryManager _dictionaryManager; + private readonly ExplorerMonitor _explorerMonitor; private readonly ShellManager _shellManager; + private readonly StartMenuMonitor _startMenuMonitor; private readonly Updater _updater; public App() { _shellManager = SetupManagedShell(); + _explorerMonitor = new ExplorerMonitor(); _startMenuMonitor = new StartMenuMonitor(new AppVisibilityHelper(false)); _dictionaryManager = new DictionaryManager(); _updater = new Updater(); @@ -55,7 +57,7 @@ private void App_OnStartup(object sender, StartupEventArgs e) _dictionaryManager.SetLanguageFromSettings(); loadTheme(); - _windowManager = new WindowManager(_dictionaryManager, _shellManager, _startMenuMonitor, _updater); + _windowManager = new WindowManager(_dictionaryManager, _explorerMonitor, _shellManager, _startMenuMonitor, _updater); } private void App_OnExit(object sender, ExitEventArgs e) @@ -135,6 +137,7 @@ private void ExitApp() { Settings.Instance.PropertyChanged -= Settings_PropertyChanged; + _explorerMonitor.Dispose(); _windowManager.Dispose(); _dictionaryManager.Dispose(); _shellManager.Dispose(); diff --git a/RetroBar/Utilities/WindowManager.cs b/RetroBar/Utilities/WindowManager.cs index a85b0c59..811001de 100644 --- a/RetroBar/Utilities/WindowManager.cs +++ b/RetroBar/Utilities/WindowManager.cs @@ -15,25 +15,25 @@ public class WindowManager : IDisposable private List _taskbars = new List(); private readonly DictionaryManager _dictionaryManager; + private readonly ExplorerMonitor _explorerMonitor; private readonly StartMenuMonitor _startMenuMonitor; private readonly ShellManager _shellManager; private readonly Updater _updater; - private readonly ExplorerMonitor _explorerMonitor = new(); - - public WindowManager(DictionaryManager dictionaryManager, ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater) + public WindowManager(DictionaryManager dictionaryManager, ExplorerMonitor explorerMonitor, ShellManager shellManager, StartMenuMonitor startMenuMonitor, Updater updater) { _dictionaryManager = dictionaryManager; + _explorerMonitor = explorerMonitor; _shellManager = shellManager; _startMenuMonitor = startMenuMonitor; _updater = updater; - _explorerMonitor.ExplorerMonitorStart(this); - _shellManager.ExplorerHelper.HideExplorerTaskbar = true; openTaskbars(); + _explorerMonitor.ExplorerMonitorStart(this); + Settings.Instance.PropertyChanged += Settings_PropertyChanged; } @@ -189,7 +189,6 @@ private void resetScreenCache() public void Dispose() { - _explorerMonitor?.Dispose(); _shellManager.ExplorerHelper.HideExplorerTaskbar = false; Settings.Instance.PropertyChanged -= Settings_PropertyChanged; }