From 50ef6e9aeabfcb0c6c9db30f7bc8eb5733abf8eb Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Fri, 26 Jun 2020 07:48:38 +0530 Subject: [PATCH 1/6] Implemented settings and recently opened file list syncing across all instances. --- src/Notepads/App.xaml.cs | 1 - .../Controls/Dialog/NotepadsDialog.cs | 4 +- src/Notepads/Notepads.csproj | 1 + src/Notepads/Services/AppSettingsService.cs | 72 ++++++++++++--- .../Services/InterInstanceSyncService.cs | 69 +++++++++++++++ src/Notepads/Services/ThemeSettingsService.cs | 88 ++++++++----------- src/Notepads/Settings/ApplicationSettings.cs | 7 ++ src/Notepads/Settings/SettingsKey.cs | 3 +- src/Notepads/Strings/en-US/Resources.resw | 2 +- .../MainPage/NotepadsMainPage.MainMenu.cs | 12 ++- .../Views/MainPage/NotepadsMainPage.xaml.cs | 7 ++ .../PersonalizationSettingsPage.xaml.cs | 32 +++---- 12 files changed, 205 insertions(+), 93 deletions(-) create mode 100644 src/Notepads/Services/InterInstanceSyncService.cs diff --git a/src/Notepads/App.xaml.cs b/src/Notepads/App.xaml.cs index d8ffef582..58641361d 100644 --- a/src/Notepads/App.xaml.cs +++ b/src/Notepads/App.xaml.cs @@ -93,7 +93,6 @@ private async Task ActivateAsync(IActivatedEventArgs e) { { "OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString() }, { "OSVersion", $"{SystemInformation.OperatingSystemVersion.Major}.{SystemInformation.OperatingSystemVersion.Minor}.{SystemInformation.OperatingSystemVersion.Build}" }, - { "UseWindowsTheme", ThemeSettingsService.UseWindowsTheme.ToString() }, { "ThemeMode", ThemeSettingsService.ThemeMode.ToString() }, { "UseWindowsAccentColor", ThemeSettingsService.UseWindowsAccentColor.ToString() }, { "AppBackgroundTintOpacity", $"{(int) (ThemeSettingsService.AppBackgroundPanelTintOpacity * 10.0) * 10}" }, diff --git a/src/Notepads/Controls/Dialog/NotepadsDialog.cs b/src/Notepads/Controls/Dialog/NotepadsDialog.cs index bb27e1b9c..73c82d856 100644 --- a/src/Notepads/Controls/Dialog/NotepadsDialog.cs +++ b/src/Notepads/Controls/Dialog/NotepadsDialog.cs @@ -17,8 +17,8 @@ public class NotepadsDialog : ContentDialog public NotepadsDialog() { - RequestedTheme = ThemeSettingsService.ThemeMode; - Background = ThemeSettingsService.ThemeMode == ElementTheme.Dark + RequestedTheme = ThemeSettingsService.GetActualTheme(ThemeSettingsService.ThemeMode); + Background = RequestedTheme == ElementTheme.Dark ? _darkModeBackgroundBrush : _lightModeBackgroundBrush; diff --git a/src/Notepads/Notepads.csproj b/src/Notepads/Notepads.csproj index 5bda548f5..63b41413a 100644 --- a/src/Notepads/Notepads.csproj +++ b/src/Notepads/Notepads.csproj @@ -137,6 +137,7 @@ + diff --git a/src/Notepads/Services/AppSettingsService.cs b/src/Notepads/Services/AppSettingsService.cs index d98c868d1..3966aa59d 100644 --- a/src/Notepads/Services/AppSettingsService.cs +++ b/src/Notepads/Services/AppSettingsService.cs @@ -286,13 +286,17 @@ public static bool IsSmartCopyEnabled public static void Initialize() { - InitializeFontSettings(); + InitializeFontFamilySettings(); + InitializeFontSizeSettings(); + InitializeFontStyleSettings(); + InitializeFontWeightSettings(); InitializeTextWrappingSettings(); InitializeSpellingSettings(); - InitializeDisplaySettings(); + InitializeDisplayLineHighlighterSettings(); + InitializeDisplayLineNumbersSettings(); InitializeSmartCopySettings(); @@ -305,6 +309,7 @@ public static void Initialize() InitializeTabIndentsSettings(); InitializeSearchEngineSettings(); + InitializeCustomSearchUrlSettings(); InitializeStatusBarSettings(); @@ -313,7 +318,7 @@ public static void Initialize() InitializeAppOpeningPreferencesSettings(); } - private static void InitializeStatusBarSettings() + public static void InitializeStatusBarSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorShowStatusBarBool) is bool showStatusBar) { @@ -323,6 +328,8 @@ private static void InitializeStatusBarSettings() { _showStatusBar = true; } + + if (invokeChangedEvent) OnStatusBarVisibilityChanged?.Invoke(null, _showStatusBar); } private static void InitializeSessionSnapshotSettings() @@ -349,7 +356,7 @@ private static void InitializeSessionSnapshotSettings() } } - private static void InitializeLineEndingSettings() + public static void InitializeLineEndingSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultLineEndingStr) is string lineEndingStr && Enum.TryParse(typeof(LineEnding), lineEndingStr, out var lineEnding)) @@ -360,9 +367,11 @@ private static void InitializeLineEndingSettings() { _editorDefaultLineEnding = LineEnding.Crlf; } + + if (invokeChangedEvent) OnDefaultLineEndingChanged?.Invoke(null, _editorDefaultLineEnding); } - private static void InitializeTextWrappingSettings() + public static void InitializeTextWrappingSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultTextWrappingStr) is string textWrappingStr && Enum.TryParse(typeof(TextWrapping), textWrappingStr, out var textWrapping)) @@ -373,9 +382,11 @@ private static void InitializeTextWrappingSettings() { _editorDefaultTextWrapping = TextWrapping.NoWrap; } + + if (invokeChangedEvent) OnDefaultTextWrappingChanged?.Invoke(null, _editorDefaultTextWrapping); } - private static void InitializeSpellingSettings() + public static void InitializeSpellingSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorHighlightMisspelledWordsBool) is bool highlightMisspelledWords) { @@ -385,9 +396,11 @@ private static void InitializeSpellingSettings() { _isHighlightMisspelledWordsEnabled = false; } + + if (invokeChangedEvent) OnHighlightMisspelledWordsChanged?.Invoke(null, _isHighlightMisspelledWordsEnabled); } - private static void InitializeDisplaySettings() + public static void InitializeDisplayLineHighlighterSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultLineHighlighterViewStateBool) is bool displayLineHighlighter) { @@ -398,6 +411,11 @@ private static void InitializeDisplaySettings() _editorDisplayLineHighlighter = true; } + if (invokeChangedEvent) OnDefaultLineHighlighterViewStateChanged?.Invoke(null, _editorDisplayLineHighlighter); + } + + public static void InitializeDisplayLineNumbersSettings(bool invokeChangedEvent = false) + { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultDisplayLineNumbersBool) is bool displayLineNumbers) { _displayLineNumbers = displayLineNumbers; @@ -406,9 +424,11 @@ private static void InitializeDisplaySettings() { _displayLineNumbers = true; } + + if (invokeChangedEvent) OnDefaultDisplayLineNumbersViewStateChanged?.Invoke(null, _displayLineNumbers); } - private static void InitializeSmartCopySettings() + public static void InitializeSmartCopySettings() { if (ApplicationSettingsStore.Read(SettingsKey.EditorEnableSmartCopyBool) is bool enableSmartCopy) { @@ -420,7 +440,7 @@ private static void InitializeSmartCopySettings() } } - private static void InitializeEncodingSettings() + public static void InitializeEncodingSettings(bool invokeChangedEvent = false) { Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); @@ -446,9 +466,11 @@ private static void InitializeEncodingSettings() { _editorDefaultEncoding = new UTF8Encoding(false); } + + if (invokeChangedEvent) OnDefaultEncodingChanged?.Invoke(null, _editorDefaultEncoding); } - private static void InitializeDecodingSettings() + public static void InitializeDecodingSettings() { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultDecodingCodePageInt) is int decodingCodePage) { @@ -480,7 +502,7 @@ private static void InitializeDecodingSettings() } } - private static void InitializeTabIndentsSettings() + public static void InitializeTabIndentsSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultTabIndentsInt) is int tabIndents) { @@ -490,9 +512,11 @@ private static void InitializeTabIndentsSettings() { _editorDefaultTabIndents = -1; } + + if (invokeChangedEvent) OnDefaultTabIndentsChanged?.Invoke(null, _editorDefaultTabIndents); } - private static void InitializeSearchEngineSettings() + public static void InitializeSearchEngineSettings() { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultSearchEngineStr) is string searchEngineStr && Enum.TryParse(typeof(SearchEngine), searchEngineStr, out var searchEngine)) @@ -503,7 +527,10 @@ private static void InitializeSearchEngineSettings() { _editorDefaultSearchEngine = SearchEngine.Bing; } + } + public static void InitializeCustomSearchUrlSettings() + { if (ApplicationSettingsStore.Read(SettingsKey.EditorCustomMadeSearchUrlStr) is string customMadeSearchUrl) { _editorCustomMadeSearchUrl = customMadeSearchUrl; @@ -514,7 +541,7 @@ private static void InitializeSearchEngineSettings() } } - private static void InitializeFontSettings() + public static void InitializeFontFamilySettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorFontFamilyStr) is string fontFamily) { @@ -525,6 +552,11 @@ private static void InitializeFontSettings() _editorFontFamily = "Consolas"; } + if (invokeChangedEvent) OnFontFamilyChanged?.Invoke(null, _editorFontFamily); + } + + public static void InitializeFontSizeSettings(bool invokeChangedEvent = false) + { if (ApplicationSettingsStore.Read(SettingsKey.EditorFontSizeInt) is int fontSize) { _editorFontSize = fontSize; @@ -534,6 +566,11 @@ private static void InitializeFontSettings() _editorFontSize = 14; } + if (invokeChangedEvent) OnFontSizeChanged?.Invoke(null, _editorFontSize); + } + + public static void InitializeFontStyleSettings(bool invokeChangedEvent = false) + { if (ApplicationSettingsStore.Read(SettingsKey.EditorFontStyleStr) is string fontStyleStr && Enum.TryParse(typeof(FontStyle), fontStyleStr, out var fontStyle)) { @@ -544,6 +581,11 @@ private static void InitializeFontSettings() _editorFontStyle = FontStyle.Normal; } + if (invokeChangedEvent) OnFontStyleChanged?.Invoke(null, _editorFontStyle); + } + + public static void InitializeFontWeightSettings(bool invokeChangedEvent = false) + { if (ApplicationSettingsStore.Read(SettingsKey.EditorFontWeightUshort) is ushort fontWeight) { _editorFontWeight = new FontWeight() @@ -555,9 +597,11 @@ private static void InitializeFontSettings() { _editorFontWeight = FontWeights.Normal; } + + if (invokeChangedEvent) OnFontWeightChanged?.Invoke(null, _editorFontWeight); } - private static void InitializeAppOpeningPreferencesSettings() + public static void InitializeAppOpeningPreferencesSettings() { if (ApplicationSettingsStore.Read(SettingsKey.AlwaysOpenNewWindowBool) is bool alwaysOpenNewWindow) { diff --git a/src/Notepads/Services/InterInstanceSyncService.cs b/src/Notepads/Services/InterInstanceSyncService.cs new file mode 100644 index 000000000..751040a5b --- /dev/null +++ b/src/Notepads/Services/InterInstanceSyncService.cs @@ -0,0 +1,69 @@ +namespace Notepads.Services +{ + using Notepads.Extensions; + using Notepads.Settings; + using Notepads.Views.MainPage; + using System; + using System.Collections.Generic; + using Windows.Storage; + + public static class InterInstanceSyncService + { + private static NotepadsMainPage _notepadsMainPage = null; + + public static readonly string OpenRecentKey = "BuildOpenRecentButtonSubItems"; + + public static IReadOnlyDictionary SyncManager = new Dictionary + { + {SettingsKey.AppBackgroundTintOpacityDouble, () => ThemeSettingsService.InitializeAppBackgroundPanelTintOpacity(true)}, + {SettingsKey.RequestedThemeStr, () => ThemeSettingsService.InitializeThemeMode(true)}, + {SettingsKey.UseWindowsAccentColorBool, () => { } }, + {SettingsKey.AppAccentColorHexStr, () => { } }, + {SettingsKey.CustomAccentColorHexStr, () => ThemeSettingsService.InitializeCustomAccentColor()}, + {SettingsKey.EditorDefaultLineHighlighterViewStateBool, () => AppSettingsService.InitializeDisplayLineHighlighterSettings(true)}, + {SettingsKey.EditorDefaultDisplayLineNumbersBool, () => AppSettingsService.InitializeDisplayLineNumbersSettings(true)}, + {SettingsKey.EditorDefaultTabIndentsInt, () => AppSettingsService.InitializeTabIndentsSettings(true)}, + {SettingsKey.EditorDefaultTextWrappingStr, () => AppSettingsService.InitializeTextWrappingSettings(true)}, + {SettingsKey.EditorFontFamilyStr, () => AppSettingsService.InitializeFontFamilySettings(true)}, + {SettingsKey.EditorFontSizeInt, () => AppSettingsService.InitializeFontSizeSettings(true)}, + {SettingsKey.EditorFontStyleStr, () => AppSettingsService.InitializeFontStyleSettings(true)}, + {SettingsKey.EditorFontWeightUshort, () => AppSettingsService.InitializeFontWeightSettings(true)}, + {SettingsKey.EditorHighlightMisspelledWordsBool, () => AppSettingsService.InitializeSpellingSettings(true)}, + {SettingsKey.EditorDefaultEncodingCodePageInt, () => AppSettingsService.InitializeEncodingSettings(true)}, + {SettingsKey.EditorDefaultLineEndingStr, () => AppSettingsService.InitializeLineEndingSettings(true)}, + {SettingsKey.EditorShowStatusBarBool, () => AppSettingsService.InitializeStatusBarSettings(true)}, + {SettingsKey.EditorCustomMadeSearchUrlStr, () => AppSettingsService.InitializeCustomSearchUrlSettings()}, + {SettingsKey.EditorDefaultDecodingCodePageInt, () => AppSettingsService.InitializeDecodingSettings()}, + {SettingsKey.EditorDefaultSearchEngineStr, () => AppSettingsService.InitializeSearchEngineSettings()}, + {SettingsKey.EditorEnableSmartCopyBool, () => AppSettingsService.InitializeSmartCopySettings() }, + {SettingsKey.AlwaysOpenNewWindowBool, () => AppSettingsService.InitializeAppOpeningPreferencesSettings() }, + {OpenRecentKey, async () => await _notepadsMainPage.BuildOpenRecentButtonSubItems(false) } + }; + + public static void Initialize(NotepadsMainPage page) + { + _notepadsMainPage = page; + ApplicationData.Current.DataChanged += Application_OnDataChanged; + } + + private static async void Application_OnDataChanged(ApplicationData sender, object args) + { + if (ApplicationSettingsStore.Read(SettingsKey.LastChangedSettingsAppInstanceIdStr) is string lastChangedSettingsAppInstanceIdStr && + lastChangedSettingsAppInstanceIdStr == App.Id.ToString()) + { + return; + } + + if (ApplicationSettingsStore.Read(SettingsKey.LastChangedSettingsKeyStr) is string lastChangedSettingsKeyStr && + SyncManager.ContainsKey(lastChangedSettingsKeyStr) && _notepadsMainPage != null) + { + await DispatcherExtensions.CallOnUIThreadAsync(_notepadsMainPage.Dispatcher, () => + { + if (lastChangedSettingsKeyStr != OpenRecentKey) _notepadsMainPage.CloseSettingsPane(); + SyncManager[lastChangedSettingsKeyStr].Invoke(); + ThemeSettingsService.InitializeAppAccentColor(true); + }); + } + } + } +} diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index c1a438b81..c3c1e1695 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -18,32 +18,22 @@ public static class ThemeSettingsService public static event EventHandler OnBackgroundChanged; public static event EventHandler OnAccentColorChanged; - public static ElementTheme ThemeMode { get; set; } - private static readonly UISettings UISettings = new UISettings(); private static readonly ThemeListener ThemeListener = new ThemeListener(); private static Brush _currentAppBackgroundBrush; - private static bool _useWindowsTheme; + private static ElementTheme _themeMode; - public static bool UseWindowsTheme + public static ElementTheme ThemeMode { - get => _useWindowsTheme; + get => _themeMode; set { - if (value != _useWindowsTheme) + if (value != _themeMode) { - _useWindowsTheme = value; - if (value) - { - var currentWindowsTheme = Application.Current.RequestedTheme.ToElementTheme(); - if (ThemeMode != currentWindowsTheme) - { - ThemeMode = currentWindowsTheme; - OnThemeChanged?.Invoke(null, ThemeMode); - } - } - ApplicationSettingsStore.Write(SettingsKey.UseWindowsThemeBool, _useWindowsTheme); + _themeMode = value; + OnThemeChanged?.Invoke(null, value); + ApplicationSettingsStore.Write(SettingsKey.RequestedThemeStr, value.ToString()); } } } @@ -113,7 +103,7 @@ public static void Initialize() InitializeAppBackgroundPanelTintOpacity(); } - private static void InitializeAppAccentColor() + public static void InitializeAppAccentColor(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.UseWindowsAccentColorBool) is bool useWindowsAccentColor) { @@ -135,9 +125,11 @@ private static void InitializeAppAccentColor() _appAccentColor = accentColorHexStr.ToColor(); } } + + if (invokeChangedEvent) OnAccentColorChanged?.Invoke(null, _appAccentColor); } - private static void InitializeCustomAccentColor() + public static void InitializeCustomAccentColor() { if (ApplicationSettingsStore.Read(SettingsKey.CustomAccentColorHexStr) is string customAccentColorHexStr) { @@ -157,7 +149,7 @@ private static void UiSettings_ColorValuesChanged(UISettings sender, object args } } - private static void InitializeAppBackgroundPanelTintOpacity() + public static void InitializeAppBackgroundPanelTintOpacity(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.AppBackgroundTintOpacityDouble) is double tintOpacity) { @@ -167,51 +159,32 @@ private static void InitializeAppBackgroundPanelTintOpacity() { _appBackgroundPanelTintOpacity = 0.75; } + + if (invokeChangedEvent) OnBackgroundChanged?.Invoke(null, GetAppBackgroundBrush(ThemeMode)); } - private static void InitializeThemeMode() + public static void InitializeThemeMode(bool invokeChangedEvent = false) { - if (ApplicationSettingsStore.Read(SettingsKey.UseWindowsThemeBool) is bool useWindowsTheme) - { - _useWindowsTheme = useWindowsTheme; - } - else - { - _useWindowsTheme = true; - } - ThemeListener.ThemeChanged += ThemeListener_ThemeChanged; - ThemeMode = Application.Current.RequestedTheme.ToElementTheme(); - - if (!UseWindowsTheme) + if (ApplicationSettingsStore.Read(SettingsKey.RequestedThemeStr) is string themeModeStr) { - if (ApplicationSettingsStore.Read(SettingsKey.RequestedThemeStr) is string themeModeStr) + if (Enum.TryParse(typeof(ElementTheme), themeModeStr, out var theme)) { - if (Enum.TryParse(typeof(ElementTheme), themeModeStr, out var theme)) - { - ThemeMode = (ElementTheme)theme; - } + _themeMode = (ElementTheme)theme; } } - } - - private static void ThemeListener_ThemeChanged(ThemeListener sender) - { - if (UseWindowsTheme) + else { - SetTheme(sender.CurrentTheme.ToElementTheme()); + _themeMode = ElementTheme.Default; } + + if (invokeChangedEvent) OnThemeChanged?.Invoke(null, ThemeMode); } - public static void SetTheme(ElementTheme theme) + private static void ThemeListener_ThemeChanged(ThemeListener sender) { - if (ThemeMode != theme) - { - ThemeMode = theme; - ApplicationSettingsStore.Write(SettingsKey.RequestedThemeStr, ThemeMode.ToString()); - OnThemeChanged?.Invoke(null, theme); - } + _themeMode = sender.CurrentTheme.ToElementTheme(); } public static void SetRequestedTheme(Panel backgroundPanel, UIElement currentContent, ApplicationViewTitleBar titleBar) @@ -235,7 +208,7 @@ public static void SetRequestedTheme(Panel backgroundPanel, UIElement currentCon // Set ContentDialog background dimming color ((SolidColorBrush)Application.Current.Resources["SystemControlPageBackgroundMediumAltMediumBrush"]).Color = - ThemeMode == ElementTheme.Dark ? Color.FromArgb(153, 0, 0, 0) : Color.FromArgb(153, 255, 255, 255); + GetActualTheme(ThemeMode) == ElementTheme.Dark ? Color.FromArgb(153, 0, 0, 0) : Color.FromArgb(153, 255, 255, 255); if (DialogManager.ActiveDialog != null) { @@ -264,11 +237,20 @@ public static ElementTheme ToElementTheme(this ApplicationTheme theme) } } + public static ElementTheme GetActualTheme(ElementTheme theme) + { + if (theme == ElementTheme.Default) + return Application.Current.RequestedTheme.ToElementTheme(); + else + return theme; + } + private static Brush GetAppBackgroundBrush(ElementTheme theme) { var darkModeBaseColor = Color.FromArgb(255, 46, 46, 46); var lightModeBaseColor = Color.FromArgb(255, 240, 240, 240); + theme = GetActualTheme(theme); var baseColor = theme == ElementTheme.Light ? lightModeBaseColor : darkModeBaseColor; if (AppBackgroundPanelTintOpacity > 0.99f || @@ -291,6 +273,8 @@ private static Brush GetAppBackgroundBrush(ElementTheme theme) public static void ApplyThemeForTitleBarButtons(ApplicationViewTitleBar titleBar, ElementTheme theme) { + theme = GetActualTheme(theme); + if (theme == ElementTheme.Dark) { // Set active window colors diff --git a/src/Notepads/Settings/ApplicationSettings.cs b/src/Notepads/Settings/ApplicationSettings.cs index c0e682984..e994e1b66 100644 --- a/src/Notepads/Settings/ApplicationSettings.cs +++ b/src/Notepads/Settings/ApplicationSettings.cs @@ -23,6 +23,13 @@ public static void Write(string key, object obj) { ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values[key] = obj; + + if (InterInstanceSyncService.SyncManager.ContainsKey(key)) + { + localSettings.Values[SettingsKey.LastChangedSettingsKeyStr] = key; + localSettings.Values[SettingsKey.LastChangedSettingsAppInstanceIdStr] = App.Id.ToString(); + ApplicationData.Current.SignalDataChanged(); + } } public static bool Remove(string key) diff --git a/src/Notepads/Settings/SettingsKey.cs b/src/Notepads/Settings/SettingsKey.cs index 245afdf1b..5fbed1313 100644 --- a/src/Notepads/Settings/SettingsKey.cs +++ b/src/Notepads/Settings/SettingsKey.cs @@ -7,10 +7,11 @@ internal static class SettingsKey internal static string IsJumpListOutOfDateBool = "IsJumpListOutOfDateBool"; internal static string ActiveInstanceIdStr = "ActiveInstanceIdStr"; internal static string AlwaysOpenNewWindowBool = "AlwaysOpenNewWindowBool"; + internal static string LastChangedSettingsKeyStr = "LastChangedSettingsKeyStr"; + internal static string LastChangedSettingsAppInstanceIdStr = "LastChangedSettingsAppInstanceIdStr"; // Theme related internal static string RequestedThemeStr = "RequestedThemeStr"; - internal static string UseWindowsThemeBool = "UseWindowsThemeBool"; internal static string AppBackgroundTintOpacityDouble = "AppBackgroundTintOpacityDouble"; internal static string AppAccentColorHexStr = "AppAccentColorHexStr"; internal static string CustomAccentColorHexStr = "CustomAccentColorHexStr"; diff --git a/src/Notepads/Strings/en-US/Resources.resw b/src/Notepads/Strings/en-US/Resources.resw index b5ec406ab..18a0d0367 100644 --- a/src/Notepads/Strings/en-US/Resources.resw +++ b/src/Notepads/Strings/en-US/Resources.resw @@ -438,7 +438,7 @@ App: DragAndDrop UIOverride Caption: "Open with Notepads" display text - This is a shadow window of Notepads. Session snapshot and settings are disabled. + This is a shadow window of Notepads. Session snapshot is disabled. App: ShadowWindowIndicator Description display text. diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs index eb407df80..740e3a5df 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs @@ -11,6 +11,7 @@ using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Media; using Notepads.Services; + using Notepads.Settings; public sealed partial class NotepadsMainPage { @@ -34,8 +35,7 @@ private void InitializeMainMenu() if (!App.IsFirstInstance) { - MainMenuButton.Foreground = new SolidColorBrush(ThemeSettingsService.AppAccentColor); - MenuSettingsButton.IsEnabled = false; + MainMenuButton.Foreground = (SolidColorBrush)Application.Current.Resources["SystemControlForegroundAccentBrush"]; } if (App.IsGameBarWidget) @@ -106,7 +106,7 @@ private void MainMenuButtonFlyout_Opening(object sender, object e) MenuSaveAllButton.IsEnabled = NotepadsCore.HaveUnsavedTextEditor(); } - private async Task BuildOpenRecentButtonSubItems() + public async Task BuildOpenRecentButtonSubItems(bool invokeAfterChanged = true) { var openRecentSubItem = new MenuFlyoutSubItem { @@ -168,6 +168,12 @@ private async Task BuildOpenRecentButtonSubItems() var indexToInsert = MainMenuButtonFlyout.Items.IndexOf(MenuOpenFileButton) + 1; MainMenuButtonFlyout.Items.Insert(indexToInsert, openRecentSubItem); } + + if (invokeAfterChanged) + { + ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsKeyStr, InterInstanceSyncService.OpenRecentKey); + ApplicationData.Current.SignalDataChanged(); + } } } } \ No newline at end of file diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs index 7b02764de..3ae329436 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml.cs @@ -274,6 +274,8 @@ private async void Sets_Loaded(object sender, RoutedEventArgs e) Window.Current.CoreWindow.Activated -= CoreWindow_Activated; Window.Current.CoreWindow.Activated += CoreWindow_Activated; } + + InterInstanceSyncService.Initialize(this); } private async void App_EnteredBackground(object sender, Windows.ApplicationModel.EnteredBackgroundEventArgs e) @@ -423,6 +425,11 @@ private void HideAllOpenFlyouts() } } + public void CloseSettingsPane() + { + RootSplitView.IsPaneOpen = false; + } + private async void OnSessionBackupAndRestoreOptionChanged(object sender, bool isSessionBackupAndRestoreEnabled) { await Dispatcher.CallOnUIThreadAsync(async () => diff --git a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs index 4ec25a495..764cb0bf0 100644 --- a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs @@ -18,21 +18,17 @@ public PersonalizationSettingsPage() { InitializeComponent(); - if (ThemeSettingsService.UseWindowsTheme) + switch (ThemeSettingsService.ThemeMode) { - ThemeModeDefaultButton.IsChecked = true; - } - else - { - switch (ThemeSettingsService.ThemeMode) - { - case ElementTheme.Light: - ThemeModeLightButton.IsChecked = true; - break; - case ElementTheme.Dark: - ThemeModeDarkButton.IsChecked = true; - break; - } + case ElementTheme.Light: + ThemeModeLightButton.IsChecked = true; + break; + case ElementTheme.Dark: + ThemeModeDarkButton.IsChecked = true; + break; + default: + ThemeModeDefaultButton.IsChecked = true; + break; } AccentColorToggle.IsOn = ThemeSettingsService.UseWindowsAccentColor; @@ -124,15 +120,13 @@ private void ThemeRadioButton_OnChecked(object sender, RoutedEventArgs e) switch (radioButton.Tag) { case "Light": - ThemeSettingsService.UseWindowsTheme = false; - ThemeSettingsService.SetTheme(ElementTheme.Light); + ThemeSettingsService.ThemeMode = ElementTheme.Light; break; case "Dark": - ThemeSettingsService.UseWindowsTheme = false; - ThemeSettingsService.SetTheme(ElementTheme.Dark); + ThemeSettingsService.ThemeMode = ElementTheme.Dark; break; case "Default": - ThemeSettingsService.UseWindowsTheme = true; + ThemeSettingsService.ThemeMode = ElementTheme.Default; break; } } From 281edc7e17ace175410706d4e8d331057bf50583 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Fri, 26 Jun 2020 08:44:38 +0530 Subject: [PATCH 2/6] fixed. --- src/Notepads/App.xaml.cs | 13 ++++++++++ src/Notepads/Services/AppSettingsService.cs | 26 +++++++++---------- src/Notepads/Services/ThemeSettingsService.cs | 8 +++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/Notepads/App.xaml.cs b/src/Notepads/App.xaml.cs index 58641361d..4f8f605bc 100644 --- a/src/Notepads/App.xaml.cs +++ b/src/Notepads/App.xaml.cs @@ -51,6 +51,7 @@ public App() InitializeComponent(); Suspending += OnSuspending; + LeavingBackground += OnLeavingBackground; } /// @@ -197,6 +198,18 @@ private void OnSuspending(object sender, SuspendingEventArgs e) deferral.Complete(); } + /// + /// Occurs when the app moves to foreground from background. + /// Pending changes to the UI is made before app comes to focus. + /// + /// The source of the leaving background request. + /// Details about the leaving background request. + private void OnLeavingBackground(object sender, LeavingBackgroundEventArgs e) + { + ThemeSettingsService.Initialize(true); + AppSettingsService.Initialize(true); + } + // Occurs when an exception is not handled on the UI thread. private static void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) { diff --git a/src/Notepads/Services/AppSettingsService.cs b/src/Notepads/Services/AppSettingsService.cs index 3966aa59d..d395259b6 100644 --- a/src/Notepads/Services/AppSettingsService.cs +++ b/src/Notepads/Services/AppSettingsService.cs @@ -284,34 +284,34 @@ public static bool IsSmartCopyEnabled } } - public static void Initialize() + public static void Initialize(bool shouldInvokeChangedEvent = false) { - InitializeFontFamilySettings(); - InitializeFontSizeSettings(); - InitializeFontStyleSettings(); - InitializeFontWeightSettings(); + InitializeFontFamilySettings(shouldInvokeChangedEvent); + InitializeFontSizeSettings(shouldInvokeChangedEvent); + InitializeFontStyleSettings(shouldInvokeChangedEvent); + InitializeFontWeightSettings(shouldInvokeChangedEvent); - InitializeTextWrappingSettings(); + InitializeTextWrappingSettings(shouldInvokeChangedEvent); - InitializeSpellingSettings(); + InitializeSpellingSettings(shouldInvokeChangedEvent); - InitializeDisplayLineHighlighterSettings(); - InitializeDisplayLineNumbersSettings(); + InitializeDisplayLineHighlighterSettings(shouldInvokeChangedEvent); + InitializeDisplayLineNumbersSettings(shouldInvokeChangedEvent); InitializeSmartCopySettings(); - InitializeLineEndingSettings(); + InitializeLineEndingSettings(shouldInvokeChangedEvent); - InitializeEncodingSettings(); + InitializeEncodingSettings(shouldInvokeChangedEvent); InitializeDecodingSettings(); - InitializeTabIndentsSettings(); + InitializeTabIndentsSettings(shouldInvokeChangedEvent); InitializeSearchEngineSettings(); InitializeCustomSearchUrlSettings(); - InitializeStatusBarSettings(); + InitializeStatusBarSettings(shouldInvokeChangedEvent); InitializeSessionSnapshotSettings(); diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index c3c1e1695..993595fcf 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -92,15 +92,15 @@ public static Color CustomAccentColor } } - public static void Initialize() + public static void Initialize(bool shouldInvokeChangedEvent = false) { - InitializeThemeMode(); + InitializeThemeMode(shouldInvokeChangedEvent); - InitializeAppAccentColor(); + InitializeAppAccentColor(shouldInvokeChangedEvent); InitializeCustomAccentColor(); - InitializeAppBackgroundPanelTintOpacity(); + InitializeAppBackgroundPanelTintOpacity(shouldInvokeChangedEvent); } public static void InitializeAppAccentColor(bool invokeChangedEvent = false) From 6a9131a65c05107b1abdf62307146fa5473e129d Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Sat, 27 Jun 2020 20:10:09 +0530 Subject: [PATCH 3/6] fixed. --- src/Notepads/Services/AppSettingsService.cs | 24 ++++---- .../Services/InterInstanceSyncService.cs | 55 +++++++++---------- src/Notepads/Services/ThemeSettingsService.cs | 4 +- .../MainPage/NotepadsMainPage.MainMenu.cs | 3 +- .../PersonalizationSettingsPage.xaml.cs | 2 +- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Notepads/Services/AppSettingsService.cs b/src/Notepads/Services/AppSettingsService.cs index d395259b6..5e65d62b3 100644 --- a/src/Notepads/Services/AppSettingsService.cs +++ b/src/Notepads/Services/AppSettingsService.cs @@ -298,24 +298,24 @@ public static void Initialize(bool shouldInvokeChangedEvent = false) InitializeDisplayLineHighlighterSettings(shouldInvokeChangedEvent); InitializeDisplayLineNumbersSettings(shouldInvokeChangedEvent); - InitializeSmartCopySettings(); + InitializeSmartCopySettings(shouldInvokeChangedEvent); InitializeLineEndingSettings(shouldInvokeChangedEvent); InitializeEncodingSettings(shouldInvokeChangedEvent); - InitializeDecodingSettings(); + InitializeDecodingSettings(shouldInvokeChangedEvent); InitializeTabIndentsSettings(shouldInvokeChangedEvent); - InitializeSearchEngineSettings(); - InitializeCustomSearchUrlSettings(); + InitializeSearchEngineSettings(shouldInvokeChangedEvent); + InitializeCustomSearchUrlSettings(shouldInvokeChangedEvent); InitializeStatusBarSettings(shouldInvokeChangedEvent); - InitializeSessionSnapshotSettings(); + InitializeSessionSnapshotSettings(shouldInvokeChangedEvent); - InitializeAppOpeningPreferencesSettings(); + InitializeAppOpeningPreferencesSettings(shouldInvokeChangedEvent); } public static void InitializeStatusBarSettings(bool invokeChangedEvent = false) @@ -332,7 +332,7 @@ public static void InitializeStatusBarSettings(bool invokeChangedEvent = false) if (invokeChangedEvent) OnStatusBarVisibilityChanged?.Invoke(null, _showStatusBar); } - private static void InitializeSessionSnapshotSettings() + private static void InitializeSessionSnapshotSettings(bool invokeChangedEvent = false) { // We should disable session snapshot feature on multi instances if (!App.IsFirstInstance) @@ -428,7 +428,7 @@ public static void InitializeDisplayLineNumbersSettings(bool invokeChangedEvent if (invokeChangedEvent) OnDefaultDisplayLineNumbersViewStateChanged?.Invoke(null, _displayLineNumbers); } - public static void InitializeSmartCopySettings() + public static void InitializeSmartCopySettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorEnableSmartCopyBool) is bool enableSmartCopy) { @@ -470,7 +470,7 @@ public static void InitializeEncodingSettings(bool invokeChangedEvent = false) if (invokeChangedEvent) OnDefaultEncodingChanged?.Invoke(null, _editorDefaultEncoding); } - public static void InitializeDecodingSettings() + public static void InitializeDecodingSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultDecodingCodePageInt) is int decodingCodePage) { @@ -516,7 +516,7 @@ public static void InitializeTabIndentsSettings(bool invokeChangedEvent = false) if (invokeChangedEvent) OnDefaultTabIndentsChanged?.Invoke(null, _editorDefaultTabIndents); } - public static void InitializeSearchEngineSettings() + public static void InitializeSearchEngineSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorDefaultSearchEngineStr) is string searchEngineStr && Enum.TryParse(typeof(SearchEngine), searchEngineStr, out var searchEngine)) @@ -529,7 +529,7 @@ public static void InitializeSearchEngineSettings() } } - public static void InitializeCustomSearchUrlSettings() + public static void InitializeCustomSearchUrlSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.EditorCustomMadeSearchUrlStr) is string customMadeSearchUrl) { @@ -601,7 +601,7 @@ public static void InitializeFontWeightSettings(bool invokeChangedEvent = false) if (invokeChangedEvent) OnFontWeightChanged?.Invoke(null, _editorFontWeight); } - public static void InitializeAppOpeningPreferencesSettings() + public static void InitializeAppOpeningPreferencesSettings(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.AlwaysOpenNewWindowBool) is bool alwaysOpenNewWindow) { diff --git a/src/Notepads/Services/InterInstanceSyncService.cs b/src/Notepads/Services/InterInstanceSyncService.cs index 751040a5b..05176b813 100644 --- a/src/Notepads/Services/InterInstanceSyncService.cs +++ b/src/Notepads/Services/InterInstanceSyncService.cs @@ -11,33 +11,33 @@ public static class InterInstanceSyncService { private static NotepadsMainPage _notepadsMainPage = null; - public static readonly string OpenRecentKey = "BuildOpenRecentButtonSubItems"; + public static readonly string RecentFilesListKey = "BuildOpenRecentButtonSubItems"; - public static IReadOnlyDictionary SyncManager = new Dictionary + public static IReadOnlyDictionary> SyncManager = new Dictionary> { - {SettingsKey.AppBackgroundTintOpacityDouble, () => ThemeSettingsService.InitializeAppBackgroundPanelTintOpacity(true)}, - {SettingsKey.RequestedThemeStr, () => ThemeSettingsService.InitializeThemeMode(true)}, - {SettingsKey.UseWindowsAccentColorBool, () => { } }, - {SettingsKey.AppAccentColorHexStr, () => { } }, - {SettingsKey.CustomAccentColorHexStr, () => ThemeSettingsService.InitializeCustomAccentColor()}, - {SettingsKey.EditorDefaultLineHighlighterViewStateBool, () => AppSettingsService.InitializeDisplayLineHighlighterSettings(true)}, - {SettingsKey.EditorDefaultDisplayLineNumbersBool, () => AppSettingsService.InitializeDisplayLineNumbersSettings(true)}, - {SettingsKey.EditorDefaultTabIndentsInt, () => AppSettingsService.InitializeTabIndentsSettings(true)}, - {SettingsKey.EditorDefaultTextWrappingStr, () => AppSettingsService.InitializeTextWrappingSettings(true)}, - {SettingsKey.EditorFontFamilyStr, () => AppSettingsService.InitializeFontFamilySettings(true)}, - {SettingsKey.EditorFontSizeInt, () => AppSettingsService.InitializeFontSizeSettings(true)}, - {SettingsKey.EditorFontStyleStr, () => AppSettingsService.InitializeFontStyleSettings(true)}, - {SettingsKey.EditorFontWeightUshort, () => AppSettingsService.InitializeFontWeightSettings(true)}, - {SettingsKey.EditorHighlightMisspelledWordsBool, () => AppSettingsService.InitializeSpellingSettings(true)}, - {SettingsKey.EditorDefaultEncodingCodePageInt, () => AppSettingsService.InitializeEncodingSettings(true)}, - {SettingsKey.EditorDefaultLineEndingStr, () => AppSettingsService.InitializeLineEndingSettings(true)}, - {SettingsKey.EditorShowStatusBarBool, () => AppSettingsService.InitializeStatusBarSettings(true)}, - {SettingsKey.EditorCustomMadeSearchUrlStr, () => AppSettingsService.InitializeCustomSearchUrlSettings()}, - {SettingsKey.EditorDefaultDecodingCodePageInt, () => AppSettingsService.InitializeDecodingSettings()}, - {SettingsKey.EditorDefaultSearchEngineStr, () => AppSettingsService.InitializeSearchEngineSettings()}, - {SettingsKey.EditorEnableSmartCopyBool, () => AppSettingsService.InitializeSmartCopySettings() }, - {SettingsKey.AlwaysOpenNewWindowBool, () => AppSettingsService.InitializeAppOpeningPreferencesSettings() }, - {OpenRecentKey, async () => await _notepadsMainPage.BuildOpenRecentButtonSubItems(false) } + {SettingsKey.AppBackgroundTintOpacityDouble, ThemeSettingsService.InitializeAppBackgroundPanelTintOpacity }, + {SettingsKey.RequestedThemeStr, ThemeSettingsService.InitializeThemeMode }, + {SettingsKey.UseWindowsAccentColorBool, ThemeSettingsService.InitializeAppAccentColor }, + {SettingsKey.AppAccentColorHexStr, ThemeSettingsService.InitializeAppAccentColor }, + {SettingsKey.CustomAccentColorHexStr, ThemeSettingsService.InitializeCustomAccentColor }, + {SettingsKey.EditorDefaultLineHighlighterViewStateBool, AppSettingsService.InitializeDisplayLineHighlighterSettings }, + {SettingsKey.EditorDefaultDisplayLineNumbersBool, AppSettingsService.InitializeDisplayLineNumbersSettings }, + {SettingsKey.EditorDefaultTabIndentsInt, AppSettingsService.InitializeTabIndentsSettings }, + {SettingsKey.EditorDefaultTextWrappingStr, AppSettingsService.InitializeTextWrappingSettings }, + {SettingsKey.EditorFontFamilyStr, AppSettingsService.InitializeFontFamilySettings }, + {SettingsKey.EditorFontSizeInt, AppSettingsService.InitializeFontSizeSettings }, + {SettingsKey.EditorFontStyleStr, AppSettingsService.InitializeFontStyleSettings }, + {SettingsKey.EditorFontWeightUshort, AppSettingsService.InitializeFontWeightSettings }, + {SettingsKey.EditorHighlightMisspelledWordsBool, AppSettingsService.InitializeSpellingSettings }, + {SettingsKey.EditorDefaultEncodingCodePageInt, AppSettingsService.InitializeEncodingSettings }, + {SettingsKey.EditorDefaultLineEndingStr, AppSettingsService.InitializeLineEndingSettings }, + {SettingsKey.EditorShowStatusBarBool, AppSettingsService.InitializeStatusBarSettings }, + {SettingsKey.EditorCustomMadeSearchUrlStr, AppSettingsService.InitializeCustomSearchUrlSettings }, + {SettingsKey.EditorDefaultDecodingCodePageInt, AppSettingsService.InitializeDecodingSettings }, + {SettingsKey.EditorDefaultSearchEngineStr, AppSettingsService.InitializeSearchEngineSettings }, + {SettingsKey.EditorEnableSmartCopyBool, AppSettingsService.InitializeSmartCopySettings }, + {SettingsKey.AlwaysOpenNewWindowBool, AppSettingsService.InitializeAppOpeningPreferencesSettings }, + {RecentFilesListKey, async (permission) => await _notepadsMainPage.BuildOpenRecentButtonSubItems(!permission) } }; public static void Initialize(NotepadsMainPage page) @@ -59,9 +59,8 @@ private static async void Application_OnDataChanged(ApplicationData sender, obje { await DispatcherExtensions.CallOnUIThreadAsync(_notepadsMainPage.Dispatcher, () => { - if (lastChangedSettingsKeyStr != OpenRecentKey) _notepadsMainPage.CloseSettingsPane(); - SyncManager[lastChangedSettingsKeyStr].Invoke(); - ThemeSettingsService.InitializeAppAccentColor(true); + if (lastChangedSettingsKeyStr != RecentFilesListKey) _notepadsMainPage.CloseSettingsPane(); + SyncManager[lastChangedSettingsKeyStr].Invoke(true); }); } } diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index 993595fcf..548b73458 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -98,7 +98,7 @@ public static void Initialize(bool shouldInvokeChangedEvent = false) InitializeAppAccentColor(shouldInvokeChangedEvent); - InitializeCustomAccentColor(); + InitializeCustomAccentColor(shouldInvokeChangedEvent); InitializeAppBackgroundPanelTintOpacity(shouldInvokeChangedEvent); } @@ -129,7 +129,7 @@ public static void InitializeAppAccentColor(bool invokeChangedEvent = false) if (invokeChangedEvent) OnAccentColorChanged?.Invoke(null, _appAccentColor); } - public static void InitializeCustomAccentColor() + public static void InitializeCustomAccentColor(bool invokeChangedEvent = false) { if (ApplicationSettingsStore.Read(SettingsKey.CustomAccentColorHexStr) is string customAccentColorHexStr) { diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs index 740e3a5df..c5ace665d 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs @@ -171,7 +171,8 @@ public async Task BuildOpenRecentButtonSubItems(bool invokeAfterChanged = true) if (invokeAfterChanged) { - ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsKeyStr, InterInstanceSyncService.OpenRecentKey); + ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsKeyStr, InterInstanceSyncService.RecentFilesListKey); + ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsAppInstanceIdStr, App.Id.ToString()); ApplicationData.Current.SignalDataChanged(); } } diff --git a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs index 764cb0bf0..2ab069ea1 100644 --- a/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs +++ b/src/Notepads/Views/Settings/PersonalizationSettingsPage.xaml.cs @@ -136,8 +136,8 @@ private void AccentColorPicker_OnColorChanged(ColorPicker sender, ColorChangedEv { if (AccentColorPicker.IsEnabled) { - ThemeSettingsService.AppAccentColor = args.NewColor; if (!AccentColorToggle.IsOn) ThemeSettingsService.CustomAccentColor = args.NewColor; + ThemeSettingsService.AppAccentColor = args.NewColor; } } From 1cb689016a2fb3e59a3435262c716ebe3f151f43 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Sat, 27 Jun 2020 20:33:39 +0530 Subject: [PATCH 4/6] fixed. --- src/Notepads/Settings/ApplicationSettings.cs | 21 +++++++++++-------- .../MainPage/NotepadsMainPage.MainMenu.cs | 7 +------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Notepads/Settings/ApplicationSettings.cs b/src/Notepads/Settings/ApplicationSettings.cs index e994e1b66..05d607f45 100644 --- a/src/Notepads/Settings/ApplicationSettings.cs +++ b/src/Notepads/Settings/ApplicationSettings.cs @@ -6,14 +6,15 @@ public static class ApplicationSettingsStore { + private static readonly ApplicationDataContainer _localSettings = ApplicationData.Current.LocalSettings; + public static object Read(string key) { object obj = null; - ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; - if (localSettings.Values.ContainsKey(key)) + if (_localSettings.Values.ContainsKey(key)) { - obj = localSettings.Values[key]; + obj = _localSettings.Values[key]; } return obj; @@ -21,13 +22,16 @@ public static object Read(string key) public static void Write(string key, object obj) { - ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; - localSettings.Values[key] = obj; + _localSettings.Values[key] = obj; + SignalDataChanged(key); + } + public static void SignalDataChanged(string key) + { if (InterInstanceSyncService.SyncManager.ContainsKey(key)) { - localSettings.Values[SettingsKey.LastChangedSettingsKeyStr] = key; - localSettings.Values[SettingsKey.LastChangedSettingsAppInstanceIdStr] = App.Id.ToString(); + _localSettings.Values[SettingsKey.LastChangedSettingsKeyStr] = key; + _localSettings.Values[SettingsKey.LastChangedSettingsAppInstanceIdStr] = App.Id.ToString(); ApplicationData.Current.SignalDataChanged(); } } @@ -36,8 +40,7 @@ public static bool Remove(string key) { try { - ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; - return localSettings.Values.Remove(key); + return _localSettings.Values.Remove(key); } catch (Exception ex) { diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs index c5ace665d..df7688ef0 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.MainMenu.cs @@ -169,12 +169,7 @@ public async Task BuildOpenRecentButtonSubItems(bool invokeAfterChanged = true) MainMenuButtonFlyout.Items.Insert(indexToInsert, openRecentSubItem); } - if (invokeAfterChanged) - { - ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsKeyStr, InterInstanceSyncService.RecentFilesListKey); - ApplicationSettingsStore.Write(SettingsKey.LastChangedSettingsAppInstanceIdStr, App.Id.ToString()); - ApplicationData.Current.SignalDataChanged(); - } + if (invokeAfterChanged) ApplicationSettingsStore.SignalDataChanged(InterInstanceSyncService.RecentFilesListKey); } } } \ No newline at end of file From 780a2a6d64ae2624a17029c5529e8bee8df0b379 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Sun, 28 Jun 2020 02:53:50 +0530 Subject: [PATCH 5/6] fixed. --- src/Notepads/Services/InterInstanceSyncService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Notepads/Services/InterInstanceSyncService.cs b/src/Notepads/Services/InterInstanceSyncService.cs index 05176b813..f0de7c05a 100644 --- a/src/Notepads/Services/InterInstanceSyncService.cs +++ b/src/Notepads/Services/InterInstanceSyncService.cs @@ -13,7 +13,7 @@ public static class InterInstanceSyncService public static readonly string RecentFilesListKey = "BuildOpenRecentButtonSubItems"; - public static IReadOnlyDictionary> SyncManager = new Dictionary> + public static readonly IReadOnlyDictionary> SyncManager = new Dictionary> { {SettingsKey.AppBackgroundTintOpacityDouble, ThemeSettingsService.InitializeAppBackgroundPanelTintOpacity }, {SettingsKey.RequestedThemeStr, ThemeSettingsService.InitializeThemeMode }, From 18966728b09f3cec2bda4b8443c393759116fa38 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Wed, 15 Jul 2020 15:04:43 +0530 Subject: [PATCH 6/6] fixed. --- src/Notepads/Settings/ApplicationSettings.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Notepads/Settings/ApplicationSettings.cs b/src/Notepads/Settings/ApplicationSettings.cs index 05d607f45..8c5b785ef 100644 --- a/src/Notepads/Settings/ApplicationSettings.cs +++ b/src/Notepads/Settings/ApplicationSettings.cs @@ -22,6 +22,8 @@ public static object Read(string key) public static void Write(string key, object obj) { + if (_localSettings.Values.ContainsKey(key) && _localSettings.Values[key].Equals(obj)) return; + _localSettings.Values[key] = obj; SignalDataChanged(key); }