1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-11 12:15:44 +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 EnableAnimatedImages { get; set; } = true;
public bool _enableSmoothScrolling = true;
public bool _enableTouchAdjustment = false;
public string _customCefArgs = null;
private bool _enableSmoothScrolling = true;
private bool _enableTouchAdjustment = false;
private string _customCefArgs = null;
public string BrowserPath { get; set; } = null;
public bool IgnoreTrackingUrlWarning { get; set; } = false;

View File

@ -1,4 +1,5 @@
using System.Text;
using TweetDuck.Configuration;
namespace TweetDuck.Core.Bridge{
static class PropertyBridge{
@ -10,20 +11,21 @@ public static string GenerateScript(Environment environment){
string Bool(bool value) => value ? "true;" : "false;";
string Str(string value) => '"'+value+"\";";
UserConfig config = Program.Config.User;
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){
build.Append("x.openSearchInFirstColumn=").Append(Bool(Program.UserConfig.OpenSearchInFirstColumn));
build.Append("x.keepLikeFollowDialogsOpen=").Append(Bool(Program.UserConfig.KeepLikeFollowDialogsOpen));
build.Append("x.muteNotifications=").Append(Bool(Program.UserConfig.MuteNotifications));
build.Append("x.notificationMediaPreviews=").Append(Bool(Program.UserConfig.NotificationMediaPreviews));
build.Append("x.translationTarget=").Append(Str(Program.UserConfig.TranslationTarget));
build.Append("x.openSearchInFirstColumn=").Append(Bool(config.OpenSearchInFirstColumn));
build.Append("x.keepLikeFollowDialogsOpen=").Append(Bool(config.KeepLikeFollowDialogsOpen));
build.Append("x.muteNotifications=").Append(Bool(config.MuteNotifications));
build.Append("x.notificationMediaPreviews=").Append(Bool(config.NotificationMediaPreviews));
build.Append("x.translationTarget=").Append(Str(config.TranslationTarget));
}
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();

View File

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

View File

@ -6,6 +6,7 @@
using TweetDuck.Core.Controls;
using TweetDuck.Core.Utils;
using System.Linq;
using TweetDuck.Configuration;
using TweetDuck.Core.Bridge;
using TweetDuck.Core.Management;
using TweetDuck.Core.Notification;
@ -15,7 +16,9 @@
namespace TweetDuck.Core.Handling{
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 MenuCopyLinkUrl = (CefMenuCommand)26501;

View File

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

View File

@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using CefSharp;
using TweetDuck.Configuration;
namespace TweetDuck.Core.Handling.General{
sealed class BrowserProcessHandler : IBrowserProcessHandler{
@ -9,10 +10,12 @@ public static Task UpdatePrefs(){
}
private static void UpdatePrefsInternal(){
UserConfig config = Program.Config.User;
using(IRequestContext ctx = Cef.GetGlobalRequestContext()){
ctx.SetPreference("browser.enable_spellchecking", Program.UserConfig.EnableSpellCheck, out string _);
ctx.SetPreference("spellcheck.dictionary", Program.UserConfig.SpellCheckLanguage, out string _);
ctx.SetPreference("settings.a11y.animation_policy", Program.UserConfig.EnableAnimatedImages ? "allowed" : "none", out string _);
ctx.SetPreference("browser.enable_spellchecking", config.EnableSpellCheck, out string _);
ctx.SetPreference("spellcheck.dictionary", config.SpellCheckLanguage, 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(){
bool shouldRun = Program.SystemConfig.ClearCacheAutomatically && !ClearOnExit;
bool shouldRun = Program.Config.System.ClearCacheAutomatically && !ClearOnExit;
if (!shouldRun && AutoClearTimer != null){
AutoClearTimer.Dispose();
@ -38,7 +38,7 @@ public static void RefreshTimer(){
AutoClearTimer = new Timer(state => {
if (AutoClearTimer != null){
try{
if (CalculateCacheSize() >= Program.SystemConfig.ClearCacheThreshold*1024L*1024L){
if (CalculateCacheSize() >= Program.Config.System.ClearCacheThreshold*1024L*1024L){
SetClearOnExit();
}
}catch(Exception){

View File

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

View File

@ -8,11 +8,11 @@
namespace TweetDuck.Core.Notification.Example{
sealed class FormNotificationExample : FormNotificationMain{
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{
get{
if (Program.UserConfig.NotificationSize == TweetNotification.Size.Custom){
if (Config.NotificationSize == TweetNotification.Size.Custom){
switch(base.NotificationBorderStyle){
case FormBorderStyle.FixedSingle: return FormBorderStyle.Sizable;
case FormBorderStyle.FixedToolWindow: return FormBorderStyle.SizableToolWindow;

View File

@ -11,6 +11,8 @@
namespace TweetDuck.Core.Notification{
partial class FormNotificationBase : Form, AnalyticsFile.IProvider{
protected static UserConfig Config => Program.Config.User;
protected static int FontSizeLevel{
get{
switch(TweetDeckBridge.FontSize){
@ -25,19 +27,18 @@ protected static int FontSizeLevel{
protected virtual Point PrimaryLocation{
get{
UserConfig config = Program.UserConfig;
Screen screen;
if (config.NotificationDisplay > 0 && config.NotificationDisplay <= Screen.AllScreens.Length){
screen = Screen.AllScreens[config.NotificationDisplay-1];
if (Config.NotificationDisplay > 0 && Config.NotificationDisplay <= Screen.AllScreens.Length){
screen = Screen.AllScreens[Config.NotificationDisplay-1];
}
else{
screen = Screen.FromControl(owner);
}
int edgeDist = config.NotificationEdgeDistance;
int edgeDist = Config.NotificationEdgeDistance;
switch(config.NotificationPosition){
switch(Config.NotificationPosition){
case TweetNotification.Position.TopLeft:
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);
case TweetNotification.Position.Custom:
if (!config.IsCustomNotificationPositionSet){
config.CustomNotificationPosition = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+edgeDist);
config.Save();
if (!Config.IsCustomNotificationPositionSet){
Config.CustomNotificationPosition = new Point(screen.WorkingArea.X+screen.WorkingArea.Width-edgeDist-Width, screen.WorkingArea.Y+edgeDist);
Config.Save();
}
return config.CustomNotificationPosition;
return Config.CustomNotificationPosition;
}
return Location;
@ -93,7 +94,7 @@ protected virtual FormBorderStyle NotificationBorderStyle{
protected override bool ShowWithoutActivation => true;
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 ChromiumWebBrowser browser;
@ -203,7 +204,7 @@ protected virtual void SetNotificationSize(int width, int height){
protected virtual void UpdateTitle(){
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(){

View File

@ -29,7 +29,7 @@ abstract partial class FormNotificationMain : FormNotificationBase, ITweetDeckBr
public virtual bool RequiresResize{
get{
return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != FontSizeLevel;
return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Config.DisplayNotificationTimer || prevFontSize != FontSizeLevel;
}
set{
@ -38,7 +38,7 @@ public virtual bool RequiresResize{
prevFontSize = null;
}
else{
prevDisplayTimer = Program.UserConfig.DisplayNotificationTimer;
prevDisplayTimer = Config.DisplayNotificationTimer;
prevFontSize = FontSizeLevel;
}
}
@ -46,29 +46,29 @@ public virtual bool RequiresResize{
private int BaseClientWidth{
get{
switch(Program.UserConfig.NotificationSize){
switch(Config.NotificationSize){
default:
return BrowserUtils.Scale(284, SizeScale*(1.0+0.05*FontSizeLevel));
case TweetNotification.Size.Custom:
return Program.UserConfig.CustomNotificationSize.Width;
return Config.CustomNotificationSize.Width;
}
}
}
private int BaseClientHeight{
get{
switch(Program.UserConfig.NotificationSize){
switch(Config.NotificationSize){
default:
return BrowserUtils.Scale(122, SizeScale*(1.0+0.08*FontSizeLevel));
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){
InitializeComponent();
@ -131,7 +131,7 @@ private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam){
int eventType = wParam.ToInt32();
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;
}
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;
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){
FinishCurrentNotification();
@ -216,7 +216,7 @@ public virtual void ShowNotification(TweetNotification notification){
public override void HideNotification(){
base.HideNotification();
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
progressBarTimer.Value = Config.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
timerProgress.Stop();
totalTime = 0;
@ -258,14 +258,14 @@ protected override string GetTweetHTML(TweetNotification tweet){
protected override void LoadTweet(TweetNotification tweet){
timerProgress.Stop();
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue);
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
totalTime = timeLeft = tweet.GetDisplayDuration(Config.NotificationDurationValue);
progressBarTimer.Value = Config.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
base.LoadTweet(tweet);
}
protected override void SetNotificationSize(int width, int height){
if (Program.UserConfig.DisplayNotificationTimer){
if (Config.DisplayNotificationTimer){
ClientSize = new Size(width, height+timerBarHeight);
progressBarTimer.Visible = true;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,13 +8,15 @@ namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsCefArgs : Form{
public string CefArgs => textBoxArgs.Text;
public DialogSettingsCefArgs(){
private readonly string initialArgs;
public DialogSettingsCefArgs(string args){
InitializeComponent();
Text = Program.BrandName+" Options - CEF Arguments";
textBoxArgs.EnableMultilineShortcuts();
textBoxArgs.Text = Program.UserConfig.CustomCefArgs ?? "";
textBoxArgs.Text = initialArgs = args ?? "";
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){
string prevArgs = Program.UserConfig.CustomCefArgs;
if (CefArgs == prevArgs){
if (CefArgs == initialArgs){
DialogResult = DialogResult.Cancel;
Close();
return;
}
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)){
DialogResult = DialogResult.OK;

View File

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

View File

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

View File

@ -103,7 +103,7 @@ private void checkClearCacheAuto_CheckedChanged(object sender, EventArgs e){
#region Configuration
private void btnEditCefArgs_Click(object sender, EventArgs e){
DialogSettingsCefArgs form = new DialogSettingsCefArgs();
DialogSettingsCefArgs form = new DialogSettingsCefArgs(Config.CustomCefArgs);
form.VisibleChanged += (sender2, args2) => {
form.MoveToCenter(ParentForm);
@ -124,7 +124,7 @@ private void btnEditCefArgs_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.MoveToCenter(ParentForm);

View File

@ -10,7 +10,7 @@ public enum Behavior{ // keep order
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 ClickClose;
@ -56,6 +56,7 @@ public TrayIcon(){
this.notifyIcon.Text = Program.BrandName;
Config.MuteToggled += Config_MuteToggled;
Disposed += (sender, args) => Config.MuteToggled -= Config_MuteToggled;
}
public TrayIcon(IContainer container) : this(){

View File

@ -16,6 +16,8 @@
namespace TweetDuck.Core{
sealed class TweetDeckBrowser : ITweetDeckBrowser, IDisposable{
private static UserConfig Config => Program.Config.User;
public bool Ready { get; private set; }
public bool Enabled{
@ -66,12 +68,12 @@ public TweetDeckBrowser(FormBrowser owner, TweetDeckBridge tdBridge, UpdateBridg
this.browser.SetupResourceHandler(TweetNotification.AppLogo);
this.browser.SetupResourceHandler(TwitterUtils.LoadingSpinner);
this.browser.SetupZoomEvents();
owner.Controls.Add(browser);
Program.UserConfig.MuteToggled += UserConfig_MuteToggled;
this.browser.SetupZoomEvents();
Program.UserConfig.SoundNotificationChanged += UserConfig_SoundNotificationInfoChanged;
Config.MuteToggled += Config_MuteToggled;
Config.SoundNotificationChanged += Config_SoundNotificationInfoChanged;
}
// setup and management
@ -89,8 +91,8 @@ public void Focus(){
}
public void Dispose(){
Program.UserConfig.MuteToggled -= UserConfig_MuteToggled;
Program.UserConfig.SoundNotificationChanged -= UserConfig_SoundNotificationInfoChanged;
Config.MuteToggled -= Config_MuteToggled;
Config.SoundNotificationChanged -= Config_SoundNotificationInfoChanged;
browser.Dispose();
}
@ -148,8 +150,8 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){
ScriptLoader.ExecuteFile(frame, "code.js", browser);
InjectBrowserCSS();
ReinjectCustomCSS(Program.UserConfig.CustomBrowserCSS);
UserConfig_SoundNotificationInfoChanged(null, EventArgs.Empty);
ReinjectCustomCSS(Config.CustomBrowserCSS);
Config_SoundNotificationInfoChanged(null, EventArgs.Empty);
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");
}
if (Program.UserConfig.FirstRun){
if (Config.FirstRun){
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();
}
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";
bool hasCustomSound = Program.UserConfig.IsCustomSoundNotificationSet;
if (prevSoundNotificationPath != Program.UserConfig.NotificationSoundPath){
browser.SetupResourceHandler(soundUrl, hasCustomSound ? SoundNotification.CreateFileHandler(Program.UserConfig.NotificationSoundPath) : null);
prevSoundNotificationPath = Program.UserConfig.NotificationSoundPath;
bool hasCustomSound = Config.IsCustomSoundNotificationSet;
string newNotificationPath = Config.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

View File

@ -21,12 +21,12 @@ static class BrowserUtils{
private static SystemConfig SysConfig => Program.Config.System;
public static void SetupCefArgs(IDictionary<string, string> args){
if (!Program.SystemConfig.HardwareAcceleration){
if (!SysConfig.HardwareAcceleration){
args["disable-gpu"] = "1";
args["disable-gpu-vsync"] = "1";
}
if (Program.UserConfig.EnableSmoothScrolling){
if (Config.EnableSmoothScrolling){
args["disable-threaded-scrolling"] = "1";
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";
}
if (!Program.UserConfig.EnableTouchAdjustment){
if (!Config.EnableTouchAdjustment){
args["disable-touch-adjustment"] = "1";
}
@ -117,7 +117,7 @@ public static void OpenExternalBrowser(string url){
FormGuide.Show(hash);
}
else{
string browserPath = Program.UserConfig.BrowserPath;
string browserPath = Config.BrowserPath;
if (browserPath == null || !File.Exists(browserPath)){
WindowsUtils.OpenAssociatedProgram(url);
@ -134,7 +134,7 @@ public static void OpenExternalBrowser(string url){
break;
case UrlCheckResult.Tracking:
if (Program.UserConfig.IgnoreTrackingUrlWarning){
if (Config.IgnoreTrackingUrlWarning){
goto case UrlCheckResult.Fine;
}
@ -146,8 +146,8 @@ public static void OpenExternalBrowser(string url){
DialogResult result = form.ShowDialog();
if (result == DialogResult.Ignore){
Program.UserConfig.IgnoreTrackingUrlWarning = true;
Program.UserConfig.Save();
Config.IgnoreTrackingUrlWarning = true;
Config.Save();
}
if (result == DialogResult.Ignore || result == DialogResult.Yes){
@ -166,7 +166,7 @@ public static void OpenExternalBrowser(string url){
public static void OpenExternalSearch(string query){
if (string.IsNullOrWhiteSpace(query))return;
string searchUrl = Program.UserConfig.SearchEngineUrl;
string searchUrl = Config.SearchEngineUrl;
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)){
@ -179,7 +179,7 @@ public static void OpenExternalSearch(string query){
if (settings == null)return;
settings.FormClosed += (sender, args) => {
if (args.CloseReason == CloseReason.UserClosing && Program.UserConfig.SearchEngineUrl != searchUrl){
if (args.CloseReason == CloseReason.UserClosing && Config.SearchEngineUrl != searchUrl){
OpenExternalSearch(query);
}
};

View File

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

View File

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