Defer saving customization files.
authorPiotr Czaja <p.czaja@samsung.com>
Thu, 2 Nov 2023 11:30:47 +0000 (12:30 +0100)
committerPiotr Czaja/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <p.czaja@samsung.com>
Wed, 8 Nov 2023 13:11:03 +0000 (14:11 +0100)
Change-Id: Iad29f0a481925bf676610d63bdcba8a61db9f570

SettingCore/GadgetManager.cs
SettingView/SettingView.cs

index 8843704102b1a33879d66168851ec01465ef40fa..5eddcb9cd5651de5c5548162b36034917e3e838f 100644 (file)
@@ -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;
             }
         }
 
index 5cbe59c0afeadec4f919d1bca78fe11ac90b6ccc..f0575e17cf9a7d91231b7120cc6420563eb22142 100644 (file)
@@ -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;
         }