Skip to content

Commit

Permalink
DYN-8121 SplashScreen Disable Close Button (#15756)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGlobant20 authored Jan 28, 2025
1 parent 7a293ed commit c0ebe10
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/DynamoCoreWpf/DynamoCoreWpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<Target Name="NpmRunBuild" BeforeTargets="BeforeBuild">
<PropertyGroup>
<PackageVersion>1.0.26</PackageVersion>
<PackageVersion>1.0.27</PackageVersion>
<PackageName>SplashScreen</PackageName>
</PropertyGroup>
<Exec Command="$(PowerShellCommand) -ExecutionPolicy Bypass -File &quot;$(SolutionDir)pkgexist.ps1&quot; &quot;$(PackageName)&quot; &quot;$(PackageVersion)&quot;" ConsoleToMSBuild="true">
Expand Down
5 changes: 1 addition & 4 deletions src/DynamoCoreWpf/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1633,12 +1633,9 @@ Dynamo.UI.Views.ScriptHomeObject.ShowSampleDatasetsInFolder() -> void
Dynamo.UI.Views.ScriptHomeObject.ShowTempalte() -> void
Dynamo.UI.Views.ScriptHomeObject.StartGuidedTour(string path) -> void
Dynamo.UI.Views.ScriptObject
Dynamo.UI.Views.ScriptObject.CloseWindow() -> void
Dynamo.UI.Views.ScriptObject.CloseWindowPreserve(bool isCheckboxChecked) -> void
Dynamo.UI.Views.ScriptObject.ImportSettings(string file) -> void
Dynamo.UI.Views.ScriptObject.LaunchDynamo(bool showScreenAgain) -> void
Dynamo.UI.Views.ScriptObject.ScriptObject(System.Action<bool> requestLaunchDynamo, System.Action<string> requestImportSettings, System.Func<bool> requestSignIn, System.Func<bool> requestSignOut, System.Action requestCloseWindow) -> void
Dynamo.UI.Views.ScriptObject.ScriptObject(System.Action<bool> requestLaunchDynamo, System.Action<string> requestImportSettings, System.Func<bool> requestSignIn, System.Func<bool> requestSignOut, System.Action<bool> requestCloseWindow) -> void
Dynamo.UI.Views.ScriptObject.ScriptObject(System.Action<bool> requestLaunchDynamo, System.Action<string> requestImportSettings, System.Func<bool> requestSignIn, System.Func<bool> requestSignOut) -> void
Dynamo.UI.Views.ScriptObject.SignIn() -> bool
Dynamo.UI.Views.ScriptObject.SignOut() -> bool
Dynamo.UI.Views.SplashScreen
Expand Down
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);
}
}
}
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

0 comments on commit c0ebe10

Please sign in to comment.