private void LoadSettingsFromJson() { // TODO this IO call should by Async, update GetFileWatcher helper to support async lock (_loadingSettingsLock) { { var retry = true; var retryCount = 0; while (retry) { try { retryCount++; if (!_settingsUtils.SettingsExists(ColorPickerModuleName)) { Logger.LogInfo("ColorPicker settings.json was missing, creating a new one"); var defaultColorPickerSettings = new ColorPickerSettings(); defaultColorPickerSettings.Save(_settingsUtils); } var settings = _settingsUtils.GetSettingsOrDefault <ColorPickerSettings>(ColorPickerModuleName); if (settings != null) { ChangeCursor.Value = settings.Properties.ChangeCursor; ActivationShortcut.Value = settings.Properties.ActivationShortcut.ToString(); CopiedColorRepresentation.Value = settings.Properties.CopiedColorRepresentation; ActivationAction.Value = settings.Properties.ActivationAction; ColorHistoryLimit.Value = settings.Properties.ColorHistoryLimit; ShowColorName.Value = settings.Properties.ShowColorName; if (settings.Properties.ColorHistory == null) { settings.Properties.ColorHistory = new System.Collections.Generic.List <string>(); } _loadingColorsHistory = true; ColorHistory.Clear(); foreach (var item in settings.Properties.ColorHistory) { ColorHistory.Add(item); } _loadingColorsHistory = false; VisibleColorFormats.Clear(); foreach (var item in settings.Properties.VisibleColorFormats) { if (item.Value) { VisibleColorFormats.Add(item.Key); } } } retry = false; } catch (IOException ex) { if (retryCount > MaxNumberOfRetry) { retry = false; } Logger.LogError("Failed to read changed settings", ex); Thread.Sleep(500); } catch (Exception ex) { if (retryCount > MaxNumberOfRetry) { retry = false; } Logger.LogError("Failed to read changed settings", ex); Thread.Sleep(500); } } } } }
public void AddColorToHistory(ColorEntry entry) { ColorHistory.Add(entry); }