-using System;
+using SettingCore.Views;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using System.Text.Json;
+using System.Text;
using Tizen.NUI;
namespace SettingCore
public class MainMenuInfo
{
public string IconPath { get; set; }
- public Color IconColor { get; set; }
+ public string IconColorHex { get; set; }
public string Title { get; set; }
public string Path { get; set; }
{
try
{
- string text = System.IO.File.ReadAllText(CachePath);
- cache = JsonSerializer.Deserialize<List<MainMenuInfo>>(text);
+ string text = System.IO.File.ReadAllText(CachePath, Encoding.ASCII);
+
+ List<MainMenuInfo> fromCache = new List<MainMenuInfo>();
+
+ string[] mainMenuItems = text.Split("\n\n");
+ foreach (string menu in mainMenuItems)
+ {
+ if (menu.Length == 0) continue;
+ string[] keyValuePairs = menu.Split("\n");
+ Dictionary<string, string> pairs = new Dictionary<string, string>();
+ foreach (string keyValuePair in keyValuePairs)
+ {
+ var kv_split = keyValuePair.Split(':');
+ pairs.Add(kv_split[0], kv_split[1]);
+ }
+
+ fromCache.Add(new MainMenuInfo()
+ {
+ Title = pairs["Title"],
+ IconPath = pairs["IconPath"],
+ IconColorHex = pairs["IconColorHex"],
+ Path = pairs["Path"],
+ });
+ }
+
+ cache = fromCache;
}
catch
{
{
cache.Clear();
cache.AddRange(infos);
- string text = JsonSerializer.Serialize(cache);
+
+ string text = getCacheString();
System.IO.File.WriteAllText(CachePath, text);
}
catch (Exception ex)
}
}
+ private static string getCacheString()
+ {
+ StringBuilder sb = new StringBuilder();
+ foreach (MainMenuInfo info in cache)
+ {
+ sb.Append($"{getCacheString(info)}\n");
+ }
+
+ return sb.ToString();
+ }
+
+ private static string getCacheString(MainMenuInfo mainMenuInfo)
+ {
+ StringBuilder sb = new StringBuilder();
+ foreach (PropertyInfo prop in typeof(MainMenuInfo).GetProperties())
+ {
+ if (!prop.GetMethod.IsStatic)
+ {
+ sb.Append($"{prop.Name}:{prop.GetValue(mainMenuInfo)}\n");
+ }
+ }
+ return sb.ToString();
+ }
+
public static void ClearCache()
{
UpdateCache(new List<MainMenuInfo>());
return null;
}
- Color iconColor = getIconColor(info);
+ string iconColor = getIconColorHex(info);
if (iconColor == null)
{
Logger.Warn($"could not create MainMenuGadget from {info.ClassName} manifest file.");
return new MainMenuInfo
{
IconPath = iconPath,
- IconColor = iconColor,
+ IconColorHex = iconColor,
Title = title,
Path = info.Path,
};
{
Title = cached.Title,
IconPath = cached.IconPath,
- IconColor = cached.IconColor,
+ IconColorHex = cached.IconColorHex,
Path = cached.Path,
};
}
return null;
}
- private static Color getIconColor(SettingGadgetInfo info)
+ private static string getIconColorHex(SettingGadgetInfo info)
{
string iconColorHex = getMetadata(info, $"{metadataNamePrefix}/{info.Path}/{iconColorMetadata}");
if (iconColorHex is null)
return null;
}
bool IsLightTheme = ThemeManager.PlatformThemeId == "org.tizen.default-light-theme";
- Color iconColor = iconColorHex is null ? null : new Color(IsLightTheme ? themeColors[0] : themeColors[1]); ;
+ string iconColor = iconColorHex is null ? null : IsLightTheme ? themeColors[0] : themeColors[1];
return iconColor;
}