@@ -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