diff --git a/Sources/MicSwitch/MainWindow/ViewModels/MainWindowViewModel.cs b/Sources/MicSwitch/MainWindow/ViewModels/MainWindowViewModel.cs index 3058be6..e6bd583 100644 --- a/Sources/MicSwitch/MainWindow/ViewModels/MainWindowViewModel.cs +++ b/Sources/MicSwitch/MainWindow/ViewModels/MainWindowViewModel.cs @@ -26,6 +26,7 @@ using PoeShared.Scaffolding; using PoeShared.Scaffolding.WPF; using PoeShared.Services; +using PoeShared.UI.Models; using Prism.Commands; using ReactiveUI; using Unity.Attributes; @@ -56,6 +57,7 @@ internal class MainWindowViewModel : DisposableReactiveObject private WindowState windowState; public MainWindowViewModel( + [NotNull] IViewController viewController, [NotNull] AppArguments appArguments, [NotNull] IKeyboardEventsSource eventSource, [NotNull] IFactory startupManagerFactory, @@ -251,11 +253,12 @@ [NotNull] [Dependency(WellKnownWindows.MainWindow)] IWindowTracker mainWindowTra }, Log.HandleException) .AddTo(Anchors); - System.Windows.Forms.Application.Idle += delegate + viewController.Loaded.Take(1).Subscribe(() => { Log.Debug("Initializing keyboard & mouse event source"); eventSource.InitializeHooks().AddTo(Anchors); - }; + }).AddTo(Anchors); + } private async Task RunAtLoginCommandExecuted(bool runAtLogin) diff --git a/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml b/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml index 6ed0f1c..c7ac154 100644 --- a/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml +++ b/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml @@ -18,6 +18,8 @@ ResizeMode="CanMinimize" WindowStyle="SingleBorderWindow" ShowInTaskbar="{Binding ShowInTaskbar, Mode=TwoWay}" + Loaded="OnLoaded" + Unloaded="OnUnloaded" Title="{Binding Title}" Width="400" SizeToContent="Height"> diff --git a/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs b/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs index 3b1eaf7..531c7e2 100644 --- a/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs +++ b/Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Windows; using Common.Logging; using MicSwitch.MainWindow.Models; using MicSwitch.MainWindow.ViewModels; @@ -9,8 +10,11 @@ using PoeShared.Native; using PoeShared.Prism; using PoeShared.Scaffolding; +using PoeShared.UI.Models; using Unity; +using Unity.Injection; using Unity.Lifetime; +using Unity.Resolution; namespace MicSwitch.MainWindow.Views { @@ -26,9 +30,11 @@ public partial class MainWindow public MainWindow() { Log.Debug($"Initializing MainWindow for process {AppArguments.Instance.ProcessId}"); + var sw = Stopwatch.StartNew(); InitializeComponent(); Log.Debug($"BAML loaded in {sw.ElapsedMilliseconds:F0}ms"); + var viewController = new ViewController(this); sw.Restart(); container.RegisterInstance(AppArguments.Instance, new ContainerControlledLifetimeManager()); @@ -49,7 +55,7 @@ public MainWindow() Log.Debug($"Registrations took {sw.ElapsedMilliseconds:F0}ms"); sw.Restart(); - DataContext = container.Resolve(); + DataContext = container.Resolve(new DependencyOverride(viewController)); Log.Debug($"MainWindow resolved in {sw.ElapsedMilliseconds:F0}ms"); sw.Restart(); @@ -66,5 +72,15 @@ public MainWindow() overlayController.RegisterChild(overlayViewModel); Log.Debug($"Overlays loaded in {sw.ElapsedMilliseconds:F0}ms"); } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + Log.Debug($"MainWindow unloaded"); + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + Log.Debug($"MainWindow loaded"); + } } } \ No newline at end of file diff --git a/Submodules/PoeEye b/Submodules/PoeEye index fce95b4..48d3610 160000 --- a/Submodules/PoeEye +++ b/Submodules/PoeEye @@ -1 +1 @@ -Subproject commit fce95b47b9c7ef0c254c2d78ed9bb6976113461a +Subproject commit 48d3610c25a7ed08bb0c9fc34ff60dac4dfa4889