Skip to content

Commit

Permalink
Update DynamoView.xaml.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Feb 26, 2024
1 parent ed5376f commit 4353d2e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
Expand Down Expand Up @@ -73,6 +74,12 @@ public partial class DynamoView : Window, IDisposable
private double restoreWidth = 0;
private DynamoViewModel dynamoViewModel;
private readonly Stopwatch _timer;

#region Open Workspace performance tools
private static int idleCounter;
private Stopwatch WorkspaceRenderedTimer;
#endregion

private StartPageViewModel startPage;
private int tabSlidingWindowStart, tabSlidingWindowEnd;
private readonly LoginService loginService;
Expand Down Expand Up @@ -245,6 +252,7 @@ public DynamoView(DynamoViewModel dynamoViewModel)
this.dynamoViewModel.RequestCloseHomeWorkSpace += OnRequestCloseHomeWorkSpace;
this.dynamoViewModel.RequestReturnFocusToView += OnRequestReturnFocusToView;
this.dynamoViewModel.Model.WorkspaceSaving += OnWorkspaceSaving;
this.dynamoViewModel.Model.WorkspaceOpening += OnWorkspaceOpening;
this.dynamoViewModel.Model.WorkspaceOpened += OnWorkspaceOpened;
this.dynamoViewModel.Model.WorkspaceAdded += OnWorkspaceAdded;
this.dynamoViewModel.Model.WorkspaceHidden += OnWorkspaceHidden;
Expand All @@ -265,6 +273,12 @@ public DynamoView(DynamoViewModel dynamoViewModel)
DefaultMinWidth = MinWidth;
}

private void OnWorkspaceOpening(object obj)
{
WorkspaceRenderedTimer ??= Stopwatch.StartNew();
WorkspaceRenderedTimer.Start();
}

private void OnRequestCloseHomeWorkSpace()
{
CalculateWindowMinWidth();
Expand Down Expand Up @@ -362,7 +376,24 @@ private void OnWorkspaceOpened(WorkspaceModel workspace)
foreach (var extension in viewExtensionManager.StorageAccessViewExtensions)
{
DynamoModel.RaiseIExtensionStorageAccessWorkspaceOpened(hws, extension, dynamoViewModel.Model.Logger);
}
}

void Hooks_DispatcherInactive(object sender, EventArgs e)
{
if (idleCounter < 10)
{
Interlocked.Increment(ref idleCounter);
return;
}

Interlocked.Exchange(ref idleCounter, 0);
dynamoViewModel.Model.Logger.Log($"Opened workspace found at {workspace.FileName} in {WorkspaceRenderedTimer.Elapsed}");
WorkspaceRenderedTimer.Reset();

Dispatcher.Hooks.DispatcherInactive -= Hooks_DispatcherInactive;
}

Dispatcher.Hooks.DispatcherInactive += Hooks_DispatcherInactive;
}

private void OnWorkspaceSaving(WorkspaceModel workspace, Graph.SaveContext saveContext)
Expand Down Expand Up @@ -2015,6 +2046,7 @@ private void WindowClosed(object sender, EventArgs e)
this.dynamoViewModel.RequestCloseHomeWorkSpace -= OnRequestCloseHomeWorkSpace;
this.dynamoViewModel.RequestReturnFocusToView -= OnRequestReturnFocusToView;
this.dynamoViewModel.Model.WorkspaceSaving -= OnWorkspaceSaving;
this.dynamoViewModel.Model.WorkspaceOpening -= OnWorkspaceOpening;
this.dynamoViewModel.Model.WorkspaceOpened -= OnWorkspaceOpened;
this.dynamoViewModel.Model.WorkspaceAdded -= OnWorkspaceAdded;
this.dynamoViewModel.Model.WorkspaceHidden -= OnWorkspaceHidden;
Expand Down

0 comments on commit 4353d2e

Please sign in to comment.