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-5816 locale splash screen #14118

Merged
merged 62 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
18c74c4
Display the proper language in the Splash Screen
jesusalvino Jun 29, 2023
2ebe836
spacing RootDirectories
jesusalvino Jun 29, 2023
9614f08
Keeping spacing
jesusalvino Jun 29, 2023
b265118
Remove Splash Screen default title
jesusalvino Jun 30, 2023
4766900
Dissect the Preferences creation from the DynamoModel ctor
jesusalvino Jun 30, 2023
7194409
removing null validation
jesusalvino Jun 30, 2023
fe25ed1
Refactoring based on the PathManager and Preferences
Jul 11, 2023
f27f2de
Adding a PathManager and Preference singleton
Jul 12, 2023
49cfc60
cleaning text
Jul 12, 2023
4da1ea6
PathManager and PreferenceSetttings as singleton
Jul 13, 2023
695628c
Cleaning spacing and others
Jul 13, 2023
1fb48cb
Using the singleton PathManager class instead of the Interface
Jul 14, 2023
db89a94
Changing the scope and documenting the function CreateIPathResolver
Jul 20, 2023
fb647ec
Changing access to be flexible for integrators
Jul 20, 2023
777f584
Removing unused function
Jul 21, 2023
4c42d65
Setting the Preferences to the RecorderTests
Jul 21, 2023
7dd7321
Add the PreferenceSettings.Instance to the DynamoCoreTests setup
Jul 22, 2023
06bbbd4
Adding the preference settings to the DynamoTestUIBase Start configur…
Jul 22, 2023
1aefe4a
Set the Preferences to the SystemTesttBase
Jul 23, 2023
2ce8be4
Set the PreferenceSettings.Instance to the DynamoViewModelUnitTest Start
Jul 24, 2023
d229f81
Dealing with the PathResolver
Jul 25, 2023
0b3902f
Passing the Preferences to the DynamoModel Start function and update …
Jul 25, 2023
1f449e0
Passing the Prererences to the VisualizationTest Start
Jul 25, 2023
b63a8dd
Update the MakeCLIModel function
Jul 25, 2023
2eab90c
Passing the Preferences to the DefaultStartConfiguration
Jul 25, 2023
9e1f6d9
merge master-resolve conflicts
reddyashish Jul 28, 2023
b50b5e4
Update AssemblySharedInfo.cs
reddyashish Jul 28, 2023
ff3862c
Passing the settings to the configuration from the parameter
Jul 31, 2023
6fc2258
untouch the hostApplicationDirectory
Jul 31, 2023
e81b146
Untouching the preLoadedLibraries field and renaming
Jul 31, 2023
9da3a1f
Restoring fields and adding doc
Aug 1, 2023
f4bafcd
Adding the preferences to the start of some tests
Aug 1, 2023
7ed64f7
Validating the settings in the DynamoModelTestBase setup
Aug 2, 2023
4dfdef4
Adding Preferences to the config Settings Test
Aug 3, 2023
7252051
Refactoring the PathManager and Preference creation on the DynamoMode…
Aug 3, 2023
1ddba71
Merge branch 'master' into DYN-5816-locale-splash-screen
Aug 3, 2023
84e111d
Cleaning Tests setup and ignore Pref Instance property for xml
Aug 3, 2023
37620ba
Merge branch 'DynamoDS:master' into DYN-5816-locale-splash-screen
jesusalvino Aug 4, 2023
1321eb7
Merge branch 'DynamoDS:master' into DYN-5816-locale-splash-screen
jesusalvino Aug 4, 2023
8c3ee26
Removing Pref Singleton to the CoreTest Setup
Aug 4, 2023
cc58ece
Rollback fron the 6213 commit
Aug 4, 2023
90e4a7f
Merge branch 'master' into DYN-5816-locale-splash-screen
Aug 4, 2023
1f0d671
keep the StartInTestMode to false since this is an special case and s…
Aug 4, 2023
e14ee63
Handling Preferences
Aug 5, 2023
fe980b9
clieaning references
Aug 5, 2023
4771ed4
Saving them with the proper Unicode
Aug 5, 2023
33a5d63
Removing Singletion Preferences
Aug 5, 2023
e5e92ab
Explicit Settings since the StartInTestMode is false
Aug 5, 2023
745a431
Add the specific Preferences
Aug 7, 2023
53d2218
Rollback the cc58
Aug 7, 2023
2539d97
Rollback the cc58
Aug 7, 2023
b630a38
Merge branch 'master' of https://github.com/jesusalvino/Dynamo
Aug 7, 2023
06ea6c5
Merge branch 'master' into DYN-5816-T1
Aug 7, 2023
2caf714
Fix Solution
Aug 8, 2023
c290e73
Fixing the Assembly character and test file
Aug 8, 2023
63e905a
Merge branch 'master' into DYN-5816-locale-splash-screen
Aug 8, 2023
87636bb
Merge branch 'DYN-5816-T1' into DYN-5816-locale-splash-screen
Aug 8, 2023
d10541a
Forcing to update the cc58 commit
Aug 8, 2023
549e3c2
Removing the test file
Aug 8, 2023
162fe2c
Fixing Tests Unicode
Aug 8, 2023
d2f3731
No new line
Aug 8, 2023
5a22b9d
Merge branch 'DynamoDS:master' into DYN-5816-locale-splash-screen
jesusalvino Aug 8, 2023
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
52 changes: 48 additions & 4 deletions src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Text;
using System.Threading;
using CommandLine;
using Dynamo.Configuration;
using Dynamo.Core;
using Dynamo.Interfaces;
using Dynamo.Models;
using Dynamo.Scheduler;
Expand Down Expand Up @@ -273,10 +275,21 @@ public static DynamoModel MakeModel(bool CLImode, string asmPath = "", string ho
/// <returns></returns>
public static DynamoModel MakeModel(bool CLImode, string asmPath = "", HostAnalyticsInfo info = new HostAnalyticsInfo())
{
var pathManagerAndPreference = CreatePathManagerAndPreference();
DynamoModel.OnDetectLanguage();

// Preload ASM and display corresponding message on splash screen
DynamoModel.OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenPreLoadingAsm, 10));
var isASMloaded = PreloadASM(asmPath, out string geometryFactoryPath, out string preloaderLocation);
var model = StartDynamoWithDefaultConfig(CLImode, string.Empty, string.Empty, geometryFactoryPath, preloaderLocation, info);
var model = StartDynamoWithDefaultConfig(CLImode,
string.Empty,
string.Empty,
geometryFactoryPath,
preloaderLocation,
info,
false,
pathManagerAndPreference.Item1,
pathManagerAndPreference.Item2);
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
model.IsASMLoaded = isASMloaded;
return model;
}
Expand Down Expand Up @@ -360,13 +373,42 @@ private static bool PreloadASM(string asmPath, out string geometryFactoryPath, o
}
}

