Skip to content

Commit

Permalink
DYN-8121 SplashScreen Disable Close Button
Browse files Browse the repository at this point in the history
Removing all the Dynamo code (including unit tests) that is used for the close SplashScreen functionality.
  • Loading branch information
RobertGlobant20 committed Jan 14, 2025
1 parent d1dd01f commit ccdfc35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 122 deletions.
78 changes: 2 additions & 76 deletions src/DynamoCoreWpf/Views/SplashScreen/SplashScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public DynamoView DynamoView
return;
}
viewModel = value.DataContext as DynamoViewModel;
// When view model is closed, we need to close the splash screen if it is displayed.
viewModel.RequestClose += SplashScreenRequestClose;
authManager = viewModel.Model.AuthenticationManager;
}
}
Expand Down Expand Up @@ -229,18 +227,6 @@ private void WebView_NavigationCompleted(object sender, CoreWebView2NavigationCo
}
}

/// <summary>
/// Request to close SplashScreen.
/// </summary>
private void SplashScreenRequestClose(object sender, EventArgs e)
{
//This is only called when shutdownparams.closeDynamoView = true
//which is during tests or an exit command
//which is used rarely, but it is used when the Revit document is lost and Dynamo is open.
CloseWindow();
viewModel.RequestClose -= SplashScreenRequestClose;
}

/// <summary>
/// Import setting file from chosen path
/// </summary>
Expand Down Expand Up @@ -399,7 +385,7 @@ protected override async void OnContentRendered(EventArgs e)

webView.NavigateToString(htmlString);
webView.CoreWebView2.AddHostObjectToScript("scriptObject",
new ScriptObject(RequestLaunchDynamo, RequestImportSettings, RequestSignIn, RequestSignOut, CloseWindow));
new ScriptObject(RequestLaunchDynamo, RequestImportSettings, RequestSignIn, RequestSignOut));
}
catch (ObjectDisposedException ex)
{
Expand Down Expand Up @@ -578,41 +564,6 @@ private static bool IsValidPreferencesFile(string filePath)
}
}

/// <summary>
/// If the user wants to close the window, we shutdown the application and don't launch Dynamo
/// </summary>
/// <param name="isCheckboxChecked">If true, the user has chosen to not show splash screen on next run.</param>
internal void CloseWindow(bool isCheckboxChecked = false)
{
CloseWasExplicit = true;
currentCloseMode = CloseMode.ByCloseButton;

if (viewModel != null && isCheckboxChecked)
{
viewModel.PreferenceSettings.EnableStaticSplashScreen = !isCheckboxChecked;
}

if (string.IsNullOrEmpty(DynamoModel.HostAnalyticsInfo.HostName))
{
Application.Current?.Shutdown();
Analytics.TrackEvent(Actions.Close, Categories.SplashScreenOperations);
}
// If Dynamo is launched from an integrator host, user should be able to close the splash screen window.
// Additionally, we will have to shutdown the ViewModel which will close all the services and dispose the events.
// RequestUpdateLoadBarStatus event needs to be unsubscribed when the splash screen window is closed, to avoid populating the info on splash screen.
else
{
Close();
if (viewModel != null)
{
viewModel.RequestClose -= SplashScreenRequestClose;
}

DynamoView?.Close();
DynamoView = null;
}
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Expand Down Expand Up @@ -653,31 +604,17 @@ public class ScriptObject
readonly Action<string> RequestImportSettings;
readonly Func<bool> RequestSignIn;
readonly Func<bool> RequestSignOut;
readonly Action RequestCloseWindow;
readonly Action<bool> RequestCloseWindowPreserve;

/// <summary>
/// [Obsolete] Constructor for ScriptObject
/// </summary>
[Obsolete]
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func< bool> requestSignIn, Func<bool> requestSignOut, Action requestCloseWindow)
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func< bool> requestSignIn, Func<bool> requestSignOut)
{
RequestLaunchDynamo = requestLaunchDynamo;
RequestImportSettings = requestImportSettings;
RequestSignIn = requestSignIn;
RequestSignOut = requestSignOut;
RequestCloseWindow = requestCloseWindow;
}
/// <summary>
/// Constructor for ScriptObject with an overload for close window method, to preserve "Don't show again" setting on splash screen on explicit close event.
/// </summary>
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func<bool> requestSignIn, Func<bool> requestSignOut, Action<bool> requestCloseWindow)
{
RequestLaunchDynamo = requestLaunchDynamo;
RequestImportSettings = requestImportSettings;
RequestSignIn = requestSignIn;
RequestSignOut = requestSignOut;
RequestCloseWindowPreserve = requestCloseWindow;
}
[DynamoJSInvokable]
public void LaunchDynamo(bool showScreenAgain)
Expand All @@ -700,16 +637,5 @@ public bool SignOut()
{
return RequestSignOut();
}
[Obsolete]
[DynamoJSInvokable]
public void CloseWindow()
{
RequestCloseWindow();
}
[DynamoJSInvokable]
public void CloseWindowPreserve(bool isCheckboxChecked)
{
RequestCloseWindowPreserve(isCheckboxChecked);
}
}
}
47 changes: 1 addition & 46 deletions test/DynamoCoreWpfTests/SplashScreenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
namespace DynamoCoreWpfTests
{

[TestFixture]
class SplashScreenViewTests: DynamoTestUIBase
{
[Test]
public void SplashScreen_ClosePersistSetsPrefs()
{
var ss = new Dynamo.UI.Views.SplashScreen();
ss.DynamoView = View;
var oldPref = ViewModel.PreferenceSettings.EnableStaticSplashScreen;
Assert.IsTrue(oldPref);

ss.CloseWindow(true);
var newPref = ViewModel.PreferenceSettings.EnableStaticSplashScreen;
Assert.False(newPref);

Assert.IsTrue(ss.CloseWasExplicit);
}
}

[TestFixture]
internal class SplashScreenTests
{
Expand Down Expand Up @@ -58,33 +39,7 @@ public void CleanUp()
{
TestUtilities.WebView2Tag = string.Empty;
}

[Test]
public void SplashScreen_CloseExplicitPropIsCorrect1()
{
var ss = new Dynamo.UI.Views.SplashScreen();
ss.RequestLaunchDynamo(true);
Assert.IsFalse(ss.CloseWasExplicit);

ss.CloseWindow();
}

[Test]
public void SplashScreen_CloseExplicitPropIsCorrect2()
{
var ss = new Dynamo.UI.Views.SplashScreen();
Assert.IsFalse(ss.CloseWasExplicit);

ss.CloseWindow();
}

[Test]
public void SplashScreen_CloseExplicitPropIsCorrect3()
{
var ss = new Dynamo.UI.Views.SplashScreen();
ss.CloseWindow();
Assert.IsTrue(ss.CloseWasExplicit);
}

[Test]
//note that this test sends a windows close message directly to the window
//but skips the JS interop that users rely on to close the window - so that is not tested by this test.
Expand Down

0 comments on commit ccdfc35

Please sign in to comment.