mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-24 06:15:48 +02:00
Move some settings from user config to system config (touch adjustment, color profile detection, system proxy)
Closes #327
This commit is contained in:
parent
03d1bc0f4c
commit
9ede2e1ccc
@ -1,9 +1,17 @@
|
||||
using TweetLib.Core;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using TweetLib.Core;
|
||||
using TweetLib.Core.Application;
|
||||
using TweetLib.Core.Systems.Configuration;
|
||||
|
||||
namespace TweetDuck.Configuration {
|
||||
sealed class SystemConfig : BaseConfig<SystemConfig> {
|
||||
sealed class SystemConfig : BaseConfig<SystemConfig>, IAppSystemConfiguration {
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public int MigrationVersion { get; set; } = 0;
|
||||
|
||||
private bool _hardwareAcceleration = true;
|
||||
private bool _enableTouchAdjustment = false;
|
||||
private bool _enableColorProfileDetection = false;
|
||||
private bool _useSystemProxyForAllConnections = false;
|
||||
|
||||
public bool ClearCacheAutomatically { get; set; } = true;
|
||||
public int ClearCacheThreshold { get; set; } = 250;
|
||||
@ -15,10 +23,47 @@ public bool HardwareAcceleration {
|
||||
set => UpdatePropertyWithCallback(ref _hardwareAcceleration, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool EnableTouchAdjustment {
|
||||
get => _enableTouchAdjustment;
|
||||
set => UpdatePropertyWithCallback(ref _enableTouchAdjustment, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool EnableColorProfileDetection {
|
||||
get => _enableColorProfileDetection;
|
||||
set => UpdatePropertyWithCallback(ref _enableColorProfileDetection, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool UseSystemProxyForAllConnections {
|
||||
get => _useSystemProxyForAllConnections;
|
||||
set => UpdatePropertyWithCallback(ref _useSystemProxyForAllConnections, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
// END OF CONFIG
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
public bool Migrate() {
|
||||
bool hasChanged = false;
|
||||
|
||||
if (MigrationVersion < 1) {
|
||||
MigrationVersion = 1;
|
||||
hasChanged = true;
|
||||
|
||||
var userConfig = Program.Config.User;
|
||||
_enableTouchAdjustment = userConfig.EnableTouchAdjustment;
|
||||
_enableColorProfileDetection = userConfig.EnableColorProfileDetection;
|
||||
_useSystemProxyForAllConnections = userConfig.UseSystemProxyForAllConnections;
|
||||
}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
|
||||
#pragma warning restore CS0618
|
||||
|
||||
public override SystemConfig ConstructWithDefaults() {
|
||||
return new SystemConfig();
|
||||
return new SystemConfig {
|
||||
MigrationVersion = 1
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,8 @@ sealed class UserConfig : BaseConfig<UserConfig>, IAppUserConfiguration {
|
||||
public bool BestImageQuality { get; set; } = true;
|
||||
public bool EnableAnimatedImages { get; set; } = true;
|
||||
|
||||
private bool _enableSmoothScrolling = true;
|
||||
private bool _enableTouchAdjustment = false;
|
||||
private bool _enableColorProfileDetection = false;
|
||||
private string _customCefArgs = null;
|
||||
private bool _enableSmoothScrolling = true;
|
||||
private string _customCefArgs = null;
|
||||
|
||||
public string BrowserPath { get; set; } = null;
|
||||
public string BrowserPathArgs { get; set; } = null;
|
||||
@ -82,8 +80,6 @@ sealed class UserConfig : BaseConfig<UserConfig>, IAppUserConfiguration {
|
||||
public string CustomBrowserCSS { get; set; } = null;
|
||||
public string CustomNotificationCSS { get; set; } = null;
|
||||
|
||||
private bool _useSystemProxyForAllConnections;
|
||||
|
||||
public bool DevToolsInContextMenu { get; set; } = false;
|
||||
public bool DevToolsWindowOnTop { get; set; } = true;
|
||||
|
||||
@ -125,21 +121,6 @@ public bool EnableSmoothScrolling {
|
||||
set => UpdatePropertyWithCallback(ref _enableSmoothScrolling, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool EnableTouchAdjustment {
|
||||
get => _enableTouchAdjustment;
|
||||
set => UpdatePropertyWithCallback(ref _enableTouchAdjustment, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool EnableColorProfileDetection {
|
||||
get => _enableColorProfileDetection;
|
||||
set => UpdatePropertyWithCallback(ref _enableColorProfileDetection, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public bool UseSystemProxyForAllConnections {
|
||||
get => _useSystemProxyForAllConnections;
|
||||
set => UpdatePropertyWithCallback(ref _useSystemProxyForAllConnections, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
public string CustomCefArgs {
|
||||
get => _customCefArgs;
|
||||
set => UpdatePropertyWithCallback(ref _customCefArgs, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
@ -150,6 +131,20 @@ public string SpellCheckLanguage {
|
||||
set => UpdatePropertyWithCallback(ref _spellCheckLanguage, value, App.ConfigManager.TriggerProgramRestartRequested);
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
|
||||
[Obsolete("Moved to SystemConfig")]
|
||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||
public bool EnableTouchAdjustment { get; set; }
|
||||
|
||||
[Obsolete("Moved to SystemConfig")]
|
||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||
public bool EnableColorProfileDetection { get; set; }
|
||||
|
||||
[Obsolete("Moved to SystemConfig")]
|
||||
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
|
||||
public bool UseSystemProxyForAllConnections { get; set; }
|
||||
|
||||
// EVENTS
|
||||
|
||||
public event EventHandler MuteToggled;
|
||||
|
@ -121,7 +121,7 @@ private void InitializeComponent() {
|
||||
this.cbSystemConfig.Size = new System.Drawing.Size(109, 19);
|
||||
this.cbSystemConfig.TabIndex = 1;
|
||||
this.cbSystemConfig.Text = "System Options";
|
||||
this.toolTip.SetToolTip(this.cbSystemConfig, "Hardware acceleration and cache options.");
|
||||
this.toolTip.SetToolTip(this.cbSystemConfig, "Options related to the current system and hardware,\r\nsuch as hardware acceleration, proxy, and cache settings.");
|
||||
this.cbSystemConfig.UseVisualStyleBackColor = true;
|
||||
this.cbSystemConfig.CheckedChanged += new System.EventHandler(this.checkBoxSelection_CheckedChanged);
|
||||
//
|
||||
|
@ -177,6 +177,7 @@ private void btnContinue_Click(object sender, EventArgs e) {
|
||||
if (importManager.Import(SelectedItems)) {
|
||||
App.ConfigManager.ProgramRestartRequested += Config_ProgramRestartRequested;
|
||||
App.ConfigManager.ReloadAll();
|
||||
App.ConfigManager.SaveAll();
|
||||
App.ConfigManager.ProgramRestartRequested -= Config_ProgramRestartRequested;
|
||||
|
||||
if (SelectedItemsForceRestart) {
|
||||
|
@ -48,7 +48,7 @@ public TabSettingsAdvanced(Action<string> reinjectBrowserCSS, Action openDevTool
|
||||
|
||||
toolTip.SetToolTip(checkUseSystemProxyForAllConnections, "Sets whether all connections should automatically detect and use the system proxy.\r\nBy default, only the browser component uses the system proxy, while other parts (such as update checks) ignore it.\r\nDisabled by default because Windows' proxy detection can be really slow.");
|
||||
|
||||
checkUseSystemProxyForAllConnections.Checked = Config.UseSystemProxyForAllConnections;
|
||||
checkUseSystemProxyForAllConnections.Checked = SysConfig.UseSystemProxyForAllConnections;
|
||||
|
||||
// development tools
|
||||
|
||||
@ -177,7 +177,7 @@ private void RestoreParentForm() {
|
||||
#region Proxy
|
||||
|
||||
private void checkUseSystemProxyForAllConnections_CheckedChanged(object sender, EventArgs e) {
|
||||
Config.UseSystemProxyForAllConnections = checkUseSystemProxyForAllConnections.Checked;
|
||||
SysConfig.UseSystemProxyForAllConnections = checkUseSystemProxyForAllConnections.Checked;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -76,8 +76,8 @@ public TabSettingsGeneral(Action reloadColumns, UpdateChecker updates) {
|
||||
toolTip.SetToolTip(comboBoxSearchEngine, "Sets the default website for opening searches.");
|
||||
|
||||
checkSmoothScrolling.Checked = Config.EnableSmoothScrolling;
|
||||
checkTouchAdjustment.Checked = Config.EnableTouchAdjustment;
|
||||
checkAutomaticallyDetectColorProfile.Checked = Config.EnableColorProfileDetection;
|
||||
checkTouchAdjustment.Checked = SysConfig.EnableTouchAdjustment;
|
||||
checkAutomaticallyDetectColorProfile.Checked = SysConfig.EnableColorProfileDetection;
|
||||
checkHardwareAcceleration.Checked = SysConfig.HardwareAcceleration;
|
||||
|
||||
foreach (WindowsUtils.Browser browserInfo in WindowsUtils.FindInstalledBrowsers()) {
|
||||
@ -247,11 +247,11 @@ private void checkSmoothScrolling_CheckedChanged(object sender, EventArgs e) {
|
||||
}
|
||||
|
||||
private void checkTouchAdjustment_CheckedChanged(object sender, EventArgs e) {
|
||||
Config.EnableTouchAdjustment = checkTouchAdjustment.Checked;
|
||||
SysConfig.EnableTouchAdjustment = checkTouchAdjustment.Checked;
|
||||
}
|
||||
|
||||
private void checkAutomaticallyDetectColorProfile_CheckedChanged(object sender, EventArgs e) {
|
||||
Config.EnableColorProfileDetection = checkAutomaticallyDetectColorProfile.Checked;
|
||||
SysConfig.EnableColorProfileDetection = checkAutomaticallyDetectColorProfile.Checked;
|
||||
}
|
||||
|
||||
private void checkHardwareAcceleration_CheckedChanged(object sender, EventArgs e) {
|
||||
|
@ -109,6 +109,10 @@ public void BeforeLaunch() {
|
||||
WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(App.StoragePath, "Service Worker"), 4000);
|
||||
BrowserCache.TryClearNow();
|
||||
}
|
||||
|
||||
if (Config.System.Migrate()) {
|
||||
Config.System.Save();
|
||||
}
|
||||
}
|
||||
|
||||
public void Launch(ResourceCache resourceCache, PluginManager pluginManager) {
|
||||
|
@ -25,11 +25,11 @@ public static void SetupCefArgs(IDictionary<string, string> args) {
|
||||
args["disable-smooth-scrolling"] = "1";
|
||||
}
|
||||
|
||||
if (!Config.EnableTouchAdjustment) {
|
||||
if (!SysConfig.EnableTouchAdjustment) {
|
||||
args["disable-touch-adjustment"] = "1";
|
||||
}
|
||||
|
||||
if (!Config.EnableColorProfileDetection) {
|
||||
if (!SysConfig.EnableColorProfileDetection) {
|
||||
args["force-color-profile"] = "srgb";
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ public static class App {
|
||||
public static IAppFileDialogs? FileDialogs { get; } = Builder.FileDialogs;
|
||||
|
||||
internal static IAppUserConfiguration UserConfiguration => ConfigManager.User;
|
||||
internal static IAppSystemConfiguration SystemConfiguration => ConfigManager.System;
|
||||
|
||||
private static string GetDataFolder() {
|
||||
string? custom = Setup.CustomDataFolder;
|
||||
@ -74,7 +75,7 @@ internal static void Launch() {
|
||||
|
||||
WebUtils.DefaultUserAgent = Lib.BrandName + " " + Version.Tag;
|
||||
|
||||
if (UserConfiguration.UseSystemProxyForAllConnections) {
|
||||
if (SystemConfiguration.UseSystemProxyForAllConnections) {
|
||||
WebUtils.EnableSystemProxy();
|
||||
}
|
||||
|
||||
|
5
lib/TweetLib.Core/Application/IAppSystemConfiguration.cs
Normal file
5
lib/TweetLib.Core/Application/IAppSystemConfiguration.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace TweetLib.Core.Application {
|
||||
public interface IAppSystemConfiguration {
|
||||
bool UseSystemProxyForAllConnections { get; }
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@ public interface IAppUserConfiguration {
|
||||
int CalendarFirstDay { get; }
|
||||
string TranslationTarget { get; }
|
||||
ImageQuality TwitterImageQuality { get; }
|
||||
bool UseSystemProxyForAllConnections { get; }
|
||||
|
||||
event EventHandler MuteToggled;
|
||||
event EventHandler OptionsDialogClosed;
|
||||
|
@ -49,14 +49,16 @@ static ConfigManager() {
|
||||
public event EventHandler? ProgramRestartRequested;
|
||||
|
||||
internal IAppUserConfiguration User { get; }
|
||||
internal IAppSystemConfiguration System { get; }
|
||||
internal PluginConfig Plugins { get; }
|
||||
|
||||
protected ConfigManager(string storagePath, IAppUserConfiguration user, PluginConfig plugins) {
|
||||
protected ConfigManager(string storagePath, IAppUserConfiguration user, IAppSystemConfiguration system, PluginConfig plugins) {
|
||||
UserPath = Path.Combine(storagePath, "TD_UserConfig.cfg");
|
||||
SystemPath = Path.Combine(storagePath, "TD_SystemConfig.cfg");
|
||||
PluginsPath = Path.Combine(storagePath, "TD_PluginConfig.cfg");
|
||||
|
||||
User = user;
|
||||
System = system;
|
||||
Plugins = plugins;
|
||||
}
|
||||
|
||||
@ -79,15 +81,15 @@ public void TriggerProgramRestartRequested() {
|
||||
protected abstract IConfigInstance GetInstanceInfo(IConfigObject instance);
|
||||
}
|
||||
|
||||
public sealed class ConfigManager<TUser, TSystem> : ConfigManager where TUser : class, IAppUserConfiguration, IConfigObject<TUser> where TSystem : class, IConfigObject<TSystem> {
|
||||
public sealed class ConfigManager<TUser, TSystem> : ConfigManager where TUser : class, IAppUserConfiguration, IConfigObject<TUser> where TSystem : class, IAppSystemConfiguration, IConfigObject<TSystem> {
|
||||
private new TUser User { get; }
|
||||
private TSystem System { get; }
|
||||
private new TSystem System { get; }
|
||||
|
||||
private readonly FileConfigInstance<TUser> infoUser;
|
||||
private readonly FileConfigInstance<TSystem> infoSystem;
|
||||
private readonly PluginConfigInstance infoPlugins;
|
||||
|
||||
public ConfigManager(string storagePath, ConfigObjects<TUser, TSystem> configObjects) : base(storagePath, configObjects.User, configObjects.Plugins) {
|
||||
public ConfigManager(string storagePath, ConfigObjects<TUser, TSystem> configObjects) : base(storagePath, configObjects.User, configObjects.System, configObjects.Plugins) {
|
||||
User = configObjects.User;
|
||||
System = configObjects.System;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user