/// <summary>
/// Create a unique instance of a PathManager and PreferenceSettings to apply the locale language and reuse them as part of the DynamoModel ctor
/// </summary>
/// <returns></returns>
private static Tuple<PathManager, PreferenceSettings> CreatePathManagerAndPreference()
{
IPathResolver pathResolver = CreateIPathResolver(false, "", "", "");
PathManager pathManager = new PathManager(new PathManagerParams
{
CorePath = string.Empty,
HostPath = string.Empty,
PathResolver = pathResolver
});

PreferenceSettings preferenceSettings = (PreferenceSettings)DynamoModel.CreateOrLoadPreferences(null, false, pathManager.PreferenceFilePath);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(preferenceSettings.Locale);
Thread.CurrentThread.CurrentCulture = new CultureInfo(preferenceSettings.Locale);
return new Tuple<PathManager, PreferenceSettings>(pathManager, preferenceSettings);
}

private static IPathResolver CreateIPathResolver(bool CLImode,string preloaderLocation,string userDataFolder, string commonDataFolder)
{
IPathResolver pathResolver = CLImode ? new CLIPathResolver(preloaderLocation, userDataFolder, commonDataFolder) as IPathResolver : new SandboxPathResolver(preloaderLocation) as IPathResolver;
return pathResolver;
}

