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

Remove user & system config properties from Program class & fix field visibility

This commit is contained in:
chylex 2018-07-29 10:16:29 +02:00
parent dff7278e2e
commit 671657e2b0
26 changed files with 131 additions and 115 deletions

View File

@ -23,9 +23,9 @@ sealed class UserConfig : ConfigManager.BaseConfig{
public bool BestImageQuality { get; set; } = true; public bool BestImageQuality { get; set; } = true;
public bool EnableAnimatedImages { get; set; } = true; public bool EnableAnimatedImages { get; set; } = true;
public bool _enableSmoothScrolling = true; private bool _enableSmoothScrolling = true;
public bool _enableTouchAdjustment = false; private bool _enableTouchAdjustment = false;
public string _customCefArgs = null; private string _customCefArgs = null;
public string BrowserPath { get; set; } = null; public string BrowserPath { get; set; } = null;
public bool IgnoreTrackingUrlWarning { get; set; } = false; public bool IgnoreTrackingUrlWarning { get; set; } = false;

View File

@ -1,4 +1,5 @@
using System.Text; using System.Text;
using TweetDuck.Configuration;
namespace TweetDuck.Core.Bridge{ namespace TweetDuck.Core.Bridge{
static class PropertyBridge{ static class PropertyBridge{
@ -10,20 +11,21 @@ public static string GenerateScript(Environment environment){
string Bool(bool value) => value ? "true;" : "false;"; string Bool(bool value) => value ? "true;" : "false;";
string Str(string value) => '"'+value+"\";"; string Str(string value) => '"'+value+"\";";
UserConfig config = Program.Config.User;
StringBuilder build = new StringBuilder().Append("(function(x){"); StringBuilder build = new StringBuilder().Append("(function(x){");
build.Append("x.expandLinksOnHover=").Append(Bool(Program.UserConfig.ExpandLinksOnHover)); build.Append("x.expandLinksOnHover=").Append(Bool(config.ExpandLinksOnHover));
if (environment == Environment.Browser){ if (environment == Environment.Browser){
build.Append("x.openSearchInFirstColumn=").Append(Bool(Program.UserConfig.OpenSearchInFirstColumn)); build.Append("x.openSearchInFirstColumn=").Append(Bool(config.OpenSearchInFirstColumn));
build.Append("x.keepLikeFollowDialogsOpen=").Append(Bool(Program.UserConfig.KeepLikeFollowDialogsOpen)); build.Append("x.keepLikeFollowDialogsOpen=").Append(Bool(config.KeepLikeFollowDialogsOpen));
build.Append("x.muteNotifications=").Append(Bool(Program.UserConfig.MuteNotifications)); build.Append("x.muteNotifications=").Append(Bool(config.MuteNotifications));
build.Append("x.notificationMediaPreviews=").Append(Bool(Program.UserConfig.NotificationMediaPreviews)); build.Append("x.notificationMediaPreviews=").Append(Bool(config.NotificationMediaPreviews));
build.Append("x.translationTarget=").Append(Str(Program.UserConfig.TranslationTarget)); build.Append("x.translationTarget=").Append(Str(config.TranslationTarget));
} }
if (environment == Environment.Notification){ if (environment == Environment.Notification){
build.Append("x.skipOnLinkClick=").Append(Bool(Program.UserConfig.NotificationSkipOnLinkClick)); build.Append("x.skipOnLinkClick=").Append(Bool(config.NotificationSkipOnLinkClick));
} }
return build.Append("})(window.$TDX=window.$TDX||{})").ToString(); return build.Append("})(window.$TDX=window.$TDX||{})").ToString();

View File

@ -20,7 +20,7 @@
namespace TweetDuck.Core{ namespace TweetDuck.Core{
sealed partial class FormBrowser : Form, AnalyticsFile.IProvider{ sealed partial class FormBrowser : Form, AnalyticsFile.IProvider{
private static UserConfig Config => Program.UserConfig; private static UserConfig Config => Program.Config.User;
public bool IsWaiting{ public bool IsWaiting{
set{ set{

View File

@ -6,6 +6,7 @@
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
using System.Linq; using System.Linq;
using TweetDuck.Configuration;
using TweetDuck.Core.Bridge; using TweetDuck.Core.Bridge;
using TweetDuck.Core.Management; using TweetDuck.Core.Management;
using TweetDuck.Core.Notification; using TweetDuck.Core.Notification;
@ -15,7 +16,9 @@
namespace TweetDuck.Core.Handling{ namespace TweetDuck.Core.Handling{
abstract class ContextMenuBase : IContextMenuHandler{ abstract class ContextMenuBase : IContextMenuHandler{
private static TwitterUtils.ImageQuality ImageQuality => Program.UserConfig.TwitterImageQuality; protected static UserConfig Config => Program.Config.User;
private static TwitterUtils.ImageQuality ImageQuality => Config.TwitterImageQuality;
private const CefMenuCommand MenuOpenLinkUrl = (CefMenuCommand)26500; private const CefMenuCommand MenuOpenLinkUrl = (CefMenuCommand)26500;
private const CefMenuCommand MenuCopyLinkUrl = (CefMenuCommand)26501; private const CefMenuCommand MenuCopyLinkUrl = (CefMenuCommand)26501;

View File

@ -77,7 +77,7 @@ public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser br
globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser); globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser);
globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications); globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications);
globalMenu.SetChecked(MenuMute, Program.UserConfig.MuteNotifications); globalMenu.SetChecked(MenuMute, Config.MuteNotifications);
globalMenu.AddSeparator(); globalMenu.AddSeparator();
globalMenu.AddItem(MenuSettings, TitleSettings); globalMenu.AddItem(MenuSettings, TitleSettings);
@ -163,7 +163,7 @@ public static ContextMenu CreateMenu(FormBrowser form){
menu.MenuItems.Add(TitleAboutProgram, (sender, args) => form.OpenAbout()); menu.MenuItems.Add(TitleAboutProgram, (sender, args) => form.OpenAbout());
menu.Popup += (sender, args) => { menu.Popup += (sender, args) => {
menu.MenuItems[1].Checked = Program.UserConfig.MuteNotifications; menu.MenuItems[1].Checked = Config.MuteNotifications;
form.AnalyticsFile.BrowserContextMenus.Trigger(); form.AnalyticsFile.BrowserContextMenus.Trigger();
}; };
@ -171,8 +171,8 @@ public static ContextMenu CreateMenu(FormBrowser form){
} }
private static void ToggleMuteNotifications(){ private static void ToggleMuteNotifications(){
Program.UserConfig.MuteNotifications = !Program.UserConfig.MuteNotifications; Config.MuteNotifications = !Config.MuteNotifications;
Program.UserConfig.Save(); Config.Save();
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using CefSharp; using CefSharp;
using TweetDuck.Configuration;
namespace TweetDuck.Core.Handling.General{ namespace TweetDuck.Core.Handling.General{
sealed class BrowserProcessHandler : IBrowserProcessHandler{ sealed class BrowserProcessHandler : IBrowserProcessHandler{
@ -9,10 +10,12 @@ public static Task UpdatePrefs(){
} }
private static void UpdatePrefsInternal(){ private static void UpdatePrefsInternal(){
UserConfig config = Program.Config.User;
using(IRequestContext ctx = Cef.GetGlobalRequestContext()){ using(IRequestContext ctx = Cef.GetGlobalRequestContext()){
ctx.SetPreference("browser.enable_spellchecking", Program.UserConfig.EnableSpellCheck, out string _); ctx.SetPreference("browser.enable_spellchecking", config.EnableSpellCheck, out string _);
ctx.SetPreference("spellcheck.dictionary", Program.UserConfig.SpellCheckLanguage, out string _); ctx.SetPreference("spellcheck.dictionary", config.SpellCheckLanguage, out string _);
ctx.SetPreference("settings.a11y.animation_policy", Program.UserConfig.EnableAnimatedImages ? "allowed" : "none", out string _); ctx.SetPreference("settings.a11y.animation_policy", config.EnableAnimatedImages ? "allowed" : "none", out string _);
} }
} }

View File

@ -28,7 +28,7 @@ public static void GetCacheSize(Action<Task<long>> callbackBytes){
} }
public static void RefreshTimer(){ public static void RefreshTimer(){
bool shouldRun = Program.SystemConfig.ClearCacheAutomatically && !ClearOnExit; bool shouldRun = Program.Config.System.ClearCacheAutomatically && !ClearOnExit;
if (!shouldRun && AutoClearTimer != null){ if (!shouldRun && AutoClearTimer != null){
AutoClearTimer.Dispose(); AutoClearTimer.Dispose();
@ -38,7 +38,7 @@ public static void RefreshTimer(){
AutoClearTimer = new Timer(state => { AutoClearTimer = new Timer(state => {
if (AutoClearTimer != null){ if (AutoClearTimer != null){
try{ try{
if (CalculateCacheSize() >= Program.SystemConfig.ClearCacheThreshold*1024L*1024L){ if (CalculateCacheSize() >= Program.Config.System.ClearCacheThreshold*1024L*1024L){
SetClearOnExit(); SetClearOnExit();
} }
}catch(Exception){ }catch(Exception){

View File

@ -2,6 +2,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Core.Controls; using TweetDuck.Core.Controls;
using TweetDuck.Core.Other; using TweetDuck.Core.Other;
using TweetDuck.Core.Utils; using TweetDuck.Core.Utils;
@ -9,6 +10,8 @@
namespace TweetDuck.Core.Management{ namespace TweetDuck.Core.Management{
sealed class VideoPlayer : IDisposable{ sealed class VideoPlayer : IDisposable{
private static UserConfig Config => Program.Config.User;
public bool Running => currentInstance != null && currentInstance.Running; public bool Running => currentInstance != null && currentInstance.Running;
public event EventHandler ProcessExited; public event EventHandler ProcessExited;
@ -37,7 +40,7 @@ public void Launch(string url, string username){
if ((process = Process.Start(new ProcessStartInfo{ if ((process = Process.Start(new ProcessStartInfo{
FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"), FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"),
Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\" \"{pipe.GenerateToken()}\"", Arguments = $"{owner.Handle} {Config.VideoPlayerVolume} \"{url}\" \"{pipe.GenerateToken()}\"",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true RedirectStandardOutput = true
})) != null){ })) != null){
@ -68,9 +71,9 @@ private void pipe_DataIn(object sender, DuplexPipe.PipeReadEventArgs e){
owner.InvokeSafe(() => { owner.InvokeSafe(() => {
switch(e.Key){ switch(e.Key){
case "vol": case "vol":
if (int.TryParse(e.Data, out int volume) && volume != Program.UserConfig.VideoPlayerVolume){ if (int.TryParse(e.Data, out int volume) && volume != Config.VideoPlayerVolume){
Program.UserConfig.VideoPlayerVolume = volume; Config.VideoPlayerVolume = volume;
Program.UserConfig.Save(); Config.Save();
} }
break; break;

View File

@ -8,11 +8,11 @@
namespace TweetDuck.Core.Notification.Example{ namespace TweetDuck.Core.Notification.Example{
sealed class FormNotificationExample : FormNotificationMain{ sealed class FormNotificationExample : FormNotificationMain{
public override bool RequiresResize => true; public override bool RequiresResize => true;
protected override bool CanDragWindow => Program.UserConfig.NotificationPosition == TweetNotification.Position.Custom; protected override bool CanDragWindow => Config.NotificationPosition == TweetNotification.Position.Custom;
protected override FormBorderStyle NotificationBorderStyle{ protected override FormBorderStyle NotificationBorderStyle{
get{ get{
if (Program.UserConfig.NotificationSize == TweetNotification.Size.Custom){ if (Config.NotificationSize == TweetNotification.Size.Custom){
switch(base.NotificationBorderStyle){ switch(base.NotificationBorderStyle){
case FormBorderStyle.FixedSingle: return FormBorderStyle.Sizable; case FormBorderStyle.FixedSingle: return FormBorderStyle.Sizable;
case FormBorderStyle.FixedToolWindow: return FormBorderStyle.SizableToolWindow; case FormBorderStyle.FixedToolWindow: return FormBorderStyle.SizableToolWindow;

View File

@ -11,6 +11,8 @@
namespace TweetDuck.Core.Notification{ namespace TweetDuck.Core.Notification{
partial class FormNotificationBase : Form, AnalyticsFile.IProvider{ partial class FormNotificationBase : Form, AnalyticsFile.IProvider{
protected static UserConfig Config => Program.Config.User;
protected static int FontSizeLevel{ protected static int FontSizeLevel{
get{ get{
switch(TweetDeckBridge.FontSize){ switch(TweetDeckBridge.FontSize){
@ -25,19 +27,18 @@ protected static int FontSizeLevel{
protected virtual Point PrimaryLocation{ protected virtual Point PrimaryLocation{
get{ get{
UserConfig config = Program.UserConfig;
Screen screen; Screen screen;
if (config.NotificationDisplay > 0 && config.NotificationDisplay <= Screen.AllScreens.Length){ if (Config.NotificationDisplay > 0 && Config.NotificationDisplay <= Screen.AllScreens.Length){
screen = Screen.AllScreens[config.NotificationDisplay-1]; screen = Screen.AllScreens[Config.NotificationDisplay-1];
} }
else{ else{
screen = Screen.FromControl(owner); screen = Screen.FromControl(owner);
} }
int edgeDist = config.NotificationEdgeDistance; int edgeDist = Config.NotificationEdgeDistance;
switch(config.NotificationPosition){ switch(Config.NotificationPosition){
case TweetNotification.Position.TopLeft: case TweetNotification.Position.TopLeft:
return new Point(screen.WorkingArea.X+edgeDist, screen.WorkingArea.Y+edgeDist); return new Point(screen.WorkingArea.X+edgeDist, screen.WorkingArea.Y+edgeDist);
@ -51,12 +52,12 @@ protected virtual Point PrimaryLocation{
return new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+screen.WorkingArea.Height-edgeDist-Height); return new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+screen.WorkingArea.Height-edgeDist-Height);
case TweetNotification.Position.Custom: case TweetNotification.Position.Custom:
if (!config.IsCustomNotificationPositionSet){ if (!Config.IsCustomNotificationPositionSet){
config.CustomNotificationPosition = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+edgeDist); Config.CustomNotificationPosition = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+edgeDist);
config.Save(); Config.Save();
} }
return config.CustomNotificationPosition; return Config.CustomNotificationPosition;
} }
return Location; return Location;
@ -93,7 +94,7 @@ protected virtual FormBorderStyle NotificationBorderStyle{
protected override bool ShowWithoutActivation => true; protected override bool ShowWithoutActivation => true;
protected float DpiScale { get; } protected float DpiScale { get; }
protected double SizeScale => DpiScale*Program.UserConfig.ZoomLevel/100.0; protected double SizeScale => DpiScale*Config.ZoomLevel/100.0;
protected readonly FormBrowser owner; protected readonly FormBrowser owner;
protected readonly ChromiumWebBrowser browser; protected readonly ChromiumWebBrowser browser;
@ -203,7 +204,7 @@ protected virtual void SetNotificationSize(int width, int height){
protected virtual void UpdateTitle(){ protected virtual void UpdateTitle(){
string title = currentNotification?.ColumnTitle; string title = currentNotification?.ColumnTitle;
Text = string.IsNullOrEmpty(title) || !Program.UserConfig.DisplayNotificationColumn ? Program.BrandName : Program.BrandName+" - "+title; Text = string.IsNullOrEmpty(title) || !Config.DisplayNotificationColumn ? Program.BrandName : $"{Program.BrandName} - {title}";
} }
public void ShowTweetDetail(){ public void ShowTweetDetail(){

View File

@ -29,7 +29,7 @@ abstract partial class FormNotificationMain : FormNotificationBase, ITweetDeckBr
public virtual bool RequiresResize{ public virtual bool RequiresResize{
get{ get{
return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != FontSizeLevel; return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Config.DisplayNotificationTimer || prevFontSize != FontSizeLevel;
} }
set{ set{
@ -38,7 +38,7 @@ public virtual bool RequiresResize{
prevFontSize = null; prevFontSize = null;
} }
else{ else{
prevDisplayTimer = Program.UserConfig.DisplayNotificationTimer; prevDisplayTimer = Config.DisplayNotificationTimer;
prevFontSize = FontSizeLevel; prevFontSize = FontSizeLevel;
} }
} }
@ -46,29 +46,29 @@ public virtual bool RequiresResize{
private int BaseClientWidth{ private int BaseClientWidth{
get{ get{
switch(Program.UserConfig.NotificationSize){ switch(Config.NotificationSize){
default: default:
return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*FontSizeLevel)); return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*FontSizeLevel));
case TweetNotification.Size.Custom: case TweetNotification.Size.Custom:
return Program.UserConfig.CustomNotificationSize.Width; return Config.CustomNotificationSize.Width;
} }
} }
} }
private int BaseClientHeight{ private int BaseClientHeight{
get{ get{
switch(Program.UserConfig.NotificationSize){ switch(Config.NotificationSize){
default: default:
return BrowserUtils.Scale(122, SizeScale*(1.0+0.08*FontSizeLevel)); return BrowserUtils.Scale(122, SizeScale*(1.0+0.08*FontSizeLevel));
case TweetNotification.Size.Custom: case TweetNotification.Size.Custom:
return Program.UserConfig.CustomNotificationSize.Height; return Config.CustomNotificationSize.Height;
} }
} }
} }
public Size BrowserSize => Program.UserConfig.DisplayNotificationTimer ? new Size(ClientSize.Width, ClientSize.Height-timerBarHeight) : ClientSize; public Size BrowserSize => Config.DisplayNotificationTimer ? new Size(ClientSize.Width, ClientSize.Height-timerBarHeight) : ClientSize;
protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, bool enableContextMenu) : base(owner, enableContextMenu){ protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, bool enableContextMenu) : base(owner, enableContextMenu){
InitializeComponent(); InitializeComponent();
@ -131,7 +131,7 @@ private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam){
int eventType = wParam.ToInt32(); int eventType = wParam.ToInt32();
if (eventType == NativeMethods.WM_MOUSEWHEEL && IsCursorOverBrowser){ if (eventType == NativeMethods.WM_MOUSEWHEEL && IsCursorOverBrowser){
browser.SendMouseWheelEvent(0, 0, 0, BrowserUtils.Scale(NativeMethods.GetMouseHookData(lParam), Program.UserConfig.NotificationScrollSpeed*0.01), CefEventFlags.None); browser.SendMouseWheelEvent(0, 0, 0, BrowserUtils.Scale(NativeMethods.GetMouseHookData(lParam), Config.NotificationScrollSpeed*0.01), CefEventFlags.None);
return NativeMethods.HOOK_HANDLED; return NativeMethods.HOOK_HANDLED;
} }
else if (eventType == NativeMethods.WM_XBUTTONDOWN && DesktopBounds.Contains(Cursor.Position)){ else if (eventType == NativeMethods.WM_XBUTTONDOWN && DesktopBounds.Contains(Cursor.Position)){
@ -200,7 +200,7 @@ private void timerHideProgress_Tick(object sender, EventArgs e){
timeLeft -= timerProgress.Interval; timeLeft -= timerProgress.Interval;
int value = BrowserUtils.Scale(progressBarTimer.Maximum+25, (totalTime-timeLeft)/(double)totalTime); int value = BrowserUtils.Scale(progressBarTimer.Maximum+25, (totalTime-timeLeft)/(double)totalTime);
progressBarTimer.SetValueInstant(Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum-value : value); progressBarTimer.SetValueInstant(Config.NotificationTimerCountDown ? progressBarTimer.Maximum-value : value);
if (timeLeft <= 0){ if (timeLeft <= 0){
FinishCurrentNotification(); FinishCurrentNotification();
@ -216,7 +216,7 @@ public virtual void ShowNotification(TweetNotification notification){
public override void HideNotification(){ public override void HideNotification(){
base.HideNotification(); base.HideNotification();
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum; progressBarTimer.Value = Config.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
timerProgress.Stop(); timerProgress.Stop();
totalTime = 0; totalTime = 0;
@ -258,14 +258,14 @@ protected override string GetTweetHTML(TweetNotification tweet){
protected override void LoadTweet(TweetNotification tweet){ protected override void LoadTweet(TweetNotification tweet){
timerProgress.Stop(); timerProgress.Stop();
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue); totalTime = timeLeft = tweet.GetDisplayDuration(Config.NotificationDurationValue);
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum; progressBarTimer.Value = Config.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
base.LoadTweet(tweet); base.LoadTweet(tweet);
} }
protected override void SetNotificationSize(int width, int height){ protected override void SetNotificationSize(int width, int height){
if (Program.UserConfig.DisplayNotificationTimer){ if (Config.DisplayNotificationTimer){
ClientSize = new Size(width, height+timerBarHeight); ClientSize = new Size(width, height+timerBarHeight);
progressBarTimer.Visible = true; progressBarTimer.Visible = true;
} }

View File

@ -32,10 +32,10 @@ protected override bool CanDragWindow{
public FormNotificationTweet(FormBrowser owner, PluginManager pluginManager) : base(owner, pluginManager, true){ public FormNotificationTweet(FormBrowser owner, PluginManager pluginManager) : base(owner, pluginManager, true){
InitializeComponent(); InitializeComponent();
Program.UserConfig.MuteToggled += Config_MuteToggled; Config.MuteToggled += Config_MuteToggled;
Disposed += (sender, args) => Program.UserConfig.MuteToggled -= Config_MuteToggled; Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
if (Program.UserConfig.MuteNotifications){ if (Config.MuteNotifications){
PauseNotification(); PauseNotification();
} }
} }
@ -57,7 +57,7 @@ protected override void WndProc(ref Message m){
// event handlers // event handlers
private void Config_MuteToggled(object sender, EventArgs e){ private void Config_MuteToggled(object sender, EventArgs e){
if (Program.UserConfig.MuteNotifications){ if (Config.MuteNotifications){
PauseNotification(); PauseNotification();
} }
else{ else{
@ -73,7 +73,7 @@ private void timerCursorCheck_Tick(object sender, EventArgs e){
} }
private void timerIdlePauseCheck_Tick(object sender, EventArgs e){ private void timerIdlePauseCheck_Tick(object sender, EventArgs e){
if (NativeMethods.GetIdleSeconds() < Program.UserConfig.NotificationIdlePauseSeconds){ if (NativeMethods.GetIdleSeconds() < Config.NotificationIdlePauseSeconds){
ResumeNotification(); ResumeNotification();
timerIdlePauseCheck.Stop(); timerIdlePauseCheck.Stop();
} }
@ -128,7 +128,7 @@ public override void ResumeNotification(){
private void LoadNextNotification(){ private void LoadNextNotification(){
if (!IsNotificationVisible){ if (!IsNotificationVisible){
if (Program.UserConfig.NotificationNonIntrusiveMode && IsCursorOverNotificationArea && NativeMethods.GetIdleSeconds() < NonIntrusiveIdleLimit){ if (Config.NotificationNonIntrusiveMode && IsCursorOverNotificationArea && NativeMethods.GetIdleSeconds() < NonIntrusiveIdleLimit){
if (!timerCursorCheck.Enabled){ if (!timerCursorCheck.Enabled){
PauseNotification(); PauseNotification();
timerCursorCheck.Start(); timerCursorCheck.Start();
@ -136,7 +136,7 @@ private void LoadNextNotification(){
return; return;
} }
else if (Program.UserConfig.NotificationIdlePauseSeconds > 0 && NativeMethods.GetIdleSeconds() >= Program.UserConfig.NotificationIdlePauseSeconds){ else if (Config.NotificationIdlePauseSeconds > 0 && NativeMethods.GetIdleSeconds() >= Config.NotificationIdlePauseSeconds){
if (!timerIdlePauseCheck.Enabled){ if (!timerIdlePauseCheck.Enabled){
PauseNotification(); PauseNotification();
timerIdlePauseCheck.Start(); timerIdlePauseCheck.Start();

View File

@ -59,8 +59,8 @@ public string GenerateHtml(string bodyClasses, Control sync){
build.Append(TweetDeckBridge.NotificationHeadLayout ?? DefaultHeadLayout); build.Append(TweetDeckBridge.NotificationHeadLayout ?? DefaultHeadLayout);
build.Append("<style type='text/css'>").Append(ScriptLoader.LoadResource("styles/notification.css", sync) ?? string.Empty).Append("</style>"); build.Append("<style type='text/css'>").Append(ScriptLoader.LoadResource("styles/notification.css", sync) ?? string.Empty).Append("</style>");
if (!string.IsNullOrEmpty(Program.UserConfig.CustomNotificationCSS)){ if (!string.IsNullOrEmpty(Program.Config.User.CustomNotificationCSS)){
build.Append("<style type='text/css'>").Append(Program.UserConfig.CustomNotificationCSS).Append("</style>"); build.Append("<style type='text/css'>").Append(Program.Config.User.CustomNotificationCSS).Append("</style>");
} }
build.Append("</head>"); build.Append("</head>");

View File

@ -119,8 +119,8 @@ public static AnalyticsReport Create(AnalyticsFile file, ExternalInfo info, Plug
}.FinalizeReport(); }.FinalizeReport();
} }
private static UserConfig UserConfig => Program.UserConfig; private static UserConfig UserConfig => Program.Config.User;
private static SystemConfig SysConfig => Program.SystemConfig; private static SystemConfig SysConfig => Program.Config.System;
private static string Bool(bool value) => value ? "on" : "off"; private static string Bool(bool value) => value ? "on" : "off";
private static string Exact(int value) => value.ToString(); private static string Exact(int value) => value.ToString();

View File

@ -3,11 +3,14 @@
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Plugins; using TweetDuck.Plugins;
using TweetDuck.Plugins.Controls; using TweetDuck.Plugins.Controls;
namespace TweetDuck.Core.Other{ namespace TweetDuck.Core.Other{
sealed partial class FormPlugins : Form, FormManager.IAppDialog{ sealed partial class FormPlugins : Form, FormManager.IAppDialog{
private static UserConfig Config => Program.Config.User;
private readonly PluginManager pluginManager; private readonly PluginManager pluginManager;
public FormPlugins(){ public FormPlugins(){
@ -19,8 +22,8 @@ public FormPlugins(){
public FormPlugins(PluginManager pluginManager) : this(){ public FormPlugins(PluginManager pluginManager) : this(){
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
if (!Program.UserConfig.PluginsWindowSize.IsEmpty){ if (!Config.PluginsWindowSize.IsEmpty){
Size targetSize = Program.UserConfig.PluginsWindowSize; Size targetSize = Config.PluginsWindowSize;
Size = new Size(Math.Max(MinimumSize.Width, targetSize.Width), Math.Max(MinimumSize.Height, targetSize.Height)); Size = new Size(Math.Max(MinimumSize.Width, targetSize.Width), Math.Max(MinimumSize.Height, targetSize.Height));
} }
@ -29,8 +32,8 @@ public FormPlugins(PluginManager pluginManager) : this(){
}; };
FormClosed += (sender, args) => { FormClosed += (sender, args) => {
Program.UserConfig.PluginsWindowSize = Size; Config.PluginsWindowSize = Size;
Program.UserConfig.Save(); Config.Save();
}; };
ResizeEnd += (sender, args) => { ResizeEnd += (sender, args) => {

View File

@ -4,8 +4,8 @@
namespace TweetDuck.Core.Other.Settings{ namespace TweetDuck.Core.Other.Settings{
class BaseTabSettings : UserControl{ class BaseTabSettings : UserControl{
protected static UserConfig Config => Program.UserConfig; protected static UserConfig Config => Program.Config.User;
protected static SystemConfig SysConfig => Program.SystemConfig; protected static SystemConfig SysConfig => Program.Config.System;
public IEnumerable<Control> InteractiveControls{ public IEnumerable<Control> InteractiveControls{
get{ get{

View File

@ -13,7 +13,7 @@ sealed partial class DialogSettingsCSS : Form{
private readonly Action<string> reinjectBrowserCSS; private readonly Action<string> reinjectBrowserCSS;
private readonly Action openDevTools; private readonly Action openDevTools;
public DialogSettingsCSS(Action<string> reinjectBrowserCSS, Action openDevTools){ public DialogSettingsCSS(string browserCSS, string notificationCSS, Action<string> reinjectBrowserCSS, Action openDevTools){
InitializeComponent(); InitializeComponent();
Text = Program.BrandName+" Options - CSS"; Text = Program.BrandName+" Options - CSS";
@ -22,10 +22,10 @@ public DialogSettingsCSS(Action<string> reinjectBrowserCSS, Action openDevTools)
this.openDevTools = openDevTools; this.openDevTools = openDevTools;
textBoxBrowserCSS.EnableMultilineShortcuts(); textBoxBrowserCSS.EnableMultilineShortcuts();
textBoxBrowserCSS.Text = Program.UserConfig.CustomBrowserCSS ?? ""; textBoxBrowserCSS.Text = browserCSS ?? "";
textBoxNotificationCSS.EnableMultilineShortcuts(); textBoxNotificationCSS.EnableMultilineShortcuts();
textBoxNotificationCSS.Text = Program.UserConfig.CustomNotificationCSS ?? ""; textBoxNotificationCSS.Text = notificationCSS ?? "";
if (!BrowserUtils.HasDevTools){ if (!BrowserUtils.HasDevTools){
btnOpenDevTools.Enabled = false; btnOpenDevTools.Enabled = false;

View File

@ -8,13 +8,15 @@ namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsCefArgs : Form{ sealed partial class DialogSettingsCefArgs : Form{
public string CefArgs => textBoxArgs.Text; public string CefArgs => textBoxArgs.Text;
public DialogSettingsCefArgs(){ private readonly string initialArgs;
public DialogSettingsCefArgs(string args){
InitializeComponent(); InitializeComponent();
Text = Program.BrandName+" Options - CEF Arguments"; Text = Program.BrandName+" Options - CEF Arguments";
textBoxArgs.EnableMultilineShortcuts(); textBoxArgs.EnableMultilineShortcuts();
textBoxArgs.Text = Program.UserConfig.CustomCefArgs ?? ""; textBoxArgs.Text = initialArgs = args ?? "";
textBoxArgs.Select(textBoxArgs.Text.Length, 0); textBoxArgs.Select(textBoxArgs.Text.Length, 0);
} }
@ -23,16 +25,14 @@ private void btnHelp_Click(object sender, EventArgs e){
} }
private void btnApply_Click(object sender, EventArgs e){ private void btnApply_Click(object sender, EventArgs e){
string prevArgs = Program.UserConfig.CustomCefArgs; if (CefArgs == initialArgs){
if (CefArgs == prevArgs){
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
return; return;
} }
int count = CommandLineArgs.ReadCefArguments(CefArgs).Count; int count = CommandLineArgs.ReadCefArguments(CefArgs).Count;
string prompt = count == 0 && !string.IsNullOrWhiteSpace(prevArgs) ? "All current arguments will be removed. Continue?" : count+(count == 1 ? " argument was" : " arguments were")+" detected. Continue?"; string prompt = count == 0 && !string.IsNullOrWhiteSpace(initialArgs) ? "All current arguments will be removed. Continue?" : count+(count == 1 ? " argument was" : " arguments were")+" detected. Continue?";
if (FormMessage.Question("Confirm CEF Arguments", prompt, FormMessage.OK, FormMessage.Cancel)){ if (FormMessage.Question("Confirm CEF Arguments", prompt, FormMessage.OK, FormMessage.Cancel)){
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;

View File

@ -125,11 +125,11 @@ private void btnContinue_Click(object sender, EventArgs e){
Program.Config.ProgramRestartRequested += Config_ProgramRestartRequested; Program.Config.ProgramRestartRequested += Config_ProgramRestartRequested;
if (SelectedItems.HasFlag(ProfileManager.Items.UserConfig)){ if (SelectedItems.HasFlag(ProfileManager.Items.UserConfig)){
Program.UserConfig.Reset(); Program.Config.User.Reset();
} }
if (SelectedItems.HasFlag(ProfileManager.Items.SystemConfig)){ if (SelectedItems.HasFlag(ProfileManager.Items.SystemConfig)){
Program.SystemConfig.Reset(); Program.Config.System.Reset();
} }
Program.Config.ProgramRestartRequested -= Config_ProgramRestartRequested; Program.Config.ProgramRestartRequested -= Config_ProgramRestartRequested;

View File

@ -10,7 +10,7 @@ public DialogSettingsSearchEngine(){
Text = Program.BrandName+" Options - Custom Search Engine"; Text = Program.BrandName+" Options - Custom Search Engine";
textBoxUrl.Text = Program.UserConfig.SearchEngineUrl ?? ""; textBoxUrl.Text = Program.Config.User.SearchEngineUrl ?? "";
textBoxUrl.Select(textBoxUrl.Text.Length, 0); textBoxUrl.Select(textBoxUrl.Text.Length, 0);
} }

View File

@ -103,7 +103,7 @@ private void checkClearCacheAuto_CheckedChanged(object sender, EventArgs e){
#region Configuration #region Configuration
private void btnEditCefArgs_Click(object sender, EventArgs e){ private void btnEditCefArgs_Click(object sender, EventArgs e){
DialogSettingsCefArgs form = new DialogSettingsCefArgs(); DialogSettingsCefArgs form = new DialogSettingsCefArgs(Config.CustomCefArgs);
form.VisibleChanged += (sender2, args2) => { form.VisibleChanged += (sender2, args2) => {
form.MoveToCenter(ParentForm); form.MoveToCenter(ParentForm);
@ -124,7 +124,7 @@ private void btnEditCefArgs_Click(object sender, EventArgs e){
} }
private void btnEditCSS_Click(object sender, EventArgs e){ private void btnEditCSS_Click(object sender, EventArgs e){
DialogSettingsCSS form = new DialogSettingsCSS(reinjectBrowserCSS, openDevTools); DialogSettingsCSS form = new DialogSettingsCSS(Config.CustomBrowserCSS, Config.CustomNotificationCSS, reinjectBrowserCSS, openDevTools);
form.VisibleChanged += (sender2, args2) => { form.VisibleChanged += (sender2, args2) => {
form.MoveToCenter(ParentForm); form.MoveToCenter(ParentForm);

View File

@ -10,7 +10,7 @@ public enum Behavior{ // keep order
Disabled, DisplayOnly, MinimizeToTray, CloseToTray, Combined Disabled, DisplayOnly, MinimizeToTray, CloseToTray, Combined
} }
private static UserConfig Config => Program.UserConfig; private static UserConfig Config => Program.Config.User;
public event EventHandler ClickRestore; public event EventHandler ClickRestore;
public event EventHandler ClickClose; public event EventHandler ClickClose;
@ -56,6 +56,7 @@ public TrayIcon(){
this.notifyIcon.Text = Program.BrandName; this.notifyIcon.Text = Program.BrandName;
Config.MuteToggled += Config_MuteToggled; Config.MuteToggled += Config_MuteToggled;
Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
} }
public TrayIcon(IContainer container) : this(){ public TrayIcon(IContainer container) : this(){

View File

@ -16,6 +16,8 @@
namespace TweetDuck.Core{ namespace TweetDuck.Core{
sealed class TweetDeckBrowser : ITweetDeckBrowser, IDisposable{ sealed class TweetDeckBrowser : ITweetDeckBrowser, IDisposable{
private static UserConfig Config => Program.Config.User;
public bool Ready { get; private set; } public bool Ready { get; private set; }
public bool Enabled{ public bool Enabled{
@ -66,12 +68,12 @@ public TweetDeckBrowser(FormBrowser owner, TweetDeckBridge tdBridge, UpdateBridg
this.browser.SetupResourceHandler(TweetNotification.AppLogo); this.browser.SetupResourceHandler(TweetNotification.AppLogo);
this.browser.SetupResourceHandler(TwitterUtils.LoadingSpinner); this.browser.SetupResourceHandler(TwitterUtils.LoadingSpinner);
this.browser.SetupZoomEvents();
owner.Controls.Add(browser); owner.Controls.Add(browser);
Program.UserConfig.MuteToggled += UserConfig_MuteToggled; Config.MuteToggled += Config_MuteToggled;
this.browser.SetupZoomEvents(); Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;
Program.UserConfig.SoundNotificationChanged += UserConfig_SoundNotificationInfoChanged;
} }
// setup and management // setup and management
@ -89,8 +91,8 @@ public void Focus(){
} }
public void Dispose(){ public void Dispose(){
Program.UserConfig.MuteToggled -= UserConfig_MuteToggled; Config.MuteToggled -= Config_MuteToggled;
Program.UserConfig.SoundNotificationChanged -= UserConfig_SoundNotificationInfoChanged; Config.SoundNotificationChanged -= Config_SoundNotificationInfoChanged;
browser.Dispose(); browser.Dispose();
} }
@ -148,8 +150,8 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
ScriptLoader.ExecuteFile(frame, "code.js", browser); ScriptLoader.ExecuteFile(frame, "code.js", browser);
InjectBrowserCSS(); InjectBrowserCSS();
ReinjectCustomCSS(Program.UserConfig.CustomBrowserCSS); ReinjectCustomCSS(Config.CustomBrowserCSS);
UserConfig_SoundNotificationInfoChanged(null, EventArgs.Empty); Config_SoundNotificationInfoChanged(null, EventArgs.Empty);
TweetDeckBridge.ResetStaticProperties(); TweetDeckBridge.ResetStaticProperties();
@ -157,7 +159,7 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
ScriptLoader.ExecuteScript(frame, "TD.storage.Account.prototype.requiresConsent = function(){ return false; }", "gen:gdpr"); ScriptLoader.ExecuteScript(frame, "TD.storage.Account.prototype.requiresConsent = function(){ return false; }", "gen:gdpr");
} }
if (Program.UserConfig.FirstRun){ if (Config.FirstRun){
ScriptLoader.ExecuteFile(frame, "introduction.js", browser); ScriptLoader.ExecuteFile(frame, "introduction.js", browser);
} }
} }
@ -180,20 +182,22 @@ private void browser_LoadError(object sender, LoadErrorEventArgs e){
} }
} }
private void UserConfig_MuteToggled(object sender, EventArgs e){ private void Config_MuteToggled(object sender, EventArgs e){
UpdateProperties(); UpdateProperties();
} }
private void UserConfig_SoundNotificationInfoChanged(object sender, EventArgs e){ private void Config_SoundNotificationInfoChanged(object sender, EventArgs e){
const string soundUrl = "https://ton.twimg.com/tduck/updatesnd"; const string soundUrl = "https://ton.twimg.com/tduck/updatesnd";
bool hasCustomSound = Program.UserConfig.IsCustomSoundNotificationSet;
if (prevSoundNotificationPath != Program.UserConfig.NotificationSoundPath){ bool hasCustomSound = Config.IsCustomSoundNotificationSet;
browser.SetupResourceHandler(soundUrl, hasCustomSound ? SoundNotification.CreateFileHandler(Program.UserConfig.NotificationSoundPath) : null); string newNotificationPath = Config.NotificationSoundPath;
prevSoundNotificationPath = Program.UserConfig.NotificationSoundPath;
if (prevSoundNotificationPath != newNotificationPath){
browser.SetupResourceHandler(soundUrl, hasCustomSound ? SoundNotification.CreateFileHandler(newNotificationPath) : null);
prevSoundNotificationPath = newNotificationPath;
} }
browser.ExecuteScriptAsync("TDGF_setSoundNotificationData", hasCustomSound, Program.UserConfig.NotificationSoundVolume); browser.ExecuteScriptAsync("TDGF_setSoundNotificationData", hasCustomSound, Config.NotificationSoundVolume);
} }
// external handling // external handling

View File

@ -21,12 +21,12 @@ static class BrowserUtils{
private static SystemConfig SysConfig => Program.Config.System; private static SystemConfig SysConfig => Program.Config.System;
public static void SetupCefArgs(IDictionary<string, string> args){ public static void SetupCefArgs(IDictionary<string, string> args){
if (!Program.SystemConfig.HardwareAcceleration){ if (!SysConfig.HardwareAcceleration){
args["disable-gpu"] = "1"; args["disable-gpu"] = "1";
args["disable-gpu-vsync"] = "1"; args["disable-gpu-vsync"] = "1";
} }
if (Program.UserConfig.EnableSmoothScrolling){ if (Config.EnableSmoothScrolling){
args["disable-threaded-scrolling"] = "1"; args["disable-threaded-scrolling"] = "1";
if (args.TryGetValue("disable-features", out string disabledFeatures)){ if (args.TryGetValue("disable-features", out string disabledFeatures)){
@ -40,7 +40,7 @@ public static void SetupCefArgs(IDictionary<string, string> args){
args["disable-smooth-scrolling"] = "1"; args["disable-smooth-scrolling"] = "1";
} }
if (!Program.UserConfig.EnableTouchAdjustment){ if (!Config.EnableTouchAdjustment){
args["disable-touch-adjustment"] = "1"; args["disable-touch-adjustment"] = "1";
} }
@ -117,7 +117,7 @@ public static void OpenExternalBrowser(string url){
FormGuide.Show(hash); FormGuide.Show(hash);
} }
else{ else{
string browserPath = Program.UserConfig.BrowserPath; string browserPath = Config.BrowserPath;
if (browserPath == null || !File.Exists(browserPath)){ if (browserPath == null || !File.Exists(browserPath)){
WindowsUtils.OpenAssociatedProgram(url); WindowsUtils.OpenAssociatedProgram(url);
@ -134,7 +134,7 @@ public static void OpenExternalBrowser(string url){
break; break;
case UrlCheckResult.Tracking: case UrlCheckResult.Tracking:
if (Program.UserConfig.IgnoreTrackingUrlWarning){ if (Config.IgnoreTrackingUrlWarning){
goto case UrlCheckResult.Fine; goto case UrlCheckResult.Fine;
} }
@ -146,8 +146,8 @@ public static void OpenExternalBrowser(string url){
DialogResult result = form.ShowDialog(); DialogResult result = form.ShowDialog();
if (result == DialogResult.Ignore){ if (result == DialogResult.Ignore){
Program.UserConfig.IgnoreTrackingUrlWarning = true; Config.IgnoreTrackingUrlWarning = true;
Program.UserConfig.Save(); Config.Save();
} }
if (result == DialogResult.Ignore || result == DialogResult.Yes){ if (result == DialogResult.Ignore || result == DialogResult.Yes){
@ -166,7 +166,7 @@ public static void OpenExternalBrowser(string url){
public static void OpenExternalSearch(string query){ public static void OpenExternalSearch(string query){
if (string.IsNullOrWhiteSpace(query))return; if (string.IsNullOrWhiteSpace(query))return;
string searchUrl = Program.UserConfig.SearchEngineUrl; string searchUrl = Config.SearchEngineUrl;
if (string.IsNullOrEmpty(searchUrl)){ if (string.IsNullOrEmpty(searchUrl)){
if (FormMessage.Question("Search Options", "You have not configured a default search engine yet, would you like to do it now?", FormMessage.Yes, FormMessage.No)){ if (FormMessage.Question("Search Options", "You have not configured a default search engine yet, would you like to do it now?", FormMessage.Yes, FormMessage.No)){
@ -179,7 +179,7 @@ public static void OpenExternalSearch(string query){
if (settings == null)return; if (settings == null)return;
settings.FormClosed += (sender, args) => { settings.FormClosed += (sender, args) => {
if (args.CloseReason == CloseReason.UserClosing && Program.UserConfig.SearchEngineUrl != searchUrl){ if (args.CloseReason == CloseReason.UserClosing && Config.SearchEngineUrl != searchUrl){
OpenExternalSearch(query); OpenExternalSearch(query);
} }
}; };

View File

@ -49,11 +49,7 @@ static class Program{
public static CultureInfo Culture { get; } public static CultureInfo Culture { get; }
public static Reporter Reporter { get; } public static Reporter Reporter { get; }
public static ConfigManager Config { get; } public static ConfigManager Config { get; }
// TODO
public static UserConfig UserConfig => Config.User;
public static SystemConfig SystemConfig => Config.System;
static Program(){ static Program(){
Culture = CultureInfo.CurrentCulture; Culture = CultureInfo.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
@ -147,7 +143,7 @@ private static void Main(){
#endif #endif
}; };
CommandLineArgs.ReadCefArguments(UserConfig.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs); CommandLineArgs.ReadCefArguments(Config.User.CustomCefArgs).ToDictionary(settings.CefCommandLineArgs);
BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs); BrowserUtils.SetupCefArgs(settings.CefCommandLineArgs);
Cef.Initialize(settings, false, new BrowserProcessHandler()); Cef.Initialize(settings, false, new BrowserProcessHandler());

View File

@ -39,7 +39,7 @@ public void StartTimer(){
timer.Stop(); timer.Stop();
if (Program.UserConfig.EnableUpdateCheck){ if (Program.Config.User.EnableUpdateCheck){
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
TimeSpan nextHour = now.AddSeconds(60*(60-now.Minute)-now.Second)-now; TimeSpan nextHour = now.AddSeconds(60*(60-now.Minute)-now.Second)-now;
@ -53,7 +53,7 @@ public void StartTimer(){
} }
public int Check(bool force){ public int Check(bool force){
if (Program.UserConfig.EnableUpdateCheck || force){ if (Program.Config.User.EnableUpdateCheck || force){
int nextEventId = unchecked(++lastEventId); int nextEventId = unchecked(++lastEventId);
Task<UpdateInfo> checkTask = client.Check(); Task<UpdateInfo> checkTask = client.Check();