Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent singleton init #951

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions RetroBar/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ namespace RetroBar
/// </summary>
public partial class App : Application
{
public DictionaryManager DictionaryManager { get; }

private bool _errorVisible;
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();
_dictionaryManager = new DictionaryManager();
_updater = new Updater();

Settings.Instance.PropertyChanged += Settings_PropertyChanged;
Expand All @@ -54,9 +55,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, _explorerMonitor, _shellManager, _startMenuMonitor, _updater);
}

private void App_OnExit(object sender, ExitEventArgs e)
Expand Down Expand Up @@ -90,7 +91,7 @@ private void Settings_PropertyChanged(object sender, System.ComponentModel.Prope

private void loadTheme()
{
DictionaryManager.SetThemeFromSettings();
_dictionaryManager.SetThemeFromSettings();
setTaskIconSize();
}

Expand Down Expand Up @@ -136,8 +137,9 @@ private void ExitApp()
{
Settings.Instance.PropertyChanged -= Settings_PropertyChanged;

_explorerMonitor.Dispose();
_windowManager.Dispose();
DictionaryManager.Dispose();
_dictionaryManager.Dispose();
_shellManager.Dispose();
_startMenuMonitor.Dispose();
_updater.Dispose();
Expand Down
10 changes: 6 additions & 4 deletions RetroBar/Taskbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand All @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions RetroBar/Utilities/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ public class WindowManager : IDisposable
private List<AppBarScreen> _screenState = new List<AppBarScreen>();
private List<Taskbar> _taskbars = new List<Taskbar>();

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(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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -187,7 +189,6 @@ private void resetScreenCache()

public void Dispose()
{
_explorerMonitor?.Dispose();
_shellManager.ExplorerHelper.HideExplorerTaskbar = false;
Settings.Instance.PropertyChanged -= Settings_PropertyChanged;
}
Expand Down