PowerToys/Wox.Core/UserSettings/UserSettingStorage.cs

184 lines
5.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2015-10-31 07:17:34 +08:00
using System.Drawing;
using System.Linq;
using Wox.Core.Plugin;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Newtonsoft.Json;
namespace Wox.Core.UserSettings
{
public class UserSettingStorage : JsonStrorage<UserSettingStorage>
{
2014-12-14 23:16:29 +08:00
public bool DontPromptUpdateMsg { get; set; }
2015-01-23 21:52:46 +08:00
public int ActivateTimes { get; set; }
2015-01-21 23:00:56 +08:00
public bool EnableUpdateLog { get; set; }
2014-02-22 11:55:48 +08:00
public string Hotkey { get; set; }
2014-03-23 16:17:41 +08:00
2015-01-02 16:16:09 +08:00
public string Language { get; set; }
public string Theme { get; set; }
2014-03-23 16:17:41 +08:00
2014-03-19 22:17:01 +08:00
public string QueryBoxFont { get; set; }
2014-03-23 16:17:41 +08:00
public string QueryBoxFontStyle { get; set; }
public string QueryBoxFontWeight { get; set; }
public string QueryBoxFontStretch { get; set; }
public string ResultFont { get; set; }
2014-03-23 16:17:41 +08:00
public string ResultFontStyle { get; set; }
public string ResultFontWeight { get; set; }
public string ResultFontStretch { get; set; }
2014-06-16 14:06:24 +08:00
public double WindowLeft { get; set; }
public double WindowTop { get; set; }
// Order defaults to 0 or -1, so 1 will let this property appear last
[JsonProperty(Order = 1)]
public Dictionary<string, CustomizedPluginConfig> CustomizedPluginConfigs { get; set; }
2014-02-22 15:52:20 +08:00
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }
2014-03-23 16:17:41 +08:00
public bool StartWoxOnSystemStartup { get; set; }
2014-03-23 16:17:41 +08:00
[Obsolete]
2014-03-26 17:34:19 +08:00
public double Opacity { get; set; }
[Obsolete]
2014-03-26 17:34:19 +08:00
public OpacityMode OpacityMode { get; set; }
2014-07-18 20:00:55 +08:00
public bool LeaveCmdOpen { get; set; }
2014-04-13 10:08:33 +08:00
public bool HideWhenDeactive { get; set; }
2015-02-20 21:45:42 +08:00
public bool RememberLastLaunchLocation { get; set; }
public bool IgnoreHotkeysOnFullscreen { get; set; }
2014-07-18 20:00:55 +08:00
public string ProxyServer { get; set; }
public bool ProxyEnabled { get; set; }
public int ProxyPort { get; set; }
public string ProxyUserName { get; set; }
public string ProxyPassword { get; set; }
public int MaxResultsToShow { get; set; }
2016-01-07 10:31:17 +08:00
protected override string FileName { get; } = "Settings";
2015-11-10 13:36:08 +08:00
2015-01-23 21:52:46 +08:00
public void IncreaseActivateTimes()
{
ActivateTimes++;
if (ActivateTimes % 15 == 0)
2015-01-23 21:52:46 +08:00
{
Save();
}
}
protected override UserSettingStorage LoadDefault()
2014-03-23 18:14:46 +08:00
{
2014-12-14 23:16:29 +08:00
DontPromptUpdateMsg = false;
2014-03-23 18:14:46 +08:00
Theme = "Dark";
Language = "en";
CustomizedPluginConfigs = new Dictionary<string, CustomizedPluginConfig>();
2014-03-23 18:14:46 +08:00
Hotkey = "Alt + Space";
QueryBoxFont = FontFamily.GenericSansSerif.Name;
ResultFont = FontFamily.GenericSansSerif.Name;
2014-03-26 17:34:19 +08:00
Opacity = 1;
2014-07-18 20:00:55 +08:00
OpacityMode = OpacityMode.Normal;
LeaveCmdOpen = false;
2014-04-13 10:08:33 +08:00
HideWhenDeactive = false;
2015-02-10 23:48:09 +08:00
CustomPluginHotkeys = new List<CustomPluginHotkey>();
2015-02-20 21:45:42 +08:00
RememberLastLaunchLocation = false;
MaxResultsToShow = 6;
return this;
2014-03-23 18:14:46 +08:00
}
2014-03-26 17:34:19 +08:00
protected override void OnAfterLoad(UserSettingStorage storage)
{
var metadatas = PluginManager.AllPlugins.Select(p => p.Metadata);
if (storage.CustomizedPluginConfigs == null)
{
var configs = new Dictionary<string, CustomizedPluginConfig>();
foreach (var metadata in metadatas)
{
addPluginMetadata(configs, metadata);
}
storage.CustomizedPluginConfigs = configs;
}
else
{
var configs = storage.CustomizedPluginConfigs;
foreach (var metadata in metadatas)
{
if (configs.ContainsKey(metadata.ID))
{
var config = configs[metadata.ID];
if (config.ActionKeywords?.Count > 0)
{
metadata.ActionKeywords = config.ActionKeywords;
metadata.ActionKeyword = config.ActionKeywords[0];
}
}
else
{
addPluginMetadata(configs, metadata);
}
}
}
2014-12-27 12:34:51 +08:00
if (storage.QueryBoxFont == null)
{
storage.QueryBoxFont = FontFamily.GenericSansSerif.Name;
}
if (storage.ResultFont == null)
2014-12-27 12:34:51 +08:00
{
storage.ResultFont = FontFamily.GenericSansSerif.Name;
2014-12-27 12:34:51 +08:00
}
2015-01-02 16:16:09 +08:00
if (storage.Language == null)
{
storage.Language = "en";
2015-01-02 16:16:09 +08:00
}
}
private void addPluginMetadata(Dictionary<string, CustomizedPluginConfig> configs, PluginMetadata metadata)
{
configs[metadata.ID] = new CustomizedPluginConfig
{
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords,
Disabled = false
};
}
public void UpdateActionKeyword(PluginMetadata metadata)
{
var config = CustomizedPluginConfigs[metadata.ID];
config.ActionKeywords = metadata.ActionKeywords;
Save();
}
2014-03-26 17:34:19 +08:00
}
public enum OpacityMode
{
Normal = 0,
LayeredWindow = 1,
DWM = 2
}
2015-07-17 15:08:39 +08:00
}