private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
string userDataFolder,
string commonDataFolder,
string geometryFactoryPath,
string preloaderLocation,
HostAnalyticsInfo info = new HostAnalyticsInfo(),
bool isServiceMode = false)
bool isServiceMode = false,
PathManager pathManager = null,
PreferenceSettings preferences = null
)
{
var config = new DynamoModel.DefaultStartConfiguration
{
Expand All @@ -377,8 +419,10 @@ private static DynamoModel StartDynamoWithDefaultConfig(bool CLImode,
AuthProvider = CLImode ? null : new Core.IDSDKManager(),
UpdateManager = CLImode ? null : OSHelper.IsWindows() ? InitializeUpdateManager() : null,
StartInTestMode = CLImode,
PathResolver = CLImode ? new CLIPathResolver(preloaderLocation, userDataFolder, commonDataFolder) as IPathResolver : new SandboxPathResolver(preloaderLocation) as IPathResolver,
IsServiceMode = isServiceMode
PathResolver = pathManager == null ? CreateIPathResolver(CLImode, preloaderLocation, userDataFolder, commonDataFolder) : null,
IsServiceMode = isServiceMode,
PathManager = pathManager,
Preferences = preferences
};

var model = DynamoModel.Start(config);
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Configuration/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct PathManagerParams
internal IPathResolver PathResolver { get; set; }
}

class PathManager : IPathManager
public class PathManager : IPathManager
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to clarify that all of the public methods of this class (which were hidden before because the class was private) are now going to be exposed as public members of the class. Not sure if this was intended
FYI @mjkkirschner @QilongTang

Copy link
Contributor

@QilongTang QilongTang Aug 14, 2023

Choose a reason for hiding this comment

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

This is a good point. @jesusalvino Does PathManager need to be a public singleton or internal?

Copy link
Contributor Author

@jesusalvino jesusalvino Aug 14, 2023

Choose a reason for hiding this comment

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

@QilongTang I think keep it within the .Core namespace should be enough, I will take a look

Copy link
Member

Choose a reason for hiding this comment

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

prefer internal if possible!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guys this is the PR #14263

{
#region Class Private Data Members

Expand Down
59 changes: 43 additions & 16 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ public interface IStartConfiguration
/// No update checks or analytics collection should be done.
/// </summary>
bool IsHeadless { get; set; }
IPathManager PathManager { get; set; }
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down Expand Up @@ -587,6 +588,8 @@ public struct DefaultStartConfiguration : IStartConfiguration
/// CLIMode indicates if we are running in DynamoCLI or DynamoWPFCLI mode.
/// </summary>
public bool CLIMode { get; set; }

public IPathManager PathManager { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -668,12 +671,21 @@ protected DynamoModel(IStartConfiguration config)

ClipBoard = new ObservableCollection<ModelBase>();

pathManager = new PathManager(new PathManagerParams
#region [ Dealing with the PathManager]
if (config.PathManager != null)
{
CorePath = config.DynamoCorePath,
HostPath = config.DynamoHostPath,
PathResolver = config.PathResolver
});
pathManager = (PathManager)config.PathManager;
}
else if (config.PathResolver != null)
{
pathManager = new PathManager(new PathManagerParams
{
CorePath = config.DynamoCorePath,
HostPath = config.DynamoHostPath,
PathResolver = config.PathResolver
});
}
#endregion

// Ensure we have all directories in place.
var exceptions = new List<Exception>();
Expand Down Expand Up @@ -707,16 +719,31 @@ protected DynamoModel(IStartConfiguration config)

OnRequestUpdateLoadBarStatus(new SplashScreenLoadEventArgs(Resources.SplashScreenInitPreferencesSettings, 30));

IPreferences preferences = CreateOrLoadPreferences(config.Preferences);
if (preferences is PreferenceSettings settings)

#region [ Dealing with the Preferences ]
if (config.Preferences != null)
{
PreferenceSettings = settings;
// Setting the new locale for Dynamo after Preferences loaded
Thread.CurrentThread.CurrentUICulture = new CultureInfo(PreferenceSettings.Locale);
Thread.CurrentThread.CurrentCulture = new CultureInfo(PreferenceSettings.Locale);
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
if (config.Preferences is PreferenceSettings settings)
{
PreferenceSettings = settings;
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
}
else
{
IPreferences preferences = CreateOrLoadPreferences(config.Preferences,IsServiceMode, pathManager.PreferenceFilePath);
if (preferences is PreferenceSettings settings)
{
PreferenceSettings = settings;
// Setting the new locale for Dynamo after Preferences loaded
Thread.CurrentThread.CurrentUICulture = new CultureInfo(PreferenceSettings.Locale);
Thread.CurrentThread.CurrentCulture = new CultureInfo(PreferenceSettings.Locale);
PreferenceSettings.PropertyChanged += PreferenceSettings_PropertyChanged;
PreferenceSettings.MessageLogged += LogMessage;
}
}
#endregion

if (config is DefaultStartConfiguration defaultStartConfiguration)
{
Expand Down Expand Up @@ -1727,13 +1754,13 @@ private void LoadNodeModels(List<TypeLoadData> nodes, bool isPackageMember)
}
}

private IPreferences CreateOrLoadPreferences(IPreferences preferences)
public static IPreferences CreateOrLoadPreferences(IPreferences preferences, bool isServiceMode, string preferenceFilePath)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
if (preferences != null) // If there is preference settings provided...
return preferences;

//Skip file handling and trust location in service mode.
if (IsServiceMode)
if (isServiceMode)
{
var setting = new PreferenceSettings();
setting.SetTrustWarningsDisabled(true);
Expand All @@ -1747,7 +1774,7 @@ private IPreferences CreateOrLoadPreferences(IPreferences preferences)
//
var xmlFilePath = PreferenceSettings.DynamoTestPath;
if (string.IsNullOrEmpty(xmlFilePath))
xmlFilePath = pathManager.PreferenceFilePath;
xmlFilePath = preferenceFilePath;

if (File.Exists(xmlFilePath))
{
Expand Down
4 changes: 4 additions & 0 deletions src/DynamoCore/Models/DynamoModelDelegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ namespace Dynamo.Models
/// <param name="args"></param>
internal delegate void SplashScreenLoadingHandler(SplashScreenLoadEventArgs args);

/// <summary>
/// This delegate is used to notify the detected language to the Splash Screen.
/// </summary>
internal delegate void SplashScreenLanguageDetected();
}
9 changes: 9 additions & 0 deletions src/DynamoCore/Models/DynamoModelEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ internal static void OnRequestUpdateLoadBarStatus(SplashScreenLoadEventArgs args
RequestUpdateLoadBarStatus?.Invoke(args);
}

/// <summary>
/// Event to throw for Splash Screen to display the content in the proper language
/// </summary>
internal static event SplashScreenLanguageDetected LanguageDetected;
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
internal static void OnDetectLanguage()
{
LanguageDetected?.Invoke();
}

/// <summary>
/// Occurs when changes in data may affect UI and UI needs to be refreshed
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions src/DynamoCoreWpf/Views/SplashScreen/SplashScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,21 @@ public SplashScreen()
// Bind event handlers
webView.NavigationCompleted += WebView_NavigationCompleted;
DynamoModel.RequestUpdateLoadBarStatus += DynamoModel_RequestUpdateLoadBarStatus;
DynamoModel.LanguageDetected += DynamoModel_LanguageDetected;
StaticSplashScreenReady += OnStaticScreenReady;
RequestLaunchDynamo = LaunchDynamo;
RequestImportSettings = ImportSettings;
RequestSignIn = SignIn;
RequestSignOut = SignOut;
}

private void WebView_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
private void DynamoModel_LanguageDetected()
{
SetLabels();
}

private void WebView_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
if (webView != null)
{
webView.NavigationCompleted -= WebView_NavigationCompleted;
Expand Down Expand Up @@ -276,7 +281,7 @@ protected override async void OnContentRendered(EventArgs e)
webView.CoreWebView2.Settings.IsZoomControlEnabled = false;

var assembly = Assembly.GetExecutingAssembly();

using (Stream stream = assembly.GetManifestResourceStream(htmlEmbeddedFile))
using (StreamReader reader = new StreamReader(stream))
{
Expand All @@ -296,6 +301,7 @@ protected override async void OnContentRendered(EventArgs e)
jsonString = jsonString.Replace("#base64BackgroundImage", $"data:image/{imageFileExtension};base64,{resourceBase64}");
}

jsonString = jsonString.Replace("Welcome to Dynamo!", "");
htmlString = htmlString.Replace("mainJs", jsonString);

webView.NavigateToString(htmlString);
Expand Down Expand Up @@ -474,6 +480,7 @@ protected override void OnClosed(EventArgs e)
base.OnClosed(e);

DynamoModel.RequestUpdateLoadBarStatus -= DynamoModel_RequestUpdateLoadBarStatus;
DynamoModel.LanguageDetected -= DynamoModel_LanguageDetected;
webView.Dispose();
webView = null;

Expand Down
Loading