Flow.Launcher/Wox.Core/UserSettings/UserSettingStorage.cs

187 lines
5.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2015-10-30 23:17:34 +00:00
using System.Drawing;
using System.IO;
using System.Linq;
2015-10-30 23:17:34 +00:00
using System.Reflection;
2014-03-23 08:17:41 +00:00
using Newtonsoft.Json;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
namespace Wox.Core.UserSettings
{
public class UserSettingStorage : JsonStrorage<UserSettingStorage>
{
2014-12-14 15:16:29 +00:00
[JsonProperty]
public bool DontPromptUpdateMsg { get; set; }
2015-01-23 13:52:46 +00:00
[JsonProperty]
public int ActivateTimes { get; set; }
2015-01-21 15:00:56 +00:00
[JsonProperty]
public bool EnableUpdateLog { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
2014-02-22 03:55:48 +00:00
public string Hotkey { get; set; }
2014-03-23 08:17:41 +00:00
2015-01-02 08:16:09 +00:00
[JsonProperty]
public string Language { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
public string Theme { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
2014-03-19 14:17:01 +00:00
public string QueryBoxFont { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
public string QueryBoxFontStyle { get; set; }
[JsonProperty]
public string QueryBoxFontWeight { get; set; }
[JsonProperty]
public string QueryBoxFontStretch { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
2014-03-19 14:17:01 +00:00
public string ResultItemFont { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
public string ResultItemFontStyle { get; set; }
[JsonProperty]
public string ResultItemFontWeight { get; set; }
[JsonProperty]
public string ResultItemFontStretch { get; set; }
2014-06-16 06:06:24 +00:00
[JsonProperty]
public double WindowLeft { get; set; }
[JsonProperty]
public double WindowTop { get; set; }
public List<CustomizedPluginConfig> CustomizedPluginConfigs { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
2014-02-22 07:52:20 +00:00
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }
2014-03-23 08:17:41 +00:00
[JsonProperty]
public bool StartWoxOnSystemStartup { get; set; }
2014-03-23 08:17:41 +00:00
[Obsolete]
2014-03-26 09:34:19 +00:00
[JsonProperty]
public double Opacity { get; set; }
[Obsolete]
2014-03-26 09:34:19 +00:00
[JsonProperty]
public OpacityMode OpacityMode { get; set; }
2014-07-18 12:00:55 +00:00
[JsonProperty]
public bool LeaveCmdOpen { get; set; }
2014-04-13 02:08:33 +00:00
[JsonProperty]
public bool HideWhenDeactive { get; set; }
2015-02-20 13:45:42 +00:00
[JsonProperty]
public bool RememberLastLaunchLocation { get; set; }
[JsonProperty]
public bool IgnoreHotkeysOnFullscreen { get; set; }
2014-07-18 12:00:55 +00:00
[JsonProperty]
public string ProxyServer { get; set; }
[JsonProperty]
public bool ProxyEnabled { get; set; }
[JsonProperty]
public int ProxyPort { get; set; }
[JsonProperty]
public string ProxyUserName { get; set; }
[JsonProperty]
public string ProxyPassword { get; set; }
[JsonProperty]
public int MaxResultsToShow { get; set; }
2016-01-07 02:31:17 +00:00
protected override string FileName { get; } = "Settings";
2015-11-10 05:36:08 +00:00
2015-01-23 13:52:46 +00:00
public void IncreaseActivateTimes()
{
ActivateTimes++;
if (ActivateTimes % 15 == 0)
2015-01-23 13:52:46 +00:00
{
Save();
}
}
protected override UserSettingStorage LoadDefault()
2014-03-23 10:14:46 +00:00
{
2014-12-14 15:16:29 +00:00
DontPromptUpdateMsg = false;
2014-03-23 10:14:46 +00:00
Theme = "Dark";
Language = "en";
CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
2014-03-23 10:14:46 +00:00
Hotkey = "Alt + Space";
QueryBoxFont = FontFamily.GenericSansSerif.Name;
ResultItemFont = FontFamily.GenericSansSerif.Name;
2014-03-26 09:34:19 +00:00
Opacity = 1;
2014-07-18 12:00:55 +00:00
OpacityMode = OpacityMode.Normal;
LeaveCmdOpen = false;
2014-04-13 02:08:33 +00:00
HideWhenDeactive = false;
2015-02-10 15:48:09 +00:00
CustomPluginHotkeys = new List<CustomPluginHotkey>();
2015-02-20 13:45:42 +00:00
RememberLastLaunchLocation = false;
MaxResultsToShow = 6;
return this;
2014-03-23 10:14:46 +00:00
}
2014-03-26 09:34:19 +00:00
protected override void OnAfterLoad(UserSettingStorage storage)
{
if (storage.CustomizedPluginConfigs == null)
{
storage.CustomizedPluginConfigs = new List<CustomizedPluginConfig>();
}
2014-12-27 04:34:51 +00:00
if (storage.QueryBoxFont == null)
{
storage.QueryBoxFont = FontFamily.GenericSansSerif.Name;
}
if (storage.ResultItemFont == null)
{
storage.ResultItemFont = FontFamily.GenericSansSerif.Name;
}
2015-01-02 08:16:09 +00:00
if (storage.Language == null)
{
storage.Language = "en";
2015-01-02 08:16:09 +00:00
}
}
public void UpdateActionKeyword(PluginMetadata metadata)
{
var customizedPluginConfig = CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
if (customizedPluginConfig == null)
{
2016-01-06 21:34:42 +00:00
CustomizedPluginConfigs.Add(new CustomizedPluginConfig
{
Disabled = false,
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords
});
}
else
{
customizedPluginConfig.ActionKeywords = metadata.ActionKeywords;
}
Save();
}
2014-03-26 09:34:19 +00:00
}
public enum OpacityMode
{
Normal = 0,
LayeredWindow = 1,
DWM = 2
}
2015-07-17 07:08:39 +00:00
}