PowerToys/Wox.Core/UserSettings/UserSettingStorage.cs

118 lines
4.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
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 Settings
{
public string Hotkey { get; set; } = "Alt + Space";
public string Language { get; set; } = "en";
public string Theme { get; set; } = "Dark";
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
public string QueryBoxFontStyle { get; set; }
public string QueryBoxFontWeight { get; set; }
public string QueryBoxFontStretch { get; set; }
public string ResultFont { get; set; } = FontFamily.GenericSansSerif.Name;
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; }
public int MaxResultsToShow { get; set; } = 6;
public int ActivateTimes { get; set; }
2014-06-16 14:06:24 +08:00
// Order defaults to 0 or -1, so 1 will let this property appear last
[JsonProperty(Order = 1)]
public Dictionary<string, PluginSetting> PluginSettings { get; set; } = new Dictionary<string, PluginSetting>();
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new List<CustomPluginHotkey>();
2014-03-23 16:17:41 +08:00
[Obsolete]
public double Opacity { get; set; } = 1;
2014-03-26 17:34:19 +08:00
[Obsolete]
public OpacityMode OpacityMode { get; set; } = OpacityMode.Normal;
2014-03-26 17:34:19 +08:00
public bool DontPromptUpdateMsg { get; set; }
public bool EnableUpdateLog { get; set; }
public bool StartWoxOnSystemStartup { get; set; }
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 void UpdatePluginSettings()
{
var metadatas = PluginManager.AllPlugins.Select(p => p.Metadata);
if (PluginSettings == null)
{
var configs = new Dictionary<string, PluginSetting>();
foreach (var metadata in metadatas)
{
addPluginMetadata(configs, metadata);
}
PluginSettings = configs;
}
else
{
var configs = PluginSettings;
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);
}
}
}
}
private void addPluginMetadata(Dictionary<string, PluginSetting> configs, PluginMetadata metadata)
{
configs[metadata.ID] = new PluginSetting
{
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords,
Disabled = false
};
}
public void UpdateActionKeyword(PluginMetadata metadata)
{
var config = PluginSettings[metadata.ID];
config.ActionKeywords = metadata.ActionKeywords;
}
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
}