1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-24 23:34:05 +02:00

Reorganize and refactor UserConfig and PluginConfig

This commit is contained in:
chylex 2017-07-07 19:22:33 +02:00
parent c63e6a1e49
commit 8de7e13aa3
2 changed files with 49 additions and 64 deletions
Configuration
Plugins

View File

@ -32,115 +32,102 @@ static UserConfig(){
}); });
} }
// START OF CONFIGURATION // CONFIGURATION DATA
public WindowState BrowserWindow { get; set; } public WindowState BrowserWindow { get; set; } = new WindowState();
public WindowState PluginsWindow { get; set; } public WindowState PluginsWindow { get; set; } = new WindowState();
public bool DisplayNotificationColumn { get; set; } public bool ExpandLinksOnHover { get; set; } = true;
public bool DisplayNotificationTimer { get; set; } public bool SwitchAccountSelectors { get; set; } = true;
public bool NotificationTimerCountDown { get; set; } public bool EnableSpellCheck { get; set; } = false;
public bool NotificationSkipOnLinkClick { get; set; } private int _zoomLevel = 100;
public bool NotificationNonIntrusiveMode { get; set; } private bool _muteNotifications;
private TrayIcon.Behavior _trayBehavior = TrayIcon.Behavior.Disabled;
public bool EnableTrayHighlight { get; set; } = true;
public int NotificationIdlePauseSeconds { get; set; } public bool EnableUpdateCheck { get; set; } = true;
public int NotificationDurationValue { get; set; } public string DismissedUpdate { get; set; } = null;
public int NotificationScrollSpeed { get; set; }
public TweetNotification.Position NotificationPosition { get; set; } public bool DisplayNotificationColumn { get; set; } = false;
public Point CustomNotificationPosition { get; set; } public bool NotificationSkipOnLinkClick { get; set; } = false;
public int NotificationEdgeDistance { get; set; } public bool NotificationNonIntrusiveMode { get; set; } = true;
public int NotificationDisplay { get; set; } public int NotificationIdlePauseSeconds { get; set; } = 0;
public TweetNotification.Size NotificationSize { get; set; } public bool DisplayNotificationTimer { get; set; } = true;
public Size CustomNotificationSize { get; set; } public bool NotificationTimerCountDown { get; set; } = false;
public int NotificationDurationValue { get; set; } = 25;
public bool EnableSpellCheck { get; set; } public TweetNotification.Position NotificationPosition { get; set; } = TweetNotification.Position.TopRight;
public bool ExpandLinksOnHover { get; set; } public Point CustomNotificationPosition { get; set; } = ControlExtensions.InvisibleLocation;
public bool SwitchAccountSelectors { get; set; } public int NotificationDisplay { get; set; } = 0;
public bool EnableTrayHighlight { get; set; } public int NotificationEdgeDistance { get; set; } = 8;
public bool EnableUpdateCheck { get; set; } public TweetNotification.Size NotificationSize { get; set; } = TweetNotification.Size.Auto;
public string DismissedUpdate { get; set; } public Size CustomNotificationSize { get; set; } = Size.Empty;
public int NotificationScrollSpeed { get; set; } = 10;
public string CustomCefArgs { get; set; } private string _notificationSoundPath;
public string CustomBrowserCSS { get; set; }
public string CustomNotificationCSS { get; set; } public string CustomCefArgs { get; set; } = null;
public string CustomBrowserCSS { get; set; } = null;
public string CustomNotificationCSS { get; set; } = null;
// SPECIAL PROPERTIES
public bool IsCustomNotificationPositionSet => CustomNotificationPosition != ControlExtensions.InvisibleLocation; public bool IsCustomNotificationPositionSet => CustomNotificationPosition != ControlExtensions.InvisibleLocation;
public bool IsCustomNotificationSizeSet => CustomNotificationSize != Size.Empty; public bool IsCustomNotificationSizeSet => CustomNotificationSize != Size.Empty;
public string NotificationSoundPath{ public string NotificationSoundPath{
get => string.IsNullOrEmpty(notificationSoundPath) ? string.Empty : notificationSoundPath; get => string.IsNullOrEmpty(_notificationSoundPath) ? string.Empty : _notificationSoundPath;
set => notificationSoundPath = value; set => _notificationSoundPath = value;
} }
public bool MuteNotifications{ public bool MuteNotifications{
get => muteNotifications; get => _muteNotifications;
set{ set{
if (muteNotifications != value){ if (_muteNotifications != value){
muteNotifications = value; _muteNotifications = value;
MuteToggled?.Invoke(this, new EventArgs()); MuteToggled?.Invoke(this, new EventArgs());
} }
} }
} }
public int ZoomLevel{ public int ZoomLevel{
get => zoomLevel; get => _zoomLevel;
set{ set{
if (zoomLevel != value){ if (_zoomLevel != value){
zoomLevel = value; _zoomLevel = value;
ZoomLevelChanged?.Invoke(this, new EventArgs()); ZoomLevelChanged?.Invoke(this, new EventArgs());
} }
} }
} }
public double ZoomMultiplier => zoomLevel/100.0; public double ZoomMultiplier => _zoomLevel/100.0;
public TrayIcon.Behavior TrayBehavior{ public TrayIcon.Behavior TrayBehavior{
get => trayBehavior; get => _trayBehavior;
set{ set{
if (trayBehavior != value){ if (_trayBehavior != value){
trayBehavior = value; _trayBehavior = value;
TrayBehaviorChanged?.Invoke(this, new EventArgs()); TrayBehaviorChanged?.Invoke(this, new EventArgs());
} }
} }
} }
// END OF CONFIGURATION // EVENTS
public event EventHandler MuteToggled; public event EventHandler MuteToggled;
public event EventHandler ZoomLevelChanged; public event EventHandler ZoomLevelChanged;
public event EventHandler TrayBehaviorChanged; public event EventHandler TrayBehaviorChanged;
private readonly string file; private readonly string file;
private bool muteNotifications;
private int zoomLevel;
private string notificationSoundPath;
private TrayIcon.Behavior trayBehavior;
public UserConfig(string file){ // TODO make private after removing UserConfigLegacy public UserConfig(string file){ // TODO make private after removing UserConfigLegacy
this.file = file; this.file = file;
BrowserWindow = new WindowState();
ZoomLevel = 100;
DisplayNotificationTimer = true;
NotificationNonIntrusiveMode = true;
NotificationPosition = TweetNotification.Position.TopRight;
CustomNotificationPosition = ControlExtensions.InvisibleLocation;
NotificationSize = TweetNotification.Size.Auto;
NotificationEdgeDistance = 8;
NotificationDurationValue = 25;
NotificationScrollSpeed = 100;
EnableUpdateCheck = true;
ExpandLinksOnHover = true;
SwitchAccountSelectors = true;
EnableTrayHighlight = true;
PluginsWindow = new WindowState();
} }
bool ISerializedObject.OnReadUnknownProperty(string property, string value){ bool ISerializedObject.OnReadUnknownProperty(string property, string value){

View File

@ -28,8 +28,7 @@ public bool IsEnabled(Plugin plugin){
public void Load(string file){ public void Load(string file){
try{ try{
using(FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using(StreamReader reader = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.UTF8)){
using(StreamReader reader = new StreamReader(stream, Encoding.UTF8)){
string line = reader.ReadLine(); string line = reader.ReadLine();
if (line == "#Disabled"){ if (line == "#Disabled"){
@ -49,8 +48,7 @@ public void Load(string file){
public void Save(string file){ public void Save(string file){
try{ try{
using(FileStream stream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None)) using(StreamWriter writer = new StreamWriter(new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None), Encoding.UTF8)){
using(StreamWriter writer = new StreamWriter(stream, Encoding.UTF8)){
writer.WriteLine("#Disabled"); writer.WriteLine("#Disabled");
foreach(string disabled in Disabled){ foreach(string disabled in Disabled){