Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
FIxed startup lag
Browse files Browse the repository at this point in the history
  • Loading branch information
iXab3r committed Mar 30, 2019
1 parent cffb5f1 commit 411cf66
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ internal class MainWindowViewModel : DisposableReactiveObject
private WindowState windowState;

public MainWindowViewModel(
[NotNull] IViewController viewController,
[NotNull] AppArguments appArguments,
[NotNull] IKeyboardEventsSource eventSource,
[NotNull] IFactory<IStartupManager, StartupManagerArgs> startupManagerFactory,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/MicSwitch/MainWindow/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
ResizeMode="CanMinimize"
WindowStyle="SingleBorderWindow"
ShowInTaskbar="{Binding ShowInTaskbar, Mode=TwoWay}"
Loaded="OnLoaded"
Unloaded="OnUnloaded"
Title="{Binding Title}" Width="400" SizeToContent="Height">

<Grid>
Expand Down
18 changes: 17 additions & 1 deletion Sources/MicSwitch/MainWindow/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Windows;
using Common.Logging;
using MicSwitch.MainWindow.Models;
using MicSwitch.MainWindow.ViewModels;
Expand All @@ -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
{
Expand All @@ -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());
Expand All @@ -49,7 +55,7 @@ public MainWindow()
Log.Debug($"Registrations took {sw.ElapsedMilliseconds:F0}ms");
sw.Restart();

DataContext = container.Resolve<MainWindowViewModel>();
DataContext = container.Resolve<MainWindowViewModel>(new DependencyOverride<IViewController>(viewController));
Log.Debug($"MainWindow resolved in {sw.ElapsedMilliseconds:F0}ms");
sw.Restart();

Expand All @@ -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");
}
}
}

0 comments on commit 411cf66

Please sign in to comment.