Skip to content

Commit

Permalink
Simplify and invert
Browse files Browse the repository at this point in the history
  • Loading branch information
saintentropy committed Dec 1, 2023
1 parent 6363956 commit 73b82c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ internal static void CopyProperties(this PreferenceSettings source, PreferenceSe
/// </summary>
public class PreferenceSettings : NotificationObject, IPreferences, IRenderPrecisionPreference, IDisablePackageLoadingPreferences, ILogSource, IHideAutocompleteMethodOptions
{
internal static PreferenceSettings dynamoModelRuntimePreferenceSettings;

internal readonly static Lazy<PreferenceSettings>
lazy = new Lazy<PreferenceSettings>
(() => PreferenceSettings.Load(PathManager.Instance.PreferenceFilePath));

[XmlIgnore]
public static PreferenceSettings Instance { get { return dynamoModelRuntimePreferenceSettings ?? lazy.Value; } }
public static PreferenceSettings Instance { get; internal set; } = lazy.Value;

private string numberFormat;
private string lastUpdateDownloadPath;
Expand Down
13 changes: 4 additions & 9 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ internal static string AppVersion
/// <summary>
/// Preference settings for this instance of Dynamo.
/// </summary>
public readonly PreferenceSettings PreferenceSettings;
[Obsolete("this will be removed in 4.0")]
public PreferenceSettings PreferenceSettings => PreferenceSettings.Instance;

/// <summary>
/// Node Factory, used for creating and intantiating loaded Dynamo nodes.
Expand Down Expand Up @@ -492,9 +493,6 @@ protected virtual void ShutDownCore(bool shutdownHost)
Dispose();
PreferenceSettings.SaveInternal(pathManager.PreferenceFilePath);

//Remove reference on shutdown
PreferenceSettings.dynamoModelRuntimePreferenceSettings = null;

OnCleanup();

DynamoSelection.DestroyInstance();
Expand Down Expand Up @@ -694,10 +692,7 @@ protected DynamoModel(IStartConfiguration config)

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

PreferenceSettings = (PreferenceSettings)CreateOrLoadPreferences(config.Preferences);

//Set the DynamoModel.PreferenceSetting as a static reference to the PreferenceSetting class for use in PreferenceSettings.Instance
PreferenceSettings.dynamoModelRuntimePreferenceSettings = PreferenceSettings;
PreferenceSettings.Instance = (PreferenceSettings)CreateOrLoadPreferences(config.Preferences);

if (PreferenceSettings != null)
{
Expand Down Expand Up @@ -786,7 +781,7 @@ protected DynamoModel(IStartConfiguration config)
if (migrator != null)
{
var isFirstRun = PreferenceSettings.IsFirstRun;
PreferenceSettings = migrator.PreferenceSettings;
PreferenceSettings.Instance = migrator.PreferenceSettings;

// Preserve the preference settings for IsFirstRun as this needs to be set
// only by UsageReportingManager
Expand Down

0 comments on commit 73b82c9

Please sign in to comment.