Skip to content

Commit c9c2f6d

Browse files
authored
DYN-8498: Add splash-screen message to restart Dynamo when settings are imported (DynamoDS#16878)
1 parent 08030b0 commit c9c2f6d

File tree

7 files changed

+201
-12
lines changed

7 files changed

+201
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ launchSettings.json
6868
###############
6969
.idea
7070
.vscode/
71+
.claude
72+
.agent
73+
.cursor
7174

7275
#documentation files
7376
doc/html/

src/DynamoCoreWpf/DynamoCoreWpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<Target Name="NpmRunBuild" BeforeTargets="BeforeBuild">
2525
<PropertyGroup>
26-
<PackageVersion>1.0.30</PackageVersion>
26+
<PackageVersion>1.0.31</PackageVersion>
2727
<PackageName>SplashScreen</PackageName>
2828
</PropertyGroup>
2929
<Exec Command="$(PowerShellCommand) -ExecutionPolicy Bypass -File &quot;$(SolutionDir)pkgexist.ps1&quot; &quot;$(PackageName)&quot; &quot;$(PackageVersion)&quot;" ConsoleToMSBuild="true">

src/DynamoCoreWpf/Properties/Resources.Designer.cs

Lines changed: 32 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DynamoCoreWpf/Properties/Resources.en-US.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,15 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
37363736
<data name="SplashScreenImportSettingsFailDescription" xml:space="preserve">
37373737
<value>Something went wrong when importing your custom setting file. Please try again or proceed with default settings.</value>
37383738
</data>
3739+
<data name="SplashScreenSettingsImportedRestartMessage" xml:space="preserve">
3740+
<value>Settings imported. Please restart Dynamo.</value>
3741+
</data>
3742+
<data name="SplashScreenResetSettingsTooltip" xml:space="preserve">
3743+
<value>Reset imported settings</value>
3744+
</data>
3745+
<data name="SplashScreenSettingsResetSuccess" xml:space="preserve">
3746+
<value>Imported settings have been reset.</value>
3747+
</data>
37393748
<data name="SplashScreenLaunchingDynamo" xml:space="preserve">
37403749
<value>Launching Dynamo View...</value>
37413750
</data>

src/DynamoCoreWpf/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,6 +3730,15 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
37303730
<data name="SplashScreenImportSettingsFailDescription" xml:space="preserve">
37313731
<value>Something went wrong when importing your custom setting file. Please try again or proceed with default settings.</value>
37323732
</data>
3733+
<data name="SplashScreenSettingsImportedRestartMessage" xml:space="preserve">
3734+
<value>Settings imported. Please restart Dynamo.</value>
3735+
</data>
3736+
<data name="SplashScreenResetSettingsTooltip" xml:space="preserve">
3737+
<value>Reset imported settings</value>
3738+
</data>
3739+
<data name="SplashScreenSettingsResetSuccess" xml:space="preserve">
3740+
<value>Imported settings have been reset.</value>
3741+
</data>
37333742
<data name="SplashScreenLaunchingDynamo" xml:space="preserve">
37343743
<value>Launching Dynamo View...</value>
37353744
</data>

src/DynamoCoreWpf/PublicAPI.Unshipped.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,9 @@ Dynamo.UI.Views.ScriptHomeObject.StartGuidedTour(string path) -> void
17291729
Dynamo.UI.Views.ScriptObject
17301730
Dynamo.UI.Views.ScriptObject.ImportSettings(string file) -> void
17311731
Dynamo.UI.Views.ScriptObject.LaunchDynamo(bool showScreenAgain) -> void
1732+
Dynamo.UI.Views.ScriptObject.ResetSettings() -> void
17321733
Dynamo.UI.Views.ScriptObject.ScriptObject(System.Action<bool> requestLaunchDynamo, System.Action<string> requestImportSettings, System.Func<bool> requestSignIn, System.Func<bool> requestSignOut) -> void
1734+
Dynamo.UI.Views.ScriptObject.ScriptObject(System.Action<bool> requestLaunchDynamo, System.Action<string> requestImportSettings, System.Func<bool> requestSignIn, System.Func<bool> requestSignOut, System.Action requestResetSettings) -> void
17331735
Dynamo.UI.Views.ScriptObject.SignIn() -> bool
17341736
Dynamo.UI.Views.ScriptObject.SignOut() -> bool
17351737
Dynamo.UI.Views.ScriptWizardObject
@@ -5728,6 +5730,9 @@ static Dynamo.Wpf.Properties.Resources.SplashScreenImportSettingsFailDescription
57285730
static Dynamo.Wpf.Properties.Resources.SplashScreenLaunchingDynamo.get -> string
57295731
static Dynamo.Wpf.Properties.Resources.SplashScreenLaunchTitle.get -> string
57305732
static Dynamo.Wpf.Properties.Resources.SplashScreenLoadingTimeLabel.get -> string
5733+
static Dynamo.Wpf.Properties.Resources.SplashScreenResetSettingsTooltip.get -> string
5734+
static Dynamo.Wpf.Properties.Resources.SplashScreenSettingsImportedRestartMessage.get -> string
5735+
static Dynamo.Wpf.Properties.Resources.SplashScreenSettingsResetSuccess.get -> string
57315736
static Dynamo.Wpf.Properties.Resources.SplashScreenShowScreenAgainLabel.get -> string
57325737
static Dynamo.Wpf.Properties.Resources.SplashScreenSignIn.get -> string
57335738
static Dynamo.Wpf.Properties.Resources.SplashScreenSigningIn.get -> string

src/DynamoCoreWpf/Views/SplashScreen/SplashScreen.xaml.cs

Lines changed: 142 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ internal enum CloseMode { ByStartingDynamo, ByCloseButton, ByOther };
6363
internal Func<bool> RequestSignIn;
6464
internal Func<bool> RequestSignOut;
6565

66+
// Fields for tracking imported settings and enabling reset functionality
67+
private bool settingsWereImported = false;
68+
private string originalSettingsContent = null;
69+
private string importedSettingsFilePath = null;
70+
6671
/// <summary>
6772
/// Dynamo auth manager reference
6873
/// </summary>
@@ -248,16 +253,46 @@ private void WebView_NavigationCompleted(object sender, CoreWebView2NavigationCo
248253
/// <param name="fileContent"></param>
249254
private void ImportSettings(string fileContent)
250255
{
251-
bool isImported = viewModel.PreferencesViewModel.importSettingsContent(fileContent);
252-
if (isImported)
256+
try
253257
{
254-
SetImportStatus(ImportStatus.success);
258+
// Get the settings file path
259+
var pathManager = viewModel?.Model?.PathManager ?? PathManager.Instance;
260+
importedSettingsFilePath = pathManager.PreferenceFilePath;
261+
262+
// Backup original settings before importing (only if not already backed up)
263+
if (!settingsWereImported && System.IO.File.Exists(importedSettingsFilePath))
264+
{
265+
originalSettingsContent = System.IO.File.ReadAllText(importedSettingsFilePath);
266+
}
267+
268+
// Validate the imported settings
269+
bool isImported = viewModel.PreferencesViewModel.importSettingsContent(fileContent);
270+
271+
if (isImported)
272+
{
273+
// Mark that settings were imported
274+
settingsWereImported = true;
275+
276+
// Show success status on splash screen
277+
SetImportStatus(ImportStatus.success);
278+
279+
// Show the restart message and reset button
280+
ShowRestartMessage();
281+
282+
Analytics.TrackEvent(Actions.Import, Categories.SplashScreenOperations, "true");
283+
}
284+
else
285+
{
286+
SetImportStatus(ImportStatus.error);
287+
Analytics.TrackEvent(Actions.Import, Categories.SplashScreenOperations, "false");
288+
}
255289
}
256-
else
290+
catch (Exception ex)
257291
{
292+
viewModel?.Model?.Logger?.Log($"Error importing settings: {ex.Message}");
258293
SetImportStatus(ImportStatus.error);
294+
Analytics.TrackEvent(Actions.Import, Categories.SplashScreenOperations, "false");
259295
}
260-
Analytics.TrackEvent(Actions.Import, Categories.SplashScreenOperations, isImported.ToString());
261296
}
262297

263298
/// <summary>
@@ -396,7 +431,7 @@ protected override async void OnContentRendered(EventArgs e)
396431

397432
webView.NavigateToString(htmlString);
398433
webView.CoreWebView2.AddHostObjectToScript("scriptObject",
399-
new ScriptObject(RequestLaunchDynamo, RequestImportSettings, RequestSignIn, RequestSignOut));
434+
new ScriptObject(RequestLaunchDynamo, RequestImportSettings, RequestSignIn, RequestSignOut, ResetImportedSettings));
400435
}
401436
catch (ObjectDisposedException ex)
402437
{
@@ -465,6 +500,81 @@ await webView.CoreWebView2.ExecuteScriptAsync("window.setImportStatus({" +
465500
}
466501
}
467502

