mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-14 02:34:07 +02:00
Prompt restart after profile import/reset only if an updated option requires it
This commit is contained in:
parent
52ef6cd95a
commit
643ebcaab4
Core
@ -21,9 +21,7 @@ public enum Items{
|
||||
PluginData = 8,
|
||||
All = UserConfig|SystemConfig|Session|PluginData
|
||||
}
|
||||
|
||||
public bool IsRestarting { get; private set; }
|
||||
|
||||
|
||||
private readonly string file;
|
||||
private readonly PluginManager plugins;
|
||||
|
||||
@ -125,7 +123,6 @@ public bool Import(Items items){
|
||||
case "system":
|
||||
if (items.HasFlag(Items.SystemConfig)){
|
||||
entry.WriteToFile(Program.SystemConfigFilePath);
|
||||
IsRestarting = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -153,7 +150,6 @@ public bool Import(Items items){
|
||||
case "cookies":
|
||||
if (items.HasFlag(Items.Session)){
|
||||
entry.WriteToFile(Path.Combine(Program.StoragePath, TempCookiesPath));
|
||||
IsRestarting = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -167,7 +163,7 @@ public bool Import(Items items){
|
||||
|
||||
return true;
|
||||
}catch(Exception e){
|
||||
Program.Reporter.HandleException("Profile Import Error", "An exception happened while importing TweetDuck profile.", true, e);
|
||||
Program.Reporter.HandleException("Profile Import", "An exception happened while importing TweetDuck profile.", true, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -216,10 +212,4 @@ public PathInfo(string fullPath, int rootLength){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ProfileManagerExtensions{
|
||||
public static bool NeedsRestart(this ProfileManager.Items items){
|
||||
return items.HasFlag(ProfileManager.Items.SystemConfig) || items.HasFlag(ProfileManager.Items.Session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,11 @@ private void btnManageOptions_Click(object sender, EventArgs e){
|
||||
if (dialog.ShowDialog() == DialogResult.OK){
|
||||
if (!dialog.IsRestarting){
|
||||
browser.ResumeNotification();
|
||||
|
||||
BrowserProcessHandler.UpdatePrefs();
|
||||
ShouldReloadBrowser = dialog.ShouldReloadBrowser;
|
||||
|
||||
if (dialog.ShouldReloadBrowser){
|
||||
BrowserProcessHandler.UpdatePrefs();
|
||||
ShouldReloadBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
Close();
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Windows.Forms;
|
||||
using TweetDuck.Configuration;
|
||||
using TweetDuck.Core.Management;
|
||||
using TweetDuck.Core.Utils;
|
||||
using TweetDuck.Plugins;
|
||||
|
||||
namespace TweetDuck.Core.Other.Settings.Dialogs{
|
||||
@ -22,6 +23,10 @@ private ProfileManager.Items SelectedItems{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool SelectedItemsForceRestart{
|
||||
get => _selectedItems.HasFlag(ProfileManager.Items.Session);
|
||||
}
|
||||
|
||||
public bool IsRestarting { get; private set; }
|
||||
public bool ShouldReloadBrowser { get; private set; }
|
||||
@ -31,6 +36,7 @@ private ProfileManager.Items SelectedItems{
|
||||
|
||||
private State currentState;
|
||||
private ProfileManager importManager;
|
||||
private bool requestedRestartFromConfig;
|
||||
|
||||
private ProfileManager.Items _selectedItems = ProfileManager.Items.None;
|
||||
|
||||
@ -116,6 +122,8 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
|
||||
case State.Reset:
|
||||
if (FormMessage.Warning("Reset TweetDuck Options", "This will reset the selected items. Are you sure you want to proceed?", FormMessage.Yes, FormMessage.No)){
|
||||
Program.Config.ProgramRestartRequested += Config_ProgramRestartRequested;
|
||||
|
||||
if (SelectedItems.HasFlag(ProfileManager.Items.UserConfig)){
|
||||
Program.UserConfig.Reset();
|
||||
}
|
||||
@ -124,25 +132,28 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
Program.SystemConfig.Reset();
|
||||
}
|
||||
|
||||
Program.Config.ProgramRestartRequested -= Config_ProgramRestartRequested;
|
||||
|
||||
if (SelectedItems.HasFlag(ProfileManager.Items.PluginData)){
|
||||
try{
|
||||
File.Delete(Program.PluginConfigFilePath);
|
||||
Directory.Delete(Program.PluginDataPath, true);
|
||||
}catch(Exception ex){
|
||||
Program.Reporter.HandleException("Plugin Data Reset Error", "Could not delete plugin data.", true, ex);
|
||||
Program.Reporter.HandleException("Profile Reset", "Could not delete plugin data.", true, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (SelectedItems.HasFlag(ProfileManager.Items.Session)){
|
||||
RestartProgram(Arguments.ArgDeleteCookies);
|
||||
if (SelectedItemsForceRestart){
|
||||
RestartProgram(SelectedItems.HasFlag(ProfileManager.Items.Session) ? new string[]{ Arguments.ArgDeleteCookies } : StringUtils.EmptyArray);
|
||||
}
|
||||
else if (SelectedItems.HasFlag(ProfileManager.Items.SystemConfig)){
|
||||
RestartProgram();
|
||||
}
|
||||
else{
|
||||
ShouldReloadBrowser = true;
|
||||
else if (requestedRestartFromConfig){
|
||||
if (FormMessage.Information("Profile Reset", "The application must restart for some of the restored options to take place. Do you want to restart now?", FormMessage.Yes, FormMessage.No)){
|
||||
RestartProgram();
|
||||
}
|
||||
}
|
||||
|
||||
ShouldReloadBrowser = true;
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
@ -151,21 +162,22 @@ private void btnContinue_Click(object sender, EventArgs e){
|
||||
|
||||
case State.Import:
|
||||
if (importManager.Import(SelectedItems)){
|
||||
Program.UserConfig.Reload(); // TODO reload both configs and detect if restart is needed
|
||||
|
||||
if (importManager.IsRestarting){
|
||||
if (SelectedItems.HasFlag(ProfileManager.Items.Session)){
|
||||
RestartProgram(Arguments.ArgImportCookies);
|
||||
}
|
||||
else if (SelectedItems.HasFlag(ProfileManager.Items.SystemConfig)){
|
||||
Program.Config.ProgramRestartRequested += Config_ProgramRestartRequested;
|
||||
Program.Config.ReloadAll();
|
||||
Program.Config.ProgramRestartRequested -= Config_ProgramRestartRequested;
|
||||
|
||||
if (SelectedItemsForceRestart){
|
||||
RestartProgram(SelectedItems.HasFlag(ProfileManager.Items.Session) ? new string[]{ Arguments.ArgImportCookies } : StringUtils.EmptyArray);
|
||||
}
|
||||
else if (requestedRestartFromConfig){
|
||||
if (FormMessage.Information("Profile Import", "The application must restart for some of the imported options to take place. Do you want to restart now?", FormMessage.Yes, FormMessage.No)){
|
||||
RestartProgram();
|
||||
}
|
||||
}
|
||||
else{
|
||||
ShouldReloadBrowser = true;
|
||||
}
|
||||
}
|
||||
|
||||
ShouldReloadBrowser = true;
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
break;
|
||||
@ -200,15 +212,19 @@ private void btnCancel_Click(object sender, EventArgs e){
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Config_ProgramRestartRequested(object sender, EventArgs e){
|
||||
requestedRestartFromConfig = true;
|
||||
}
|
||||
|
||||
private void SetFlag(ProfileManager.Items flag, bool enable){
|
||||
_selectedItems = enable ? _selectedItems | flag : _selectedItems & ~flag;
|
||||
btnContinue.Enabled = _selectedItems != ProfileManager.Items.None;
|
||||
|
||||
if (currentState == State.Import){
|
||||
btnContinue.Text = _selectedItems.NeedsRestart() ? "Import && Restart" : "Import Profile";
|
||||
btnContinue.Text = SelectedItemsForceRestart ? "Import && Restart" : "Import Profile";
|
||||
}
|
||||
else if (currentState == State.Reset){
|
||||
btnContinue.Text = _selectedItems.NeedsRestart() ? "Restore && Restart" : "Restore Defaults";
|
||||
btnContinue.Text = SelectedItemsForceRestart ? "Restore && Restart" : "Restore Defaults";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user