From: Piotr Czaja Date: Thu, 2 Nov 2023 11:30:47 +0000 (+0100) Subject: Defer saving customization files. X-Git-Tag: accepted/tizen/unified/20231120.023124~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47cbf6c4f37daf19d02dae9c25564ecd623d2387;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsettings.git Defer saving customization files. Change-Id: Iad29f0a481925bf676610d63bdcba8a61db9f570 --- diff --git a/SettingCore/GadgetManager.cs b/SettingCore/GadgetManager.cs index 8843704..5eddcb9 100644 --- a/SettingCore/GadgetManager.cs +++ b/SettingCore/GadgetManager.cs @@ -35,6 +35,19 @@ namespace SettingCore _ = UpdateCustomization(backupCust); } + return true; + } + catch (Exception e) + { + Logger.Error($"{e}"); + return false; + } + } + + public void SaveCustomizationToFiles() + { + try + { // save current customization to both files (current and backup) var menuCustItems = installedGadgets.Select(x => new MenuCustomizationItem(x.Path, x.Order)); FileStorage.WriteToFiles(menuCustItems); @@ -43,13 +56,10 @@ namespace SettingCore FileStorage.Instance.Changed += CustFileChanged; FileStorage.Instance.Lost += CustFileLost; FileStorage.Instance.StartMonitoring(); - - return true; } catch (Exception e) { Logger.Error($"{e}"); - return false; } } diff --git a/SettingView/SettingView.cs b/SettingView/SettingView.cs index 5cbe59c..f0575e1 100644 --- a/SettingView/SettingView.cs +++ b/SettingView/SettingView.cs @@ -20,6 +20,7 @@ using SettingView.TextResources; using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Tizen.Applications; using Tizen.NUI; using Tizen.NUI.BaseComponents; @@ -32,6 +33,7 @@ namespace SettingView { private static SettingViewBorder appCustomBorder; private ContentPage mMainPage; + private static Task rowsCreated; public Program(Size2D windowSize, Position2D windowPosition, ThemeOptions themeOptions, IBorderInterface borderInterface) : base(windowSize, windowPosition, themeOptions, borderInterface) @@ -46,6 +48,7 @@ namespace SettingView bool initilized = GadgetManager.Instance.Init(); mMainPage.Content = initilized ? CreateContent() : GetTextNotice("Failed to initialize GadgetManager.\nPlease check error logs for more information.", Color.Red); + _ = SaveCustomization(); var navigator = new SettingNavigation(); navigator.WidthResizePolicy = ResizePolicyType.FillToParent; @@ -91,6 +94,16 @@ namespace SettingView LogScalableInfo(); } + private async Task SaveCustomization() + { + await rowsCreated; + await Task.Run(() => + { + GadgetManager.Instance.SaveCustomizationToFiles(); + return true; + }); + } + private ContentPage CreateMainPage() { var mainPage = new BaseContentPage() @@ -258,7 +271,7 @@ namespace SettingView }, }; - CreateContentRows(visibleMenus, content); + rowsCreated = CreateContentRows(visibleMenus, content); return content; }