503+
/// <summary>
504+
/// Show the restart required message and reset button after settings import
505+
/// </summary>
506+
internal async void ShowRestartMessage()
507+
{
508+
try
509+
{
510+
if (webView?.CoreWebView2 != null)
511+
{
512+
await webView.CoreWebView2.ExecuteScriptAsync("window.showRestartMessage()");
513+
}
514+
}
515+
catch (Exception ex)
516+
{
517+
viewModel?.Model?.Logger?.Log($"Error showing restart message: {ex.Message}");
518+
}
519+
}
520+
521+
/// <summary>
522+
/// Hide the restart required message and reset button
523+
/// </summary>
524+
internal async void HideRestartMessage()
525+
{
526+
try
527+
{
528+
if (webView?.CoreWebView2 != null)
529+
{
530+
await webView.CoreWebView2.ExecuteScriptAsync("window.hideRestartMessage()");
531+
}
532+
}
533+
catch (Exception ex)
534+
{
535+
viewModel?.Model?.Logger?.Log($"Error hiding restart message: {ex.Message}");
536+
}
537+
}
538+
539+
/// <summary>
540+
/// Resets the imported settings to the original settings that were backed up
541+
/// </summary>
542+
private void ResetImportedSettings()
543+
{
544+
try
545+
{
546+
if (!string.IsNullOrEmpty(originalSettingsContent) &&
547+
!string.IsNullOrEmpty(importedSettingsFilePath))
548+
{
549+
// Restore original settings to disk
550+
System.IO.File.WriteAllText(importedSettingsFilePath, originalSettingsContent);
551+
552+
// Reload the original settings into the current session
553+
var restoredPreferences = PreferenceSettings.LoadContent(originalSettingsContent);
554+
if (restoredPreferences.IsCreatedFromValidFile)
555+
{
556+
viewModel.PreferencesViewModel.importSettingsContent(originalSettingsContent);
557+
}
558+
559+
// Clear the imported flag and backup
560+
settingsWereImported = false;
561+
originalSettingsContent = null;
562+
563+
// Hide the restart message
564+
HideRestartMessage();
565+
566+
// Show reset success message briefly
567+
SetImportStatus(ImportStatus.none);
568+
569+
viewModel?.Model?.Logger?.Log(Wpf.Properties.Resources.SplashScreenSettingsResetSuccess);
570+
}
571+
}
572+
catch (Exception ex)
573+
{
574+
viewModel?.Model?.Logger?.Log($"Error resetting settings: {ex.Message}");
575+
}
576+
}
577+
468578
/// <summary>
469579
/// Set the login status on splash screen.
470580
/// </summary>
@@ -516,7 +626,9 @@ await webView.CoreWebView2.ExecuteScriptAsync("window.setLabels({" +
516626
$"signOutTitle: \"{Wpf.Properties.Resources.SplashScreenSignOut}\"," +
517627
$"signOutTooltip: \"{Wpf.Properties.Resources.SignOutConfirmationDialogText}\"," +
518628
$"signingInTitle: \"{Wpf.Properties.Resources.SplashScreenSigningIn}\"," +
519-
$"importSettingsTooltipDescription: \"{Wpf.Properties.Resources.ImportPreferencesInfo}\"" + "})");
629+
$"importSettingsTooltipDescription: \"{Wpf.Properties.Resources.ImportPreferencesInfo}\"," +
630+
$"restartMessage: \"{Wpf.Properties.Resources.SplashScreenSettingsImportedRestartMessage}\"," +
631+
$"resetTooltip: \"{Wpf.Properties.Resources.SplashScreenResetSettingsTooltip}\"" + "})");
520632
}
521633
}
522634

