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

DYN-8121 SplashScreen Disable Close Button #15756

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually API breaking but I remember in the past we announced that we are not going to guard our UI code to follow backward compatible pattern. @mjkkirschner Correct me if I am wrong

{
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);
}
}
}
48 changes: 1 addition & 47 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,34 +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
Loading