@@ -663,38 +775,58 @@ public class ScriptObject
663775
readonly Action<string> RequestImportSettings;
664776
readonly Func<bool> RequestSignIn;
665777
readonly Func<bool> RequestSignOut;
778+
readonly Action RequestResetSettings;
779+
780+
[Obsolete("This constructor is obsolete. Use the constructor with the additional parameters instead.")]
781+
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func<bool> requestSignIn, Func<bool> requestSignOut)
782+
{
783+
RequestLaunchDynamo = requestLaunchDynamo;
784+
RequestImportSettings = requestImportSettings;
785+
RequestSignIn = requestSignIn;
786+
RequestSignOut = requestSignOut;
787+
}
666788

667789
/// <summary>
668-
/// [Obsolete] Constructor for ScriptObject
790+
/// Constructor for ScriptObject
669791
/// </summary>
670-
[Obsolete]
671-
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func< bool> requestSignIn, Func<bool> requestSignOut)
792+
public ScriptObject(Action<bool> requestLaunchDynamo, Action<string> requestImportSettings, Func< bool> requestSignIn, Func<bool> requestSignOut, Action requestResetSettings)
672793
{
673794
RequestLaunchDynamo = requestLaunchDynamo;
674795
RequestImportSettings = requestImportSettings;
675796
RequestSignIn = requestSignIn;
676797
RequestSignOut = requestSignOut;
798+
RequestResetSettings = requestResetSettings;
677799
}
800+
678801
[DynamoJSInvokable]
679802
public void LaunchDynamo(bool showScreenAgain)
680803
{
681804
RequestLaunchDynamo(showScreenAgain);
682805
Analytics.TrackEvent(Actions.Start, Categories.SplashScreenOperations);
683806
}
807+
684808
[DynamoJSInvokable]
685809
public void ImportSettings(string file)
686810
{
687811
RequestImportSettings(file);
688812
}
813+
689814
[DynamoJSInvokable]
690815
public bool SignIn()
691816
{
692817
return RequestSignIn();
693818
}
819+
694820
[DynamoJSInvokable]
695821
public bool SignOut()
696822
{
697823
return RequestSignOut();
698824
}
825+
826+
[DynamoJSInvokable]
827+
public void ResetSettings()
828+
{
829+
RequestResetSettings();
830+
}
699831
}
700832
}

0 commit comments

Comments
